@stats-forge/github-stats-forge-core 0.0.2 → 0.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.
- package/README.md +0 -10
- package/build/api/api-result.d.ts +6 -7
- package/build/api/api-result.d.ts.map +1 -1
- package/build/api/api-result.js +4 -5
- package/build/api/gist.d.ts +3 -10
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +4 -11
- package/build/api/index.d.ts +12 -12
- package/build/api/params.d.ts +11 -8
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +16 -14
- package/build/api/pin.d.ts +3 -19
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +6 -22
- package/build/api/stats.d.ts +10 -4
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +6 -32
- package/build/api/top-langs.d.ts +12 -6
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +6 -26
- package/build/api/wakatime.d.ts +13 -5
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +4 -21
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/gist.d.ts +2 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +27 -36
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +2 -4
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +61 -93
- package/build/cards/stats.d.ts +3 -8
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +119 -165
- package/build/cards/top-languages.d.ts +5 -31
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +176 -384
- package/build/cards/wakatime.d.ts +4 -6
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +118 -185
- package/build/common/Card.d.ts +14 -62
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +97 -199
- package/build/common/I18n.d.ts +0 -6
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +3 -6
- package/build/common/color.d.ts +4 -17
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +67 -49
- package/build/common/config.d.ts +4 -14
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +3 -16
- package/build/common/constants.d.ts +4 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +3 -1
- package/build/common/date.d.ts +0 -2
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +0 -2
- package/build/common/emojiMap.d.ts +8 -0
- package/build/common/emojiMap.d.ts.map +1 -0
- package/build/common/emojiMap.js +10 -0
- package/build/common/emojiMap.json +1915 -0
- package/build/common/error.d.ts +1 -10
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +1 -10
- package/build/common/fmt.d.ts +3 -15
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +7 -35
- package/build/common/http.d.ts +2 -7
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +8 -17
- package/build/common/icons.d.ts +18 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +103 -67
- package/build/common/languageColors.d.ts +0 -1
- package/build/common/languageColors.d.ts.map +1 -1
- package/build/common/languageColors.js +1 -4
- package/build/common/languageColors.json +18 -2
- package/build/common/ops.d.ts +3 -14
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +19 -30
- package/build/common/render.d.ts +28 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +175 -211
- package/build/common/retryer.d.ts +2 -7
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +4 -11
- package/build/fetchers/gist.d.ts +2 -5
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +1 -5
- package/build/fetchers/index.d.ts +12 -12
- package/build/fetchers/repo.d.ts +2 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +20 -33
- package/build/fetchers/stats.d.ts +2 -32
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +27 -86
- package/build/fetchers/top-languages.d.ts +2 -9
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +15 -31
- package/build/fetchers/types.d.ts +1 -1
- package/build/fetchers/wakatime.d.ts +2 -6
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +1 -5
- package/build/graphql/contributionsDocument.d.ts +3 -3
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +0 -1
- package/build/graphql/generated/gist.d.ts +1 -1
- package/build/graphql/generated/repo.d.ts +1 -1
- package/build/graphql/generated/stats.d.ts +3 -3
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +0 -1
- package/build/graphql/graphqlDocument.d.ts.map +1 -1
- package/build/graphql/graphqlDocument.js +0 -1
- package/build/graphql/reposContributedToDocument.d.ts +4 -5
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
- package/build/graphql/reposContributedToDocument.js +0 -2
- package/build/markup/css.d.ts +35 -0
- package/build/markup/css.d.ts.map +1 -0
- package/build/markup/css.js +64 -0
- package/build/markup/element.d.ts +41 -0
- package/build/markup/element.d.ts.map +1 -0
- package/build/markup/element.js +127 -0
- package/build/markup/html.d.ts +13 -0
- package/build/markup/html.d.ts.map +1 -0
- package/build/markup/html.js +27 -0
- package/build/markup/index.d.ts +9 -0
- package/build/markup/index.d.ts.map +1 -0
- package/build/markup/index.js +6 -0
- package/build/markup/serialize.d.ts +16 -0
- package/build/markup/serialize.d.ts.map +1 -0
- package/build/markup/serialize.js +17 -0
- package/build/themes/index.d.ts +332 -333
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +1 -1
- package/build/translations.d.ts +2 -6
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +621 -628
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/gist.ts +11 -18
- package/src/api/index.ts +12 -12
- package/src/api/params.ts +27 -21
- package/src/api/pin.ts +13 -28
- package/src/api/stats.ts +13 -39
- package/src/api/top-langs.ts +13 -33
- package/src/api/wakatime.ts +11 -28
- package/src/calculateRank.ts +12 -23
- package/src/cards/gist.ts +40 -43
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +97 -107
- package/src/cards/stats.ts +165 -184
- package/src/cards/top-languages.ts +297 -413
- package/src/cards/wakatime.ts +193 -221
- package/src/common/Card.ts +165 -217
- package/src/common/I18n.ts +3 -6
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +5 -2
- package/src/common/date.ts +0 -2
- package/src/common/emojiMap.json +1915 -0
- package/src/common/emojiMap.ts +13 -0
- package/src/common/error.ts +2 -11
- package/src/common/fmt.ts +7 -44
- package/src/common/http.ts +9 -15
- package/src/common/icons.ts +117 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +26 -34
- package/src/common/render.ts +279 -232
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/index.ts +12 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +44 -102
- package/src/fetchers/top-languages.ts +26 -40
- package/src/fetchers/types.ts +1 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsDocument.ts +7 -5
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +2 -2
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +0 -1
- package/src/graphql/reposContributedToDocument.ts +6 -7
- package/src/markup/css.ts +118 -0
- package/src/markup/element.ts +246 -0
- package/src/markup/html.ts +34 -0
- package/src/markup/index.ts +9 -0
- package/src/markup/serialize.ts +27 -0
- package/src/themes/index.ts +1 -1
- package/src/translations.ts +622 -629
- package/build/cards/index.d.ts +0 -11
- package/build/cards/index.d.ts.map +0 -1
- package/build/cards/index.js +0 -7
- package/build/common/html.d.ts +0 -8
- package/build/common/html.d.ts.map +0 -1
- package/build/common/html.js +0 -14
- package/build/index.d.ts +0 -15
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -10
- package/src/_emoji-name-map.d.ts +0 -10
- package/src/_github-username-regex.d.ts +0 -4
- package/src/cards/index.ts +0 -21
- package/src/common/html.ts +0 -17
- package/src/index.ts +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stats-forge/github-stats-forge-core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Dynamically generate stats for your GitHub readme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"card-generator",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/stats-forge/github-stats-forge.git",
|
|
46
|
+
"url": "git+https://github.com/stats-forge/github-stats-forge.git",
|
|
47
47
|
"directory": "packages/core"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
@@ -52,20 +52,11 @@
|
|
|
52
52
|
"README.md"
|
|
53
53
|
],
|
|
54
54
|
"type": "module",
|
|
55
|
-
"main": "./build/index.js",
|
|
56
55
|
"exports": {
|
|
57
|
-
".": {
|
|
58
|
-
"@stats/source": "./src/index.ts",
|
|
59
|
-
"default": "./build/index.js"
|
|
60
|
-
},
|
|
61
56
|
"./api": {
|
|
62
57
|
"@stats/source": "./src/api/index.ts",
|
|
63
58
|
"default": "./build/api/index.js"
|
|
64
59
|
},
|
|
65
|
-
"./cards": {
|
|
66
|
-
"@stats/source": "./src/cards/index.ts",
|
|
67
|
-
"default": "./build/cards/index.js"
|
|
68
|
-
},
|
|
69
60
|
"./fetchers": {
|
|
70
61
|
"@stats/source": "./src/fetchers/index.ts",
|
|
71
62
|
"default": "./build/fetchers/index.js"
|
|
@@ -79,36 +70,36 @@
|
|
|
79
70
|
"access": "public"
|
|
80
71
|
},
|
|
81
72
|
"dependencies": {
|
|
82
|
-
"
|
|
83
|
-
"github-username-regex": "^1.0.0",
|
|
84
|
-
"zod": "^4.4.3"
|
|
73
|
+
"zod": "^4.5.4"
|
|
85
74
|
},
|
|
86
75
|
"devDependencies": {
|
|
87
76
|
"@graphql-codegen/core": "6.2.0",
|
|
88
77
|
"@graphql-codegen/typescript": "6.1.0",
|
|
89
|
-
"@graphql-codegen/typescript-operations": "6.1.
|
|
78
|
+
"@graphql-codegen/typescript-operations": "6.1.6",
|
|
90
79
|
"@octokit/graphql-schema": "15.26.1",
|
|
91
80
|
"@testing-library/dom": "10.4.1",
|
|
92
|
-
"@testing-library/jest-dom": "
|
|
81
|
+
"@testing-library/jest-dom": "7.0.1",
|
|
82
|
+
"@types/node": "24.13.3",
|
|
93
83
|
"@uppercod/css-to-object": "1.1.1",
|
|
94
|
-
"graphql": "16.
|
|
95
|
-
"js-yaml": "5.
|
|
96
|
-
"jsdom": "
|
|
97
|
-
"vitest": "4.1.
|
|
84
|
+
"graphql": "16.14.2",
|
|
85
|
+
"js-yaml": "5.4.1",
|
|
86
|
+
"jsdom": "30.0.1",
|
|
87
|
+
"vitest": "4.1.11"
|
|
98
88
|
},
|
|
99
89
|
"engines": {
|
|
100
|
-
"node": ">=
|
|
90
|
+
"node": "^24 || >=26"
|
|
101
91
|
},
|
|
102
92
|
"scripts": {
|
|
103
93
|
"build": "tsc -p tsconfig.build.json",
|
|
94
|
+
"lint:publish": "attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm && publint --strict",
|
|
104
95
|
"test": "vitest",
|
|
105
96
|
"test:update:snapshot": "vitest -u",
|
|
106
97
|
"test:e2e": "vitest --config vitest.config.e2e.ts",
|
|
107
98
|
"bench": "vitest bench --run --config vitest.config.bench.ts",
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"generate-
|
|
99
|
+
"typecheck": "tsc -p tsconfig.typecheck.json && tsc -p tsconfig.scripts.json",
|
|
100
|
+
"generate-graphql-types": "node scripts/generate-graphql-types.ts",
|
|
101
|
+
"check-graphql-types": "node scripts/generate-graphql-types.ts --check",
|
|
102
|
+
"generate-language-colors": "node scripts/generate-language-colors.ts",
|
|
103
|
+
"generate-emoji-map": "node scripts/generate-emoji-map.ts"
|
|
113
104
|
}
|
|
114
105
|
}
|
package/src/api/api-result.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ColorParams } from '../common/color.
|
|
2
|
-
import type { ErrorCode } from '../common/error.
|
|
3
|
-
import { CardError } from '../common/error.
|
|
4
|
-
import { renderError } from '../common/render.
|
|
1
|
+
import type { ColorParams } from '../common/color.ts';
|
|
2
|
+
import type { ErrorCode } from '../common/error.ts';
|
|
3
|
+
import { CardError } from '../common/error.ts';
|
|
4
|
+
import { renderError } from '../common/render.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Why a card could not be rendered, in a form a host can act on.
|
|
@@ -37,14 +37,15 @@ export type ApiResult =
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Turns anything a handler threw into the one shape it answers with.
|
|
40
|
+
* Anything that is not a `CardError` is treated as upstream's.
|
|
40
41
|
*
|
|
41
|
-
* @param err The failure.
|
|
42
|
-
* Anything that is not a `CardError` is treated as upstream's.
|
|
43
|
-
* @param renderOptions Colors the error card is drawn with;
|
|
44
|
-
* omitted when it was a color that was rejected.
|
|
45
42
|
* @returns The rendered error.
|
|
46
43
|
*/
|
|
47
|
-
export const errorResult = (
|
|
44
|
+
export const errorResult = (
|
|
45
|
+
err: unknown,
|
|
46
|
+
/** omitted when it was a color that was rejected, which cannot draw its own error card */
|
|
47
|
+
renderOptions?: ColorParams,
|
|
48
|
+
): ApiResult => {
|
|
48
49
|
const error = CardError.from(err);
|
|
49
50
|
|
|
50
51
|
return {
|
package/src/api/gist.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import { renderGistCard } from '../cards/gist.
|
|
4
|
-
import type { CardConfig } from '../common/config.
|
|
5
|
-
import { fetchGist } from '../fetchers/gist.
|
|
3
|
+
import { renderGistCard } from '../cards/gist.ts';
|
|
4
|
+
import type { CardConfig } from '../common/config.ts';
|
|
5
|
+
import { fetchGist } from '../fetchers/gist.ts';
|
|
6
6
|
|
|
7
|
-
import type { ApiResult } from './api-result.
|
|
8
|
-
import { errorResult } from './api-result.
|
|
9
|
-
import type { ApiQuery } from './params.
|
|
10
|
-
import { booleanParam, numberParam, parseColorParams, parseParams, safeParam } from './params.
|
|
7
|
+
import type { ApiResult } from './api-result.ts';
|
|
8
|
+
import { errorResult } from './api-result.ts';
|
|
9
|
+
import type { ApiQuery } from './params.ts';
|
|
10
|
+
import { booleanParam, numberParam, parseColorParams, parseParams, safeParam } from './params.ts';
|
|
11
11
|
|
|
12
12
|
/** What the gist endpoint accepts, on top of the shared color params. */
|
|
13
13
|
const gistQuery = z.object({
|
|
@@ -24,22 +24,15 @@ type GistApiQuery = ApiQuery<typeof gistQuery>;
|
|
|
24
24
|
/**
|
|
25
25
|
* Render the gist card for a set of query params.
|
|
26
26
|
*
|
|
27
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
28
|
-
* @param query.id GitHub gist ID.
|
|
29
|
-
* @param query.border_radius Card border radius.
|
|
30
|
-
* @param query.show_owner Whether to show the gist owner.
|
|
31
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
32
|
-
* @param query.hide_border Whether to hide the card border.
|
|
33
|
-
* @param config Deployment config supplying the PAT pool.
|
|
34
27
|
* @returns The rendered card, or a rendered error.
|
|
35
28
|
*/
|
|
36
29
|
export const gist = async (query: GistApiQuery, config: CardConfig): Promise<ApiResult> => {
|
|
37
30
|
let colors;
|
|
38
31
|
try {
|
|
39
32
|
colors = parseColorParams(query);
|
|
40
|
-
} catch (
|
|
33
|
+
} catch (error) {
|
|
41
34
|
// A rejected color cannot be used to draw its own error card.
|
|
42
|
-
return errorResult(
|
|
35
|
+
return errorResult(error);
|
|
43
36
|
}
|
|
44
37
|
|
|
45
38
|
try {
|
|
@@ -60,7 +53,7 @@ export const gist = async (query: GistApiQuery, config: CardConfig): Promise<Api
|
|
|
60
53
|
hide_border,
|
|
61
54
|
}),
|
|
62
55
|
};
|
|
63
|
-
} catch (
|
|
64
|
-
return errorResult(
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return errorResult(error, colors);
|
|
65
58
|
}
|
|
66
59
|
};
|
package/src/api/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { gist } from './gist.
|
|
2
|
-
export { pin } from './pin.
|
|
3
|
-
export { stats } from './stats.
|
|
4
|
-
export { topLangs } from './top-langs.
|
|
5
|
-
export { wakatime } from './wakatime.
|
|
1
|
+
export { gist } from './gist.ts';
|
|
2
|
+
export { pin } from './pin.ts';
|
|
3
|
+
export { stats } from './stats.ts';
|
|
4
|
+
export { topLangs } from './top-langs.ts';
|
|
5
|
+
export { wakatime } from './wakatime.ts';
|
|
6
6
|
|
|
7
|
-
export type { ApiError, ApiResult } from './api-result.
|
|
7
|
+
export type { ApiError, ApiResult } from './api-result.ts';
|
|
8
8
|
|
|
9
9
|
// every handler but `wakatime` needs the PAT pool, and that one still needs the transport.
|
|
10
|
-
export { CardConfig } from '../common/config.
|
|
11
|
-
export type { CardConfigInit, PersonalAccessToken } from '../common/config.
|
|
12
|
-
export type { FetchLike } from '../common/http.
|
|
13
|
-
export type { ErrorCode } from '../common/error.
|
|
10
|
+
export { CardConfig } from '../common/config.ts';
|
|
11
|
+
export type { CardConfigInit, PersonalAccessToken } from '../common/config.ts';
|
|
12
|
+
export type { FetchLike } from '../common/http.ts';
|
|
13
|
+
export type { ErrorCode } from '../common/error.ts';
|
|
14
14
|
|
|
15
|
-
export { themes } from '../themes/index.
|
|
16
|
-
export type { ThemeName } from '../themes/index.
|
|
15
|
+
export { themes } from '../themes/index.ts';
|
|
16
|
+
export type { ThemeName } from '../themes/index.ts';
|
package/src/api/params.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import type { ColorParams } from '../common/color.
|
|
4
|
-
import { COLOR_PARAM_KEYS, THEME_PARAM_KEYS, isValidColorInput } from '../common/color.
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import type { ColorParams } from '../common/color.ts';
|
|
4
|
+
import { COLOR_PARAM_KEYS, THEME_PARAM_KEYS, isValidColorInput } from '../common/color.ts';
|
|
5
|
+
import { GITHUB_USERNAME_PATTERN } from '../common/constants.ts';
|
|
6
|
+
import { CardError } from '../common/error.ts';
|
|
7
|
+
import { parseArray, parseBoolean } from '../common/ops.ts';
|
|
8
|
+
import { isLocaleAvailable } from '../translations.ts';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @file The api layer is the trust boundary:
|
|
@@ -19,11 +20,11 @@ import { isLocaleAvailable } from '../translations.js';
|
|
|
19
20
|
/** Every param arrives as a string, or not at all. */
|
|
20
21
|
const rawParam = z.optional(z.string());
|
|
21
22
|
|
|
22
|
-
/** Characters a
|
|
23
|
+
/** Characters a repository, owner or gist id may contain. */
|
|
23
24
|
const SAFE_PATTERN = /^[-\w/.,]+$/;
|
|
24
25
|
|
|
25
26
|
/** What a check rejected a param for. */
|
|
26
|
-
type Rejection = 'number' | 'year' | 'unsafe' | 'locale' | 'enum' | 'color';
|
|
27
|
+
type Rejection = 'number' | 'year' | 'unsafe' | 'username' | 'locale' | 'enum' | 'color';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Every rejection the api can put on an error card, in one place.
|
|
@@ -33,6 +34,7 @@ const REJECTION_MESSAGES: Record<Rejection, (param: string) => string> = {
|
|
|
33
34
|
number: (param) => `Invalid number input for parameter "${param}"`,
|
|
34
35
|
year: (param) => `Invalid number input for parameter "${param}"`,
|
|
35
36
|
unsafe: (param) => `Parameter "${param}" contains unsafe characters`,
|
|
37
|
+
username: (param) => `Invalid username input for parameter "${param}"`,
|
|
36
38
|
locale: () => 'Locale not found',
|
|
37
39
|
enum: (param) => `Incorrect ${param} input`,
|
|
38
40
|
color: (param) => `Invalid color input for parameter "${param}"`,
|
|
@@ -42,11 +44,9 @@ const REJECTION_MESSAGES: Record<Rejection, (param: string) => string> = {
|
|
|
42
44
|
* A check that words its own rejection:
|
|
43
45
|
* the message is built from the kind and the param's path rather than passed in.
|
|
44
46
|
*
|
|
45
|
-
* @param kind What the check rejects the param for.
|
|
46
|
-
* @param passes Whether a value is acceptable.
|
|
47
47
|
* @returns The check, ready for `.check()`.
|
|
48
48
|
*/
|
|
49
|
-
const rejects = (kind: Rejection, passes: (value: string) => boolean) =>
|
|
49
|
+
const rejects = (kind: Rejection, passes: (value: string) => boolean): z.core.$ZodCheck<unknown> =>
|
|
50
50
|
z.refine((value: unknown) => typeof value !== 'string' || passes(value), {
|
|
51
51
|
error: (issue) => REJECTION_MESSAGES[kind](String(issue.path?.[0] ?? '')),
|
|
52
52
|
});
|
|
@@ -72,8 +72,8 @@ const listParam = z.pipe(rawParam, z.transform(parseArray));
|
|
|
72
72
|
* Yields the parsed number, or `undefined` when the param is absent.
|
|
73
73
|
*/
|
|
74
74
|
const numberParam: z.ZodMiniType<number | undefined, string | undefined> = z.pipe(
|
|
75
|
-
rawParam.check(rejects('number', (value) => Number.isFinite(parseFloat(value)))),
|
|
76
|
-
z.transform((value) => (value === undefined ? undefined : parseFloat(value))),
|
|
75
|
+
rawParam.check(rejects('number', (value) => Number.isFinite(Number.parseFloat(value)))),
|
|
76
|
+
z.transform((value) => (value === undefined ? undefined : Number.parseFloat(value))),
|
|
77
77
|
);
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -82,7 +82,7 @@ const numberParam: z.ZodMiniType<number | undefined, string | undefined> = z.pip
|
|
|
82
82
|
*/
|
|
83
83
|
const looseIntParam = z.pipe(
|
|
84
84
|
rawParam,
|
|
85
|
-
z.transform((value) => (value === undefined ? undefined : parseInt(value, 10))),
|
|
85
|
+
z.transform((value) => (value === undefined ? undefined : Number.parseInt(value, 10))),
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
/**
|
|
@@ -103,6 +103,14 @@ const safeParam: z.ZodMiniType<string | undefined, string | undefined> = rawPara
|
|
|
103
103
|
rejects('unsafe', (value) => !value || SAFE_PATTERN.test(value)),
|
|
104
104
|
);
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* A GitHub login, stricter than `safeParam`: no leading, trailing or doubled hyphen.
|
|
108
|
+
* Rejected here so a malformed one is a permanent error rather than the NOT_FOUND GitHub answers.
|
|
109
|
+
*/
|
|
110
|
+
const usernameParam: z.ZodMiniType<string | undefined, string | undefined> = rawParam.check(
|
|
111
|
+
rejects('username', (value) => !value || GITHUB_USERNAME_PATTERN.test(value)),
|
|
112
|
+
);
|
|
113
|
+
|
|
106
114
|
/**
|
|
107
115
|
* A comma-separated list of ids, checked before it is split.
|
|
108
116
|
* The safe pattern allows the commas, so one check covers the whole list.
|
|
@@ -126,7 +134,6 @@ const localeParam = z.pipe(
|
|
|
126
134
|
/**
|
|
127
135
|
* A param the card only renders as one of a fixed set of values.
|
|
128
136
|
*
|
|
129
|
-
* @param values The accepted values, as the card that renders them declares them.
|
|
130
137
|
* @returns Schema yielding one of `values`, or `undefined` when absent.
|
|
131
138
|
*/
|
|
132
139
|
const enumParam = <const T extends ReadonlyArray<string>>(
|
|
@@ -163,11 +170,10 @@ type ApiQuery<TSchema extends z.ZodMiniType> = Partial<z.input<TSchema>> & Color
|
|
|
163
170
|
* Every rejection is the query's fault, so they share one code
|
|
164
171
|
* and differ only in the message the check already worded.
|
|
165
172
|
*
|
|
166
|
-
* @param error What the schema rejected.
|
|
167
173
|
* @returns The failure, ready to render.
|
|
168
174
|
*/
|
|
169
175
|
const toCardError = (error: z.core.$ZodError): CardError => {
|
|
170
|
-
const issue = error.issues
|
|
176
|
+
const [issue] = error.issues;
|
|
171
177
|
return CardError.invalidParam(String(issue?.path[0] ?? ''), issue?.message ?? 'Invalid input');
|
|
172
178
|
};
|
|
173
179
|
|
|
@@ -177,10 +183,9 @@ const toCardError = (error: z.core.$ZodError): CardError => {
|
|
|
177
183
|
* Only the first rejection is reported:
|
|
178
184
|
* the error card has room for one line.
|
|
179
185
|
*
|
|
180
|
-
* @param schema The endpoint's schema.
|
|
181
|
-
* @param query Raw query params.
|
|
182
|
-
* @returns The parsed params.
|
|
183
186
|
* @throws {CardError} When the schema rejects a param.
|
|
187
|
+
*
|
|
188
|
+
* @returns The parsed params.
|
|
184
189
|
*/
|
|
185
190
|
const parseParams = <TSchema extends z.ZodMiniType>(
|
|
186
191
|
schema: TSchema,
|
|
@@ -197,9 +202,9 @@ const parseParams = <TSchema extends z.ZodMiniType>(
|
|
|
197
202
|
* The color params, validated.
|
|
198
203
|
* Split from the endpoint's own schema because a rejected color cannot then be used to render its own error card.
|
|
199
204
|
*
|
|
200
|
-
* @param query Raw query params.
|
|
201
|
-
* @returns The color params.
|
|
202
205
|
* @throws {CardError} When a param does not hold a color or a gradient.
|
|
206
|
+
*
|
|
207
|
+
* @returns The color params.
|
|
203
208
|
*/
|
|
204
209
|
const parseColorParams = (query: unknown): ColorParams => parseParams(colorParamsSchema, query);
|
|
205
210
|
|
|
@@ -217,5 +222,6 @@ export {
|
|
|
217
222
|
rawParam,
|
|
218
223
|
safeListParam,
|
|
219
224
|
safeParam,
|
|
225
|
+
usernameParam,
|
|
220
226
|
yearParam,
|
|
221
227
|
};
|
package/src/api/pin.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import { renderRepoCard } from '../cards/repo.
|
|
4
|
-
import type { CardConfig } from '../common/config.
|
|
5
|
-
import { fetchRepo } from '../fetchers/repo.
|
|
3
|
+
import { renderRepoCard } from '../cards/repo.ts';
|
|
4
|
+
import type { CardConfig } from '../common/config.ts';
|
|
5
|
+
import { fetchRepo } from '../fetchers/repo.ts';
|
|
6
6
|
|
|
7
|
-
import type { ApiResult } from './api-result.
|
|
8
|
-
import { errorResult } from './api-result.
|
|
9
|
-
import type { ApiQuery } from './params.
|
|
7
|
+
import type { ApiResult } from './api-result.ts';
|
|
8
|
+
import { errorResult } from './api-result.ts';
|
|
9
|
+
import type { ApiQuery } from './params.ts';
|
|
10
10
|
import {
|
|
11
11
|
booleanParam,
|
|
12
12
|
listParam,
|
|
@@ -17,11 +17,12 @@ import {
|
|
|
17
17
|
parseParams,
|
|
18
18
|
rawParam,
|
|
19
19
|
safeParam,
|
|
20
|
-
|
|
20
|
+
usernameParam,
|
|
21
|
+
} from './params.ts';
|
|
21
22
|
|
|
22
23
|
/** What the pin endpoint accepts, on top of the shared color params. */
|
|
23
24
|
const pinQuery = z.object({
|
|
24
|
-
username:
|
|
25
|
+
username: usernameParam,
|
|
25
26
|
repo: safeParam,
|
|
26
27
|
hide_border: booleanParam,
|
|
27
28
|
card_width: looseIntParam,
|
|
@@ -43,31 +44,15 @@ type PinApiQuery = ApiQuery<typeof pinQuery>;
|
|
|
43
44
|
/**
|
|
44
45
|
* Render the repository card for a set of query params.
|
|
45
46
|
*
|
|
46
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
47
|
-
* @param query.username GitHub username the repository belongs to.
|
|
48
|
-
* @param query.repo Repository name.
|
|
49
|
-
* @param query.hide_border Whether to hide the card border.
|
|
50
|
-
* @param query.card_width Card width.
|
|
51
|
-
* @param query.show_owner Whether to show the repository owner.
|
|
52
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
53
|
-
* @param query.show Comma-separated extra stats to show.
|
|
54
|
-
* @param query.show_icons Whether to show the stat icons.
|
|
55
|
-
* @param query.number_format How numbers are abbreviated.
|
|
56
|
-
* @param query.text_bold Whether the stat values are bold.
|
|
57
|
-
* @param query.line_height Line height between the stats.
|
|
58
|
-
* @param query.locale Language the card is rendered in.
|
|
59
|
-
* @param query.border_radius Card border radius.
|
|
60
|
-
* @param query.description_lines_count Lines the description is wrapped to.
|
|
61
|
-
* @param config Deployment config supplying the PAT pool.
|
|
62
47
|
* @returns The rendered card, or a rendered error.
|
|
63
48
|
*/
|
|
64
49
|
export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiResult> => {
|
|
65
50
|
let colors;
|
|
66
51
|
try {
|
|
67
52
|
colors = parseColorParams(query);
|
|
68
|
-
} catch (
|
|
53
|
+
} catch (error) {
|
|
69
54
|
// A rejected color cannot be used to draw its own error card.
|
|
70
|
-
return errorResult(
|
|
55
|
+
return errorResult(error);
|
|
71
56
|
}
|
|
72
57
|
|
|
73
58
|
try {
|
|
@@ -120,7 +105,7 @@ export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiRe
|
|
|
120
105
|
description_lines_count,
|
|
121
106
|
}),
|
|
122
107
|
};
|
|
123
|
-
} catch (
|
|
124
|
-
return errorResult(
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return errorResult(error, colors);
|
|
125
110
|
}
|
|
126
111
|
};
|
package/src/api/stats.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import { RANK_ICONS, renderStatsCard } from '../cards/stats.
|
|
4
|
-
import type { CardConfig } from '../common/config.
|
|
5
|
-
import { fetchStats } from '../fetchers/stats.
|
|
3
|
+
import { RANK_ICONS, renderStatsCard } from '../cards/stats.ts';
|
|
4
|
+
import type { CardConfig } from '../common/config.ts';
|
|
5
|
+
import { fetchStats } from '../fetchers/stats.ts';
|
|
6
6
|
|
|
7
|
-
import type { ApiResult } from './api-result.
|
|
8
|
-
import { errorResult } from './api-result.
|
|
9
|
-
import type { ApiQuery } from './params.
|
|
7
|
+
import type { ApiResult } from './api-result.ts';
|
|
8
|
+
import { errorResult } from './api-result.ts';
|
|
9
|
+
import type { ApiQuery } from './params.ts';
|
|
10
10
|
import {
|
|
11
11
|
booleanParam,
|
|
12
12
|
enumParam,
|
|
@@ -18,13 +18,13 @@ import {
|
|
|
18
18
|
parseParams,
|
|
19
19
|
rawParam,
|
|
20
20
|
safeListParam,
|
|
21
|
-
|
|
21
|
+
usernameParam,
|
|
22
22
|
yearParam,
|
|
23
|
-
} from './params.
|
|
23
|
+
} from './params.ts';
|
|
24
24
|
|
|
25
25
|
/** What the stats endpoint accepts, on top of the shared color params. */
|
|
26
26
|
const statsQuery = z.object({
|
|
27
|
-
username:
|
|
27
|
+
username: usernameParam,
|
|
28
28
|
repo: safeListParam,
|
|
29
29
|
owner: safeListParam,
|
|
30
30
|
hide: listParam,
|
|
@@ -56,41 +56,15 @@ type StatsApiQuery = ApiQuery<typeof statsQuery>;
|
|
|
56
56
|
/**
|
|
57
57
|
* Render the stats card for a set of query params.
|
|
58
58
|
*
|
|
59
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
60
|
-
* @param query.username GitHub username.
|
|
61
|
-
* @param query.repo Comma-separated repositories the search-based stats are scoped to.
|
|
62
|
-
* @param query.owner Comma-separated owners the search-based stats are scoped to.
|
|
63
|
-
* @param query.hide Comma-separated stats to hide.
|
|
64
|
-
* @param query.hide_title Whether to hide the card title.
|
|
65
|
-
* @param query.hide_border Whether to hide the card border.
|
|
66
|
-
* @param query.card_width Card width.
|
|
67
|
-
* @param query.hide_rank Whether to hide the rank circle.
|
|
68
|
-
* @param query.show_icons Whether to show the stat icons.
|
|
69
|
-
* @param query.include_all_commits Whether to count commits of all time.
|
|
70
|
-
* @param query.commits_year Year the commits are counted for.
|
|
71
|
-
* @param query.line_height Line height between the stats.
|
|
72
|
-
* @param query.text_bold Whether the stat values are bold.
|
|
73
|
-
* @param query.exclude_repo Comma-separated repositories to exclude.
|
|
74
|
-
* @param query.custom_title Card title.
|
|
75
|
-
* @param query.locale Language the card is rendered in.
|
|
76
|
-
* @param query.disable_animations Whether to disable the card animations.
|
|
77
|
-
* @param query.border_radius Card border radius.
|
|
78
|
-
* @param query.number_format How numbers are abbreviated.
|
|
79
|
-
* @param query.role Comma-separated owner affiliations to include.
|
|
80
|
-
* @param query.number_precision Decimals kept when a number is abbreviated.
|
|
81
|
-
* @param query.rank_icon Which rank indicator to draw.
|
|
82
|
-
* @param query.show Comma-separated extra stats to show.
|
|
83
|
-
* @param query.contribs_include_own_repos Whether the contributed-to counts include the user's own repositories.
|
|
84
|
-
* @param config Deployment config supplying the PAT pool.
|
|
85
59
|
* @returns The rendered card, or a rendered error.
|
|
86
60
|
*/
|
|
87
61
|
const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<ApiResult> => {
|
|
88
62
|
let colors;
|
|
89
63
|
try {
|
|
90
64
|
colors = parseColorParams(query);
|
|
91
|
-
} catch (
|
|
65
|
+
} catch (error) {
|
|
92
66
|
// A rejected color cannot be used to draw its own error card.
|
|
93
|
-
return errorResult(
|
|
67
|
+
return errorResult(error);
|
|
94
68
|
}
|
|
95
69
|
|
|
96
70
|
try {
|
|
@@ -181,8 +155,8 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
|
|
|
181
155
|
owner,
|
|
182
156
|
),
|
|
183
157
|
};
|
|
184
|
-
} catch (
|
|
185
|
-
return errorResult(
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return errorResult(error, colors);
|
|
186
160
|
}
|
|
187
161
|
};
|
|
188
162
|
|
package/src/api/top-langs.ts
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
TOP_LANG_LAYOUTS,
|
|
5
5
|
TOP_LANG_STATS_FORMATS,
|
|
6
6
|
renderTopLanguages,
|
|
7
|
-
} from '../cards/top-languages.
|
|
8
|
-
import type { CardConfig } from '../common/config.
|
|
9
|
-
import { fetchTopLanguages } from '../fetchers/top-languages.
|
|
7
|
+
} from '../cards/top-languages.ts';
|
|
8
|
+
import type { CardConfig } from '../common/config.ts';
|
|
9
|
+
import { fetchTopLanguages } from '../fetchers/top-languages.ts';
|
|
10
10
|
|
|
11
|
-
import type { ApiResult } from './api-result.
|
|
12
|
-
import { errorResult } from './api-result.
|
|
13
|
-
import type { ApiQuery } from './params.
|
|
11
|
+
import type { ApiResult } from './api-result.ts';
|
|
12
|
+
import { errorResult } from './api-result.ts';
|
|
13
|
+
import type { ApiQuery } from './params.ts';
|
|
14
14
|
import {
|
|
15
15
|
booleanParam,
|
|
16
16
|
enumParam,
|
|
@@ -21,12 +21,12 @@ import {
|
|
|
21
21
|
parseColorParams,
|
|
22
22
|
parseParams,
|
|
23
23
|
rawParam,
|
|
24
|
-
|
|
25
|
-
} from './params.
|
|
24
|
+
usernameParam,
|
|
25
|
+
} from './params.ts';
|
|
26
26
|
|
|
27
27
|
/** What the top-languages endpoint accepts, on top of the shared color params. */
|
|
28
28
|
const topLangsQuery = z.object({
|
|
29
|
-
username:
|
|
29
|
+
username: usernameParam,
|
|
30
30
|
hide: listParam,
|
|
31
31
|
hide_title: booleanParam,
|
|
32
32
|
hide_border: booleanParam,
|
|
@@ -52,35 +52,15 @@ type TopLangsApiQuery = ApiQuery<typeof topLangsQuery>;
|
|
|
52
52
|
/**
|
|
53
53
|
* Render the top languages card for a set of query params.
|
|
54
54
|
*
|
|
55
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
56
|
-
* @param query.username GitHub username.
|
|
57
|
-
* @param query.hide Comma-separated languages to hide.
|
|
58
|
-
* @param query.hide_title Whether to hide the card title.
|
|
59
|
-
* @param query.hide_border Whether to hide the card border.
|
|
60
|
-
* @param query.card_width Card width.
|
|
61
|
-
* @param query.layout How the languages are laid out.
|
|
62
|
-
* @param query.langs_count Number of languages to show.
|
|
63
|
-
* @param query.exclude_repo Comma-separated repositories to exclude.
|
|
64
|
-
* @param query.size_weight Weight given to a language's size.
|
|
65
|
-
* @param query.count_weight Weight given to a language's repository count.
|
|
66
|
-
* @param query.custom_title Card title.
|
|
67
|
-
* @param query.locale Language the card is rendered in.
|
|
68
|
-
* @param query.border_radius Card border radius.
|
|
69
|
-
* @param query.role Comma-separated owner affiliations to include.
|
|
70
|
-
* @param query.disable_animations Whether to disable the card animations.
|
|
71
|
-
* @param query.hide_progress Whether to hide the progress bars.
|
|
72
|
-
* @param query.hide_values Whether to hide the language values.
|
|
73
|
-
* @param query.stats_format Whether values are shown as bytes or percentages.
|
|
74
|
-
* @param config Deployment config supplying the PAT pool.
|
|
75
55
|
* @returns The rendered card, or a rendered error.
|
|
76
56
|
*/
|
|
77
57
|
const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Promise<ApiResult> => {
|
|
78
58
|
let colors;
|
|
79
59
|
try {
|
|
80
60
|
colors = parseColorParams(query);
|
|
81
|
-
} catch (
|
|
61
|
+
} catch (error) {
|
|
82
62
|
// A rejected color cannot be used to draw its own error card.
|
|
83
|
-
return errorResult(
|
|
63
|
+
return errorResult(error);
|
|
84
64
|
}
|
|
85
65
|
|
|
86
66
|
try {
|
|
@@ -135,8 +115,8 @@ const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Prom
|
|
|
135
115
|
stats_format,
|
|
136
116
|
}),
|
|
137
117
|
};
|
|
138
|
-
} catch (
|
|
139
|
-
return errorResult(
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return errorResult(error, colors);
|
|
140
120
|
}
|
|
141
121
|
};
|
|
142
122
|
|