@dependfix/engine 0.3.0 → 0.5.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 +3 -0
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/chunks/auth.mjs +361 -0
- package/dist/chunks/auth.mjs.map +1 -0
- package/dist/chunks/index.d.mts +262 -0
- package/dist/index.d.mts +1378 -292
- package/dist/index.mjs +11160 -5373
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -10
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/rest";
|
|
2
|
+
//#region src/auth/auth-provider.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* GitHub 认证抽象层。
|
|
5
|
+
*
|
|
6
|
+
* 支持 PAT(classic / fine-grained)与 GitHub App installation token 两种认证路径。
|
|
7
|
+
* 调用方通过 `getOctokit()` 获取已认证的 Octokit 实例;通过 `getGitCredential()`
|
|
8
|
+
* 获取推送/clone 用的 Git 凭据;通过 `getCommitAuthor()` 获取 commit author 信息。
|
|
9
|
+
*
|
|
10
|
+
* `authProvider` 字段用于审计与调试(区分 PAT vs App 路径)。
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // 推荐:从 fromPat / fromApp 工厂构造
|
|
15
|
+
* const auth = fromPat('ghp_xxxx')
|
|
16
|
+
* const octokit = auth.getOctokit()
|
|
17
|
+
*
|
|
18
|
+
* // git push 凭据
|
|
19
|
+
* const { username, token } = auth.getGitCredential()
|
|
20
|
+
*
|
|
21
|
+
* // commit author(PAT 路径固定;App 路径动态)
|
|
22
|
+
* const { name, email } = auth.getCommitAuthor()
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface AuthProvider {
|
|
26
|
+
/** 获取已认证的 Octokit 实例 */
|
|
27
|
+
getOctokit(): Octokit;
|
|
28
|
+
/** 获取推送 / clone 用的 Git 凭据(用户名 + token) */
|
|
29
|
+
getGitCredential(): {
|
|
30
|
+
username: string;
|
|
31
|
+
token: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 获取 commit author 信息。
|
|
35
|
+
*
|
|
36
|
+
* - PAT 路径:固定返回 `{ name: 'dependfix[bot]', email: 'dependfix[bot]@users.noreply.github.com' }`(保持现有行为零变化)
|
|
37
|
+
* - GitHub App 路径:动态生成 `{app_id}+{bot_login}[bot]@users.noreply.github.com`(GitHub App 协议要求)
|
|
38
|
+
*/
|
|
39
|
+
getCommitAuthor(): {
|
|
40
|
+
name: string;
|
|
41
|
+
email: string;
|
|
42
|
+
};
|
|
43
|
+
/** 认证路径标识(用于审计 + 调试) */
|
|
44
|
+
readonly authProvider: 'pat' | 'github-app';
|
|
45
|
+
}
|
|
46
|
+
/** 工厂函数统一选项(与 OctokitClientOptions.retry 字段对齐) */
|
|
47
|
+
interface AuthProviderOptions {
|
|
48
|
+
/** API 限流 / 次要限流指数退避重试策略。默认 maxRetries=3。 */
|
|
49
|
+
retry?: {
|
|
50
|
+
maxRetries?: number;
|
|
51
|
+
baseDelayMs?: number;
|
|
52
|
+
maxBackoffMs?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** PAT 工厂参数(仅 token;retry 在 options 注入) */
|
|
56
|
+
type FromPatParams = string;
|
|
57
|
+
/** GitHub App 工厂参数 */
|
|
58
|
+
interface FromAppParams {
|
|
59
|
+
/** GitHub App ID */
|
|
60
|
+
appId: string;
|
|
61
|
+
/** PEM 格式私钥 */
|
|
62
|
+
privateKey: string;
|
|
63
|
+
/** Installation ID */
|
|
64
|
+
installationId: string;
|
|
65
|
+
/** Bot 用户名(用于 commit author 动态生成) */
|
|
66
|
+
botLogin?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* PAT 路径固定 commit author(保持现有行为零变化)。
|
|
70
|
+
*
|
|
71
|
+
* 注:现有 PAT 路径硬编码 `dependfix[bot]@users.noreply.github.com`,虽非真实 bot 身份(字符串约定),
|
|
72
|
+
* 但保持行为不变以确保 PAT 用户无感升级。已知缺陷由后续阶段修复。
|
|
73
|
+
*/
|
|
74
|
+
declare const PAT_COMMIT_AUTHOR: {
|
|
75
|
+
readonly name: "dependfix[bot]";
|
|
76
|
+
readonly email: "dependfix[bot]@users.noreply.github.com";
|
|
77
|
+
};
|
|
78
|
+
/** PAT 路径固定 Git 用户名(用于 git push 时的 Basic Auth) */
|
|
79
|
+
declare const PAT_GIT_USERNAME = "x-access-token";
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/auth/pat-provider.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* PAT 工厂函数。委托给 `PatAuthProvider` 类。
|
|
84
|
+
*
|
|
85
|
+
* 保留 `fromPat` 命名习惯便于与 `fromApp` 对齐(统一工厂语义)。
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const auth = fromPat('ghp_xxxx')
|
|
90
|
+
* const octokit = auth.getOctokit()
|
|
91
|
+
* const { username, token } = auth.getGitCredential()
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function fromPat(token: FromPatParams, options?: AuthProviderOptions): AuthProvider;
|
|
95
|
+
/**
|
|
96
|
+
* PAT 认证路径实现。
|
|
97
|
+
*
|
|
98
|
+
* `getOctokit()` 委托给 [`createGitHubClient`](../github/client.ts) 以复用现有 retry policy 与限流重试实现;
|
|
99
|
+
* Octokit 实例缓存以避免重复构造(每次 `new Octokit()` + `hook.wrap()` 都有开销)。
|
|
100
|
+
*
|
|
101
|
+
* 行为与原 `createGitHubClient({ token })` 等价:
|
|
102
|
+
* - `getOctokit()` 返回通过 PAT 认证的 Octokit 实例(含限流重试 hook)
|
|
103
|
+
* - `getGitCredential()` 返回推送用的 Basic Auth(username = `'x-access-token'`)
|
|
104
|
+
* - `getCommitAuthor()` 返回固定 `dependfix[bot]`(PAT 路径用户行为零变化)
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const auth = new PatAuthProvider('ghp_xxxx', { retry: { maxRetries: 3 } })
|
|
109
|
+
* const octokit = auth.getOctokit()
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare class PatAuthProvider implements AuthProvider {
|
|
113
|
+
readonly authProvider: "pat";
|
|
114
|
+
private readonly token;
|
|
115
|
+
private readonly retry?;
|
|
116
|
+
private cachedOctokit;
|
|
117
|
+
constructor(token: FromPatParams, options?: AuthProviderOptions);
|
|
118
|
+
/**
|
|
119
|
+
* 获取已认证的 Octokit 实例(首次调用构造并缓存)。
|
|
120
|
+
*/
|
|
121
|
+
getOctokit(): Octokit;
|
|
122
|
+
/** 获取推送 / clone 用的 Git 凭据(username = `'x-access-token'`,token = PAT) */
|
|
123
|
+
getGitCredential(): {
|
|
124
|
+
username: string;
|
|
125
|
+
token: string;
|
|
126
|
+
};
|
|
127
|
+
/** 获取 commit author(PAT 路径固定 `dependfix[bot]`) */
|
|
128
|
+
getCommitAuthor(): {
|
|
129
|
+
name: string;
|
|
130
|
+
email: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/auth/app-provider.d.ts
|
|
135
|
+
/**
|
|
136
|
+
* GitHub App 工厂函数。
|
|
137
|
+
*
|
|
138
|
+
* 委托给 [`AppAuthProvider`] 类。
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const auth = fromApp({
|
|
143
|
+
* appId: '123456',
|
|
144
|
+
* privateKey: '-----BEGIN RSA PRIVATE KEY-----\n...',
|
|
145
|
+
* installationId: '7890123',
|
|
146
|
+
* botLogin: 'dependfix-bot[bot]',
|
|
147
|
+
* })
|
|
148
|
+
* const octokit = auth.getOctokit()
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function fromApp(params: FromAppParams, options?: AuthProviderOptions): AuthProvider;
|
|
152
|
+
/**
|
|
153
|
+
* GitHub App 认证路径实现。
|
|
154
|
+
*
|
|
155
|
+
* 使用 [`@octokit/auth-app`](https://github.com/octokit/auth-app.js) 提供:
|
|
156
|
+
* - JWT signing(App 身份认证)
|
|
157
|
+
* - `getInstallationOctokit`(installation token 获取;库内置 59 分钟 LRU TTL 缓存)
|
|
158
|
+
* - 自动 installation token 轮换
|
|
159
|
+
*
|
|
160
|
+
* 注意:
|
|
161
|
+
* - `getGitCredential()` 返回的 `token` 字段为占位符(installation token 不能直接从 AppAuthProvider 获取;
|
|
162
|
+
* 由 [`@octokit/auth-app`](https://github.com/octokit/auth-app.js) 内部管理);调用方应通过 `getOctokit()`
|
|
163
|
+
* 拿到的 Octokit 实例进行 API 调用
|
|
164
|
+
* - `getCommitAuthor()` 按 GitHub App 协议动态生成 `{app_id}+{bot_login}[bot]@users.noreply.github.com`
|
|
165
|
+
* - Octokit 实例缓存以避免重复构造
|
|
166
|
+
*
|
|
167
|
+
* @see [C22 PAT 无感升级评估 §4.2 AuthProvider 接口设计](../../../../docs/design/governance/c22-pat-backward-compat.md)
|
|
168
|
+
*/
|
|
169
|
+
declare class AppAuthProvider implements AuthProvider {
|
|
170
|
+
readonly authProvider: "github-app";
|
|
171
|
+
private readonly params;
|
|
172
|
+
private readonly _options?;
|
|
173
|
+
private cachedOctokit;
|
|
174
|
+
constructor(params: FromAppParams, options?: AuthProviderOptions);
|
|
175
|
+
/**
|
|
176
|
+
* 获取已认证的 Octokit 实例。
|
|
177
|
+
*
|
|
178
|
+
* 首次调用时构造并缓存;后续调用复用同一实例。
|
|
179
|
+
* installation token 由 `@octokit/auth-app` 内部管理(59 分钟 LRU TTL 缓存)。
|
|
180
|
+
*
|
|
181
|
+
* **构造方式**:使用 `authStrategy: createAppAuth` + `auth: {appId, privateKey, installationId}`
|
|
182
|
+
* 双字段组合(`@octokit/auth-app` v8.x README 标准用法),**而非** `auth: createAppAuth(...)`
|
|
183
|
+
* 单字段调用——后者被 `@octokit/core` 视作字符串 token 路径抛 `Token passed to createTokenAuth is not a string`,
|
|
184
|
+
* 或被 `authStrategy` 字段调用后命中 `auth(state, authOptions)` 的 `default` 分支抛 `Invalid auth type: undefined`
|
|
185
|
+
* (todo.md §M18.4 e2e 验证 + audit quick depth Reject 后补修发现)。
|
|
186
|
+
*
|
|
187
|
+
* @see [@octokit/auth-app README §installation authentication](https://github.com/octokit/auth-app.js#installation-authentication)
|
|
188
|
+
*/
|
|
189
|
+
getOctokit(): Octokit;
|
|
190
|
+
/**
|
|
191
|
+
* 获取推送 / clone 用的 Git 凭据。
|
|
192
|
+
*
|
|
193
|
+
* 注意:installation token 由 `@octokit/auth-app` 内部管理,**不**能从 AppAuthProvider 直接获取;
|
|
194
|
+
* 本方法返回的 `token` 字段为占位符(`'installation-token-managed-by-octokit-auth-app'`)。
|
|
195
|
+
* 调用方应通过 `getOctokit()` 拿到的 Octokit 实例进行 API 调用(含 git push / clone 等写操作)。
|
|
196
|
+
*/
|
|
197
|
+
getGitCredential(): {
|
|
198
|
+
username: string;
|
|
199
|
+
token: string;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 获取 commit author。
|
|
203
|
+
*
|
|
204
|
+
* 按 GitHub App 协议动态生成 `{app_id}+{bot_login}[bot]@users.noreply.github.com`:
|
|
205
|
+
* - `name`:`{app_id}[bot]`(GitHub 自动识别 bot 身份)
|
|
206
|
+
* - `email`:`{app_id}+{bot_login}[bot]@users.noreply.github.com`(GitHub noreply email 格式)
|
|
207
|
+
*
|
|
208
|
+
* 当 `params.botLogin` 未提供时,使用 `dependfix[bot]` 作为 fallback(保持与 PAT 路径一致的格式);
|
|
209
|
+
* 但建议调用方显式提供 `botLogin` 以确保 commit author 真实 bot 身份归属。
|
|
210
|
+
*/
|
|
211
|
+
getCommitAuthor(): {
|
|
212
|
+
name: string;
|
|
213
|
+
email: string;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/auth/installation-token-cache.d.ts
|
|
218
|
+
/**
|
|
219
|
+
* Installation token 缓存层(**M18.1 commit 4 实施**)。
|
|
220
|
+
*
|
|
221
|
+
* 当前实现:**依赖 [@octokit/auth-app](https://github.com/octokit/auth-app.js) 内置缓存**
|
|
222
|
+
* (59 分钟 LRU TTL;GitHub token 有效期 60 分钟 - 1 分钟缓冲)。
|
|
223
|
+
*
|
|
224
|
+
* 本类作为未来扩展点:
|
|
225
|
+
* - 缓存统计(命中率 / 大小 / 清理 API)
|
|
226
|
+
* - 失败重试 + 报警(M18.2 集成时实施)
|
|
227
|
+
* - 多 worker 共享(Redis-backed;超出 M18.1 范围)
|
|
228
|
+
*
|
|
229
|
+
* 注意:
|
|
230
|
+
* - `getOrRefresh` 当前委托给 `createAppAuthentication` + `getInstallationOctokit`
|
|
231
|
+
* - 当 [@octokit/auth-app](https://github.com/octokit/auth-app.js) 内部缓存命中时不会触发 API 调用
|
|
232
|
+
* - 缓存未命中时自动调用 `POST /app/installations/{installation_id}/access_tokens` 获取新 token
|
|
233
|
+
*
|
|
234
|
+
* @see [C22 PAT 无感升级评估 §4.7 commit 拆分纪律](../../../../docs/design/governance/c22-pat-backward-compat.md)
|
|
235
|
+
*/
|
|
236
|
+
declare class InstallationTokenCache {
|
|
237
|
+
private readonly params;
|
|
238
|
+
private readonly ttlMs;
|
|
239
|
+
constructor(params: FromAppParams, options?: {
|
|
240
|
+
ttlMs?: number;
|
|
241
|
+
refreshThresholdMs?: number;
|
|
242
|
+
});
|
|
243
|
+
/**
|
|
244
|
+
* 获取或刷新 installation token。
|
|
245
|
+
*
|
|
246
|
+
* 当前为占位实现:直接返回 `'installation-token-managed-by-octokit-auth-app'` 占位字符串。
|
|
247
|
+
* 调用方应使用 `fromApp(params).getOctokit()` 获取真实 Octokit 实例(由 `@octokit/auth-app`
|
|
248
|
+
* 自动管理 installation token 缓存)。
|
|
249
|
+
*
|
|
250
|
+
* @throws 永不抛错(占位实现)
|
|
251
|
+
*/
|
|
252
|
+
getOrRefresh(): Promise<string>;
|
|
253
|
+
/** 清理过期缓存项(占位实现) */
|
|
254
|
+
clear(): void;
|
|
255
|
+
/** 获取缓存 TTL 配置(毫秒) */
|
|
256
|
+
getTtlMs(): number;
|
|
257
|
+
/** 获取 cache key(基于 installationId) */
|
|
258
|
+
static getCacheKey(params: FromAppParams): string;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
export { fromPat as a, FromAppParams as c, PAT_GIT_USERNAME as d, PatAuthProvider as i, FromPatParams as l, AppAuthProvider as n, AuthProvider as o, fromApp as r, AuthProviderOptions as s, InstallationTokenCache as t, PAT_COMMIT_AUTHOR as u };
|
|
262
|
+
//# sourceMappingURL=index.d.mts.map
|