@lbdudc/linea-git 0.0.0-stage → 0.1.1
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 +47 -2
- package/dist/access.d.ts +18 -0
- package/dist/access.js +18 -0
- package/dist/access.js.map +1 -0
- package/dist/auth.d.ts +11 -0
- package/dist/auth.js +16 -0
- package/dist/auth.js.map +1 -0
- package/dist/changelog/generate.d.ts +18 -0
- package/dist/changelog/generate.js +166 -0
- package/dist/changelog/generate.js.map +1 -0
- package/dist/changelog/index.d.ts +5 -0
- package/dist/changelog/index.js +3 -0
- package/dist/changelog/index.js.map +1 -0
- package/dist/changelog/parse.d.ts +43 -0
- package/dist/changelog/parse.js +91 -0
- package/dist/changelog/parse.js.map +1 -0
- package/dist/changelog/types.d.ts +85 -0
- package/dist/changelog/types.js +2 -0
- package/dist/changelog/types.js.map +1 -0
- package/dist/checkout/credential.d.ts +14 -0
- package/dist/checkout/credential.js +29 -0
- package/dist/checkout/credential.js.map +1 -0
- package/dist/checkout/git.d.ts +78 -0
- package/dist/checkout/git.js +191 -0
- package/dist/checkout/git.js.map +1 -0
- package/dist/checkout/index.d.ts +3 -0
- package/dist/checkout/index.js +4 -0
- package/dist/checkout/index.js.map +1 -0
- package/dist/checkout/sync.d.ts +156 -0
- package/dist/checkout/sync.js +211 -0
- package/dist/checkout/sync.js.map +1 -0
- package/dist/closing.d.ts +1 -0
- package/dist/closing.js +14 -0
- package/dist/closing.js.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/deletion.d.ts +19 -0
- package/dist/deletion.js +27 -0
- package/dist/deletion.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +20 -0
- package/dist/factory.js +46 -0
- package/dist/factory.js.map +1 -0
- package/dist/github/client.d.ts +44 -0
- package/dist/github/client.js +145 -0
- package/dist/github/client.js.map +1 -0
- package/dist/github/config.d.ts +24 -0
- package/dist/github/config.js +11 -0
- package/dist/github/config.js.map +1 -0
- package/dist/github/provider.d.ts +510 -0
- package/dist/github/provider.js +1009 -0
- package/dist/github/provider.js.map +1 -0
- package/dist/gitlab/client.d.ts +50 -0
- package/dist/gitlab/client.js +228 -0
- package/dist/gitlab/client.js.map +1 -0
- package/dist/gitlab/provider.d.ts +487 -0
- package/dist/gitlab/provider.js +719 -0
- package/dist/gitlab/provider.js.map +1 -0
- package/dist/host.d.ts +27 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/local/diff.d.ts +3 -0
- package/dist/local/diff.js +43 -0
- package/dist/local/diff.js.map +1 -0
- package/dist/local/git.d.ts +24 -0
- package/dist/local/git.js +51 -0
- package/dist/local/git.js.map +1 -0
- package/dist/local/health.d.ts +36 -0
- package/dist/local/health.js +57 -0
- package/dist/local/health.js.map +1 -0
- package/dist/local/hooks.d.ts +2 -0
- package/dist/local/hooks.js +44 -0
- package/dist/local/hooks.js.map +1 -0
- package/dist/local/http.d.ts +35 -0
- package/dist/local/http.js +160 -0
- package/dist/local/http.js.map +1 -0
- package/dist/local/provider.d.ts +571 -0
- package/dist/local/provider.js +1237 -0
- package/dist/local/provider.js.map +1 -0
- package/dist/local/store.d.ts +136 -0
- package/dist/local/store.js +171 -0
- package/dist/local/store.js.map +1 -0
- package/dist/packages/github-source.d.ts +69 -0
- package/dist/packages/github-source.js +133 -0
- package/dist/packages/github-source.js.map +1 -0
- package/dist/packages/gitlab-source.d.ts +59 -0
- package/dist/packages/gitlab-source.js +214 -0
- package/dist/packages/gitlab-source.js.map +1 -0
- package/dist/packages/index.d.ts +30 -0
- package/dist/packages/index.js +45 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/provider-source.d.ts +34 -0
- package/dist/packages/provider-source.js +57 -0
- package/dist/packages/provider-source.js.map +1 -0
- package/dist/packages/repository-files.d.ts +12 -0
- package/dist/packages/repository-files.js +16 -0
- package/dist/packages/repository-files.js.map +1 -0
- package/dist/provider.d.ts +888 -0
- package/dist/provider.js +29 -0
- package/dist/provider.js.map +1 -0
- package/dist/read-cache.d.ts +5 -0
- package/dist/read-cache.js +101 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/registry/catalog.d.ts +55 -0
- package/dist/registry/catalog.js +143 -0
- package/dist/registry/catalog.js.map +1 -0
- package/dist/registry/kinds.d.ts +21 -0
- package/dist/registry/kinds.js +43 -0
- package/dist/registry/kinds.js.map +1 -0
- package/dist/registry/packages.d.ts +165 -0
- package/dist/registry/packages.js +290 -0
- package/dist/registry/packages.js.map +1 -0
- package/dist/registry/publish.d.ts +35 -0
- package/dist/registry/publish.js +155 -0
- package/dist/registry/publish.js.map +1 -0
- package/dist/registry/release.d.ts +63 -0
- package/dist/registry/release.js +79 -0
- package/dist/registry/release.js.map +1 -0
- package/dist/restoration.d.ts +14 -0
- package/dist/restoration.js +33 -0
- package/dist/restoration.js.map +1 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +39 -0
- package/dist/templates.js.map +1 -0
- package/dist/testing/contract.d.ts +43 -0
- package/dist/testing/contract.js +713 -0
- package/dist/testing/contract.js.map +1 -0
- package/dist/testing/diff.d.ts +1 -0
- package/dist/testing/diff.js +65 -0
- package/dist/testing/diff.js.map +1 -0
- package/dist/testing/git-http.d.ts +12 -0
- package/dist/testing/git-http.js +308 -0
- package/dist/testing/git-http.js.map +1 -0
- package/dist/testing/github-double.d.ts +151 -0
- package/dist/testing/github-double.js +1129 -0
- package/dist/testing/github-double.js.map +1 -0
- package/dist/testing/gitlab-double.d.ts +161 -0
- package/dist/testing/gitlab-double.js +1554 -0
- package/dist/testing/gitlab-double.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +12 -0
- package/dist/version.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQ/C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmC,CAAA;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,YAAqC,EAAQ,EAAE;IAC/F,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;AACvC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAE1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAa,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAA;AAEzE,mBAAmB,CAAC,OAAO,EAAE;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAA;QACxH,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;IACvH,CAAC;IACD,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,MAAM,CAAC,KAAK,EAAE,OAAO,IAA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,EAAE,CAAC,iBAAiB,CAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import type { GitConfig } from './config.js'\nimport { GitHubProvider } from './github/provider.js'\nimport { GitLabProvider } from './gitlab/provider.js'\nimport { LocalProvider } from './local/provider.js'\nimport type { GitProvider } from './provider.js'\nimport { withReadCache } from './read-cache.js'\n\n/** How a host is made: the provider for a configuration, and what its cached reads are keyed by (one cache per host address). */\nexport interface GitProviderRegistration {\n create: (config: GitConfig) => GitProvider\n cacheKey: (config: GitConfig) => string\n}\n\nconst registrations = new Map<string, GitProviderRegistration>()\n\n/**\n * Teaches `createGitProvider` a host. GitLab, GitHub and the local host are built in; a program can register another one by name.\n */\nexport const registerGitProvider = (kind: string, registration: GitProviderRegistration): void => {\n registrations.set(kind, registration)\n}\n\nexport const unregisterGitProvider = (kind: string): boolean => registrations.delete(kind)\n\nexport const gitProviderKinds = (): string[] => [...registrations.keys()]\n\nregisterGitProvider('local', {\n create: (config) => {\n if (!config.local?.dataDir) throw new Error('The local git host needs a folder for the repositories (LINEA_REPOS_DIR).')\n return new LocalProvider({ ...config.local, dataDir: config.local.dataDir, redirectUri: config.gitlab?.redirectUri })\n },\n cacheKey: (config) => `local|${config.local?.dataDir ?? ''}`,\n})\n\nregisterGitProvider('github', {\n create: (config) => new GitHubProvider({ config: config.github ?? {} }),\n cacheKey: (config) => `github|${config.github?.apiUrl ?? ''}`,\n})\n\nregisterGitProvider('gitlab', {\n create: (config) => {\n if (!config.gitlab?.url) throw new Error('GitLab is the git host, but no address was given for it (GITLAB_HOSTNAME).')\n return new GitLabProvider(config.gitlab)\n },\n cacheKey: (config) => `gitlab|${config.gitlab?.url ?? ''}`,\n})\n\n/**\n * A provider of the host `config` names. Each call returns a new one, because a provider remembers what it did so that `rollback()` can\n * undo it: take one per operation.\n */\nexport const createGitProvider = (config: GitConfig): GitProvider => {\n const registration = registrations.get(config.provider)\n if (!registration) throw new Error(`${config.provider} is not a git host this program offers (${gitProviderKinds().join(', ') || 'none'}).`)\n return withReadCache(registration.create(config), registration.cacheKey(config))\n}\n\n/** `createGitProvider` with the configuration fixed: what a server calls once per operation. */\nexport const gitProviderFactory = (config: GitConfig | (() => GitConfig)): (() => GitProvider) =>\n () => createGitProvider(typeof config === 'function' ? config() : config)\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
type Json = any;
|
|
3
|
+
export interface GitHubClientOptions {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
fetchImpl?: typeof fetch;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The GitHub REST API: JSON in and out, errors in LINEA's terms (401 is an expired token, anything else a `GitError` with its status),
|
|
10
|
+
* conditional requests for what was read before, and a wait-and-retry when GitHub says the limit has been reached.
|
|
11
|
+
*/
|
|
12
|
+
export declare class GitHubClient {
|
|
13
|
+
private readonly apiUrl;
|
|
14
|
+
private readonly doFetch;
|
|
15
|
+
private readonly timeoutMs;
|
|
16
|
+
constructor({ apiUrl, fetchImpl, timeoutMs }: GitHubClientOptions);
|
|
17
|
+
private urlOf;
|
|
18
|
+
private send;
|
|
19
|
+
/** A JSON answer (`null` for "no content"). */
|
|
20
|
+
json({ token, method, path, body }: {
|
|
21
|
+
token: string | undefined;
|
|
22
|
+
method?: string;
|
|
23
|
+
path: string;
|
|
24
|
+
body?: unknown;
|
|
25
|
+
}): Promise<Json>;
|
|
26
|
+
/** The bytes of a file (`null` when there is none). */
|
|
27
|
+
raw({ token, path }: {
|
|
28
|
+
token: string | undefined;
|
|
29
|
+
path: string;
|
|
30
|
+
}): Promise<Buffer | null>;
|
|
31
|
+
/** A stream of the body of the answer (an archive). */
|
|
32
|
+
stream({ token, path }: {
|
|
33
|
+
token: string | undefined;
|
|
34
|
+
path: string;
|
|
35
|
+
}): Promise<Readable>;
|
|
36
|
+
/** Every item of a list, page after page. */
|
|
37
|
+
paginate({ token, path, perPage }: {
|
|
38
|
+
token: string | undefined;
|
|
39
|
+
path: string;
|
|
40
|
+
perPage?: number;
|
|
41
|
+
}): Promise<Json[]>;
|
|
42
|
+
}
|
|
43
|
+
export declare const clearGitHubCache: () => void;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { GitAuthError, GitError } from '../errors.js';
|
|
4
|
+
const TIMEOUT_MS = 30000;
|
|
5
|
+
const MAX_RETRIES = 3;
|
|
6
|
+
const MAX_WAIT_MS = 30000;
|
|
7
|
+
const CACHE_LIMIT = 1000;
|
|
8
|
+
// Answers to GET requests, kept with their ETag. GitHub does not count a request answered "304 not modified" against the rate limit,
|
|
9
|
+
// so asking again (the same repository, the same file) costs nothing. Per token: what one user may read is not for another.
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
const remember = (key, entry) => {
|
|
12
|
+
if (cache.size >= CACHE_LIMIT)
|
|
13
|
+
cache.delete(cache.keys().next().value);
|
|
14
|
+
cache.set(key, entry);
|
|
15
|
+
};
|
|
16
|
+
const tokenKey = (token) => crypto.createHash('sha1').update(String(token)).digest('hex').slice(0, 12);
|
|
17
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
/** Whether GitHub is telling us to slow down, and for how long (ms). */
|
|
19
|
+
const throttle = (response, message) => {
|
|
20
|
+
const retryAfter = response.headers.get('retry-after');
|
|
21
|
+
const exhausted = response.headers.get('x-ratelimit-remaining') === '0';
|
|
22
|
+
const secondary = /rate limit/i.test(message ?? '');
|
|
23
|
+
if (response.status !== 429 && !(response.status === 403 && (retryAfter !== null || exhausted || secondary)))
|
|
24
|
+
return null;
|
|
25
|
+
if (retryAfter !== null)
|
|
26
|
+
return Math.min(MAX_WAIT_MS, Number(retryAfter) * 1000);
|
|
27
|
+
const reset = Number(response.headers.get('x-ratelimit-reset'));
|
|
28
|
+
if (exhausted && reset)
|
|
29
|
+
return Math.min(MAX_WAIT_MS, Math.max(0, reset * 1000 - Date.now()) + 500);
|
|
30
|
+
return 1000;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The GitHub REST API: JSON in and out, errors in LINEA's terms (401 is an expired token, anything else a `GitError` with its status),
|
|
34
|
+
* conditional requests for what was read before, and a wait-and-retry when GitHub says the limit has been reached.
|
|
35
|
+
*/
|
|
36
|
+
export class GitHubClient {
|
|
37
|
+
apiUrl;
|
|
38
|
+
doFetch;
|
|
39
|
+
timeoutMs;
|
|
40
|
+
constructor({ apiUrl, fetchImpl = globalThis.fetch, timeoutMs = TIMEOUT_MS }) {
|
|
41
|
+
this.apiUrl = apiUrl.replace(/\/+$/, '');
|
|
42
|
+
this.doFetch = fetchImpl;
|
|
43
|
+
this.timeoutMs = timeoutMs;
|
|
44
|
+
}
|
|
45
|
+
urlOf(path) {
|
|
46
|
+
return path.startsWith('http') ? path : `${this.apiUrl}${path}`;
|
|
47
|
+
}
|
|
48
|
+
async send({ token, method, path, body, accept }) {
|
|
49
|
+
const url = this.urlOf(path);
|
|
50
|
+
const cacheKey = method === 'GET' && !accept ? `${tokenKey(token)}|${url}` : null;
|
|
51
|
+
const cached = cacheKey === null ? undefined : cache.get(cacheKey);
|
|
52
|
+
for (let attempt = 0;; attempt++) {
|
|
53
|
+
const headers = {
|
|
54
|
+
Accept: accept ?? 'application/vnd.github+json',
|
|
55
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
56
|
+
'User-Agent': 'linea',
|
|
57
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
58
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
59
|
+
...(cached?.etag ? { 'If-None-Match': cached.etag } : {})
|
|
60
|
+
};
|
|
61
|
+
let response;
|
|
62
|
+
try {
|
|
63
|
+
response = await this.doFetch(url, {
|
|
64
|
+
method,
|
|
65
|
+
headers,
|
|
66
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
67
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const failure = error;
|
|
72
|
+
if (failure.name === 'TimeoutError' || failure.name === 'AbortError') {
|
|
73
|
+
throw new GitError(`GitHub request timed out after ${this.timeoutMs}ms: ${method} ${path}`);
|
|
74
|
+
}
|
|
75
|
+
throw new GitError(failure.message ?? String(error));
|
|
76
|
+
}
|
|
77
|
+
if (response.status === 304 && cached)
|
|
78
|
+
return { response, json: cached.json, cached: true };
|
|
79
|
+
if (response.ok)
|
|
80
|
+
return { response };
|
|
81
|
+
let detail = {};
|
|
82
|
+
try {
|
|
83
|
+
const text = await response.text();
|
|
84
|
+
detail = text ? JSON.parse(text) : {};
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
detail = {};
|
|
88
|
+
}
|
|
89
|
+
const wait = throttle(response, detail.message);
|
|
90
|
+
if (wait !== null && attempt < MAX_RETRIES) {
|
|
91
|
+
await sleep(wait);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (response.status === 401)
|
|
95
|
+
throw new GitAuthError(detail.message);
|
|
96
|
+
const errors = (detail.errors ?? []).map((e) => e.message ?? e.code).filter(Boolean).join('; ');
|
|
97
|
+
throw new GitError(`${detail.message ?? response.statusText}${errors ? ` (${errors})` : ''}`, response.status);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** A JSON answer (`null` for "no content"). */
|
|
101
|
+
async json({ token, method = 'GET', path, body }) {
|
|
102
|
+
const { response, json, cached } = await this.send({ token, method, path, body });
|
|
103
|
+
if (cached)
|
|
104
|
+
return json;
|
|
105
|
+
if (response.status === 204)
|
|
106
|
+
return null;
|
|
107
|
+
const parsed = await response.json();
|
|
108
|
+
if (method === 'GET') {
|
|
109
|
+
const etag = response.headers.get('etag');
|
|
110
|
+
if (etag)
|
|
111
|
+
remember(`${tokenKey(token)}|${this.urlOf(path)}`, { etag, json: parsed });
|
|
112
|
+
}
|
|
113
|
+
return parsed;
|
|
114
|
+
}
|
|
115
|
+
/** The bytes of a file (`null` when there is none). */
|
|
116
|
+
async raw({ token, path }) {
|
|
117
|
+
try {
|
|
118
|
+
const { response } = await this.send({ token, method: 'GET', path, accept: 'application/vnd.github.raw+json' });
|
|
119
|
+
return Buffer.from(await response.arrayBuffer());
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error.status === 404)
|
|
123
|
+
return null;
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** A stream of the body of the answer (an archive). */
|
|
128
|
+
async stream({ token, path }) {
|
|
129
|
+
const { response } = await this.send({ token, method: 'GET', path, accept: 'application/vnd.github+json' });
|
|
130
|
+
return Readable.fromWeb(response.body);
|
|
131
|
+
}
|
|
132
|
+
/** Every item of a list, page after page. */
|
|
133
|
+
async paginate({ token, path, perPage = 100 }) {
|
|
134
|
+
const all = [];
|
|
135
|
+
for (let page = 1;; page++) {
|
|
136
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
137
|
+
const batch = (await this.json({ token, path: `${path}${separator}per_page=${perPage}&page=${page}` }));
|
|
138
|
+
all.push(...batch);
|
|
139
|
+
if (batch.length < perPage)
|
|
140
|
+
return all;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export const clearGitHubCache = () => cache.clear();
|
|
145
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/github/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,MAA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,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,SAAS,YAAY,OAAO,SAAS,IAAI,EAAE,EAAE,CAAC,CAAW,CAAA;YACjH,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;YAClB,IAAI,KAAK,CAAC,MAAM,GAAG,OAAO;gBAAE,OAAO,GAAG,CAAA;QACxC,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAS,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA","sourcesContent":["import crypto from 'node:crypto'\nimport { Readable } from 'node:stream'\nimport { GitAuthError, GitError } from '../errors.js'\n\nconst TIMEOUT_MS = 30000\nconst MAX_RETRIES = 3\nconst MAX_WAIT_MS = 30000\nconst CACHE_LIMIT = 1000\n\ntype Json = any\n\n// Answers to GET requests, kept with their ETag. GitHub does not count a request answered \"304 not modified\" against the rate limit,\n// so asking again (the same repository, the same file) costs nothing. Per token: what one user may read is not for another.\nconst cache = new Map<string, { etag: string, json: Json }>()\nconst remember = (key: string, entry: { etag: string, json: Json }): void => {\n if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value as string)\n cache.set(key, entry)\n}\nconst tokenKey = (token: string | undefined): string => crypto.createHash('sha1').update(String(token)).digest('hex').slice(0, 12)\n\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\n/** Whether GitHub is telling us to slow down, and for how long (ms). */\nconst throttle = (response: Response, message: string | undefined): number | null => {\n const retryAfter = response.headers.get('retry-after')\n const exhausted = response.headers.get('x-ratelimit-remaining') === '0'\n const secondary = /rate limit/i.test(message ?? '')\n if (response.status !== 429 && !(response.status === 403 && (retryAfter !== null || exhausted || secondary))) return null\n if (retryAfter !== null) return Math.min(MAX_WAIT_MS, Number(retryAfter) * 1000)\n const reset = Number(response.headers.get('x-ratelimit-reset'))\n if (exhausted && reset) return Math.min(MAX_WAIT_MS, Math.max(0, reset * 1000 - Date.now()) + 500)\n return 1000\n}\n\nexport interface GitHubClientOptions {\n apiUrl: string\n fetchImpl?: typeof fetch\n timeoutMs?: number\n}\n\n/**\n * The GitHub REST API: JSON in and out, errors in LINEA's terms (401 is an expired token, anything else a `GitError` with its status),\n * conditional requests for what was read before, and a wait-and-retry when GitHub says the limit has been reached.\n */\nexport class GitHubClient {\n private readonly apiUrl: string\n private readonly doFetch: typeof fetch\n private readonly timeoutMs: number\n\n constructor({ apiUrl, fetchImpl = globalThis.fetch, timeoutMs = TIMEOUT_MS }: GitHubClientOptions) {\n this.apiUrl = apiUrl.replace(/\\/+$/, '')\n this.doFetch = fetchImpl\n this.timeoutMs = timeoutMs\n }\n\n private urlOf(path: string): string {\n return path.startsWith('http') ? path : `${this.apiUrl}${path}`\n }\n\n private async send({ token, method, path, body, accept }: { token: string | undefined, method: string, path: string, body?: unknown, accept?: string }): Promise<{ response: Response, json?: Json, cached?: boolean }> {\n const url = this.urlOf(path)\n const cacheKey = method === 'GET' && !accept ? `${tokenKey(token)}|${url}` : null\n const cached = cacheKey === null ? undefined : cache.get(cacheKey)\n for (let attempt = 0; ; attempt++) {\n const headers: Record<string, string> = {\n Accept: accept ?? 'application/vnd.github+json',\n 'X-GitHub-Api-Version': '2022-11-28',\n 'User-Agent': 'linea',\n ...(token ? { Authorization: `Bearer ${token}` } : {}),\n ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),\n ...(cached?.etag ? { 'If-None-Match': cached.etag } : {})\n }\n let response: Response\n try {\n response = await this.doFetch(url, {\n method,\n headers,\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n signal: AbortSignal.timeout(this.timeoutMs)\n })\n } catch (error) {\n const failure = error as Error\n if (failure.name === 'TimeoutError' || failure.name === 'AbortError') {\n throw new GitError(`GitHub request timed out after ${this.timeoutMs}ms: ${method} ${path}`)\n }\n throw new GitError(failure.message ?? String(error))\n }\n if (response.status === 304 && cached) return { response, json: cached.json, cached: true }\n if (response.ok) return { response }\n\n let detail: Json = {}\n try {\n const text = await response.text()\n detail = text ? JSON.parse(text) : {}\n } catch {\n detail = {}\n }\n const wait = throttle(response, detail.message)\n if (wait !== null && attempt < MAX_RETRIES) {\n await sleep(wait)\n continue\n }\n if (response.status === 401) throw new GitAuthError(detail.message)\n const errors = ((detail.errors ?? []) as Json[]).map((e) => e.message ?? e.code).filter(Boolean).join('; ')\n throw new GitError(`${detail.message ?? response.statusText}${errors ? ` (${errors})` : ''}`, response.status)\n }\n }\n\n /** A JSON answer (`null` for \"no content\"). */\n async json({ token, method = 'GET', path, body }: { token: string | undefined, method?: string, path: string, body?: unknown }): Promise<Json> {\n const { response, json, cached } = await this.send({ token, method, path, body })\n if (cached) return json\n if (response.status === 204) return null\n const parsed = await response.json()\n if (method === 'GET') {\n const etag = response.headers.get('etag')\n if (etag) remember(`${tokenKey(token)}|${this.urlOf(path)}`, { etag, json: parsed })\n }\n return parsed\n }\n\n /** The bytes of a file (`null` when there is none). */\n async raw({ token, path }: { token: string | undefined, path: string }): Promise<Buffer | null> {\n try {\n const { response } = await this.send({ token, method: 'GET', path, accept: 'application/vnd.github.raw+json' })\n return Buffer.from(await response.arrayBuffer())\n } catch (error) {\n if ((error as { status?: number }).status === 404) return null\n throw error\n }\n }\n\n /** A stream of the body of the answer (an archive). */\n async stream({ token, path }: { token: string | undefined, path: string }): Promise<Readable> {\n const { response } = await this.send({ token, method: 'GET', path, accept: 'application/vnd.github+json' })\n return Readable.fromWeb(response.body as never)\n }\n\n /** Every item of a list, page after page. */\n async paginate({ token, path, perPage = 100 }: { token: string | undefined, path: string, perPage?: number }): Promise<Json[]> {\n const all: Json[] = []\n for (let page = 1; ; page++) {\n const separator = path.includes('?') ? '&' : '?'\n const batch = (await this.json({ token, path: `${path}${separator}per_page=${perPage}&page=${page}` })) as Json[]\n all.push(...batch)\n if (batch.length < perPage) return all\n }\n }\n}\n\nexport const clearGitHubCache = (): void => cache.clear()\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where GitHub is, and who LINEA is on it. Everything has the value of github.com unless it is given otherwise (GitHub Enterprise
|
|
3
|
+
* Server, or the in-memory GitHub of the dev stack).
|
|
4
|
+
*/
|
|
5
|
+
export interface GitHubConfig {
|
|
6
|
+
/** The website (default https://github.com): where the browser logs in. */
|
|
7
|
+
webUrl?: string | undefined;
|
|
8
|
+
/** The REST API (default https://api.github.com; for another `webUrl`, `<webUrl>/api/v3`). */
|
|
9
|
+
apiUrl?: string | undefined;
|
|
10
|
+
/** The OAuth App (or GitHub App) LINEA logs in with. */
|
|
11
|
+
clientId?: string | undefined;
|
|
12
|
+
clientSecret?: string | undefined;
|
|
13
|
+
/** Where the browser comes back to after logging in. */
|
|
14
|
+
redirectUri?: string | undefined;
|
|
15
|
+
/** The web editor (default https://github.dev). */
|
|
16
|
+
webIdeUrl?: string | undefined;
|
|
17
|
+
/** A token to read with when the user has none of their own (packages from public repositories need none). */
|
|
18
|
+
token?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare const githubWebUrl: (config?: GitHubConfig) => string;
|
|
21
|
+
export declare const githubApiUrl: (config?: GitHubConfig) => string;
|
|
22
|
+
export declare const githubWebIdeUrl: (config?: GitHubConfig) => string;
|
|
23
|
+
/** What LINEA asks the user to allow: their repositories (create, write, delete), the organisations they belong to, and webhooks. */
|
|
24
|
+
export declare const GITHUB_SCOPE = "repo delete_repo read:org write:repo_hook";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const trimmed = (url) => url.replace(/\/+$/, '');
|
|
2
|
+
export const githubWebUrl = (config = {}) => trimmed(config.webUrl ?? 'https://github.com');
|
|
3
|
+
export const githubApiUrl = (config = {}) => {
|
|
4
|
+
if (config.apiUrl)
|
|
5
|
+
return trimmed(config.apiUrl);
|
|
6
|
+
return githubWebUrl(config) === 'https://github.com' ? 'https://api.github.com' : `${githubWebUrl(config)}/api/v3`;
|
|
7
|
+
};
|
|
8
|
+
export const githubWebIdeUrl = (config = {}) => trimmed(config.webIdeUrl ?? 'https://github.dev');
|
|
9
|
+
/** What LINEA asks the user to allow: their repositories (create, write, delete), the organisations they belong to, and webhooks. */
|
|
10
|
+
export const GITHUB_SCOPE = 'repo delete_repo read:org write:repo_hook';
|
|
11
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/github/config.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAEhE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAuB,EAAE,EAAU,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,oBAAoB,CAAC,CAAA;AAEjH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAuB,EAAE,EAAU,EAAE;IAChE,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAChD,OAAO,YAAY,CAAC,MAAM,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,CAAA;AACpH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAuB,EAAE,EAAU,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,oBAAoB,CAAC,CAAA;AAEvH,qIAAqI;AACrI,MAAM,CAAC,MAAM,YAAY,GAAG,2CAA2C,CAAA","sourcesContent":["/**\n * Where GitHub is, and who LINEA is on it. Everything has the value of github.com unless it is given otherwise (GitHub Enterprise\n * Server, or the in-memory GitHub of the dev stack).\n */\nexport interface GitHubConfig {\n /** The website (default https://github.com): where the browser logs in. */\n webUrl?: string | undefined\n /** The REST API (default https://api.github.com; for another `webUrl`, `<webUrl>/api/v3`). */\n apiUrl?: string | undefined\n /** The OAuth App (or GitHub App) LINEA logs in with. */\n clientId?: string | undefined\n clientSecret?: string | undefined\n /** Where the browser comes back to after logging in. */\n redirectUri?: string | undefined\n /** The web editor (default https://github.dev). */\n webIdeUrl?: string | undefined\n /** A token to read with when the user has none of their own (packages from public repositories need none). */\n token?: string | undefined\n}\n\nconst trimmed = (url: string): string => url.replace(/\\/+$/, '')\n\nexport const githubWebUrl = (config: GitHubConfig = {}): string => trimmed(config.webUrl ?? 'https://github.com')\n\nexport const githubApiUrl = (config: GitHubConfig = {}): string => {\n if (config.apiUrl) return trimmed(config.apiUrl)\n return githubWebUrl(config) === 'https://github.com' ? 'https://api.github.com' : `${githubWebUrl(config)}/api/v3`\n}\n\nexport const githubWebIdeUrl = (config: GitHubConfig = {}): string => trimmed(config.webIdeUrl ?? 'https://github.dev')\n\n/** What LINEA asks the user to allow: their repositories (create, write, delete), the organisations they belong to, and webhooks. */\nexport const GITHUB_SCOPE = 'repo delete_repo read:org write:repo_hook'\n"]}
|