@app-vitals/agent-admin 1.54.1 → 1.56.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/openapi.json +12 -0
- package/openapi.platform.json +12 -0
- package/package.json +2 -2
- package/prisma/client/internal/class.ts +4 -4
- package/prisma/client/internal/prismaNamespace.ts +4 -0
- package/prisma/client/internal/prismaNamespaceBrowser.ts +4 -0
- package/prisma/client/models/Account.ts +156 -0
- package/prisma/client/models/AgentMarketplace.ts +71 -1
- package/prisma/client/models/GitHubEnterpriseApp.ts +338 -12
- package/prisma/migrations/20261116000000_github_enterprise_app_account_id/migration.sql +21 -0
- package/prisma/migrations/20261116100000_add_agent_marketplace_row_source/migration.sql +5 -0
- package/prisma/schema/schema.prisma +20 -4
- package/src/agent-marketplaces-api.integration.test.ts +112 -0
- package/src/agent-marketplaces.integration.test.ts +9 -0
- package/src/agent-marketplaces.ts +52 -2
- package/src/agents-api.ts +3 -0
- package/src/api.ts +16 -8
- package/src/github-enterprise-api.integration.test.ts +5 -5
- package/src/github-enterprise-apps.integration.test.ts +101 -3
- package/src/github-enterprise-apps.ts +68 -23
- package/src/github-enterprise-isolation.unit.test.ts +10 -0
- package/src/openapi-schemas.ts +5 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/github-enterprise-apps.ts
|
|
3
3
|
* GitHubEnterpriseAppService — storage for the two optional admin-level GitHub
|
|
4
|
-
* Apps ('installer' and 'lookup'), at most one row per role.
|
|
5
|
-
*
|
|
4
|
+
* Apps ('installer' and 'lookup'), at most one row per (accountId, role).
|
|
5
|
+
* accountId null is the deployment-wide pair; an account row overrides it for
|
|
6
|
+
* that account (get() falls back to the deployment-wide row). Every method takes
|
|
7
|
+
* an optional accountId; omitting it behaves as before (deployment-wide row).
|
|
8
|
+
* No rows means the feature is off.
|
|
6
9
|
*
|
|
7
10
|
* The private key is encrypted on write (AES-256-GCM via TokenCrypto) and is
|
|
8
11
|
* never returned by any read path: reads return metadata plus a `keySet` flag.
|
|
@@ -26,6 +29,8 @@ export type GitHubEnterpriseAppRole =
|
|
|
26
29
|
(typeof GITHUB_ENTERPRISE_APP_ROLES)[number];
|
|
27
30
|
|
|
28
31
|
export interface GitHubEnterpriseAppMetadata {
|
|
32
|
+
/** Null/absent for the deployment-wide app. */
|
|
33
|
+
accountId?: string | null;
|
|
29
34
|
role: string;
|
|
30
35
|
appId: string;
|
|
31
36
|
slug: string;
|
|
@@ -40,6 +45,8 @@ export interface GitHubEnterpriseAppMetadata {
|
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
export interface SaveGitHubEnterpriseAppInput {
|
|
48
|
+
/** Omit/null for the deployment-wide app. */
|
|
49
|
+
accountId?: string | null;
|
|
43
50
|
role: GitHubEnterpriseAppRole;
|
|
44
51
|
appId: string;
|
|
45
52
|
slug: string;
|
|
@@ -50,6 +57,7 @@ export interface SaveGitHubEnterpriseAppInput {
|
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
interface GitHubEnterpriseAppRow {
|
|
60
|
+
accountId?: string | null;
|
|
53
61
|
role: string;
|
|
54
62
|
appId: string;
|
|
55
63
|
slug: string;
|
|
@@ -86,6 +94,7 @@ export function toGitHubEnterpriseAppMetadata(
|
|
|
86
94
|
row: GitHubEnterpriseAppRow,
|
|
87
95
|
): GitHubEnterpriseAppMetadata {
|
|
88
96
|
return {
|
|
97
|
+
accountId: row.accountId ?? null,
|
|
89
98
|
role: row.role,
|
|
90
99
|
appId: row.appId,
|
|
91
100
|
slug: row.slug,
|
|
@@ -115,7 +124,23 @@ export class GitHubEnterpriseAppService {
|
|
|
115
124
|
private clock: Clock = SystemClock(),
|
|
116
125
|
) {}
|
|
117
126
|
|
|
118
|
-
/**
|
|
127
|
+
/** Exact-scope row lookup: no fallback. */
|
|
128
|
+
private findExact(role: GitHubEnterpriseAppRole, accountId: string | null) {
|
|
129
|
+
return this.prisma.gitHubEnterpriseApp.findFirst({
|
|
130
|
+
where: { role, accountId },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Account row if present, else the deployment-wide row. */
|
|
135
|
+
private async resolve(
|
|
136
|
+
role: GitHubEnterpriseAppRole,
|
|
137
|
+
accountId: string | null,
|
|
138
|
+
) {
|
|
139
|
+
const own = accountId ? await this.findExact(role, accountId) : null;
|
|
140
|
+
return own ?? (await this.findExact(role, null));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Create or replace the app for a (accountId, role). Resets validation state. */
|
|
119
144
|
async save(
|
|
120
145
|
input: SaveGitHubEnterpriseAppInput,
|
|
121
146
|
): Promise<GitHubEnterpriseAppMetadata> {
|
|
@@ -124,6 +149,7 @@ export class GitHubEnterpriseAppService {
|
|
|
124
149
|
if (!input.privateKey) {
|
|
125
150
|
throw new UnprocessableEntityError("privateKey is required");
|
|
126
151
|
}
|
|
152
|
+
const accountId = input.accountId ?? null;
|
|
127
153
|
const data = {
|
|
128
154
|
appId: input.appId,
|
|
129
155
|
slug: input.slug,
|
|
@@ -135,48 +161,66 @@ export class GitHubEnterpriseAppService {
|
|
|
135
161
|
lastValidationError: null,
|
|
136
162
|
updatedAt: this.clock.now(),
|
|
137
163
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
164
|
+
// Not upsert: Prisma cannot target the NULL accountId side of the
|
|
165
|
+
// composite unique. The partial unique indexes still reject a racing
|
|
166
|
+
// duplicate insert.
|
|
167
|
+
const existing = await this.findExact(input.role, accountId);
|
|
168
|
+
const row = existing
|
|
169
|
+
? await this.prisma.gitHubEnterpriseApp.update({
|
|
170
|
+
where: { id: existing.id },
|
|
171
|
+
data,
|
|
172
|
+
})
|
|
173
|
+
: await this.prisma.gitHubEnterpriseApp.create({
|
|
174
|
+
data: { role: input.role, accountId, ...data },
|
|
175
|
+
});
|
|
143
176
|
return toGitHubEnterpriseAppMetadata(row);
|
|
144
177
|
}
|
|
145
178
|
|
|
179
|
+
/** The account's row if present, otherwise the deployment-wide row. */
|
|
146
180
|
async get(
|
|
147
181
|
role: GitHubEnterpriseAppRole,
|
|
182
|
+
accountId?: string | null,
|
|
148
183
|
): Promise<GitHubEnterpriseAppMetadata | null> {
|
|
149
184
|
assertRole(role);
|
|
150
|
-
const row = await this.
|
|
151
|
-
where: { role },
|
|
152
|
-
});
|
|
185
|
+
const row = await this.resolve(role, accountId ?? null);
|
|
153
186
|
return row ? toGitHubEnterpriseAppMetadata(row) : null;
|
|
154
187
|
}
|
|
155
188
|
|
|
156
|
-
|
|
189
|
+
/** Rows at exactly this scope (deployment-wide when accountId is omitted). */
|
|
190
|
+
async list(
|
|
191
|
+
accountId?: string | null,
|
|
192
|
+
): Promise<GitHubEnterpriseAppMetadata[]> {
|
|
157
193
|
const rows = await this.prisma.gitHubEnterpriseApp.findMany({
|
|
194
|
+
where: { accountId: accountId ?? null },
|
|
158
195
|
orderBy: { role: "asc" },
|
|
159
196
|
});
|
|
160
197
|
return rows.map(toGitHubEnterpriseAppMetadata);
|
|
161
198
|
}
|
|
162
199
|
|
|
163
|
-
/** Delete the app
|
|
164
|
-
async delete(
|
|
200
|
+
/** Delete the app at exactly this (accountId, role). No-ops if absent. */
|
|
201
|
+
async delete(
|
|
202
|
+
role: GitHubEnterpriseAppRole,
|
|
203
|
+
accountId?: string | null,
|
|
204
|
+
): Promise<void> {
|
|
165
205
|
assertRole(role);
|
|
166
|
-
await this.prisma.gitHubEnterpriseApp.deleteMany({
|
|
206
|
+
await this.prisma.gitHubEnterpriseApp.deleteMany({
|
|
207
|
+
where: { role, accountId: accountId ?? null },
|
|
208
|
+
});
|
|
167
209
|
}
|
|
168
210
|
|
|
169
211
|
/**
|
|
170
|
-
* Server-side only: decrypt the stored PEM
|
|
212
|
+
* Server-side only: decrypt the stored PEM of the row get() would return
|
|
213
|
+
* (account row, else deployment-wide). Strict — any failure throws
|
|
171
214
|
* PrivateKeyDecryptError (never includes the PEM or ciphertext). Returns
|
|
172
|
-
* null when
|
|
215
|
+
* null when no row resolves.
|
|
173
216
|
*/
|
|
174
|
-
async getPrivateKey(
|
|
217
|
+
async getPrivateKey(
|
|
218
|
+
role: GitHubEnterpriseAppRole,
|
|
219
|
+
accountId?: string | null,
|
|
220
|
+
): Promise<string | null> {
|
|
175
221
|
assertRole(role);
|
|
176
222
|
if (!this.crypto) throw new PrivateKeyEncryptionUnavailableError();
|
|
177
|
-
const row = await this.
|
|
178
|
-
where: { role },
|
|
179
|
-
});
|
|
223
|
+
const row = await this.resolve(role, accountId ?? null);
|
|
180
224
|
if (!row) return null;
|
|
181
225
|
try {
|
|
182
226
|
return this.crypto.decrypt(row.privateKeyEncrypted);
|
|
@@ -185,14 +229,15 @@ export class GitHubEnterpriseAppService {
|
|
|
185
229
|
}
|
|
186
230
|
}
|
|
187
231
|
|
|
188
|
-
/** Record the outcome of a validation attempt. The error text must not contain key material. */
|
|
232
|
+
/** Record the outcome of a validation attempt on exactly this (accountId, role). The error text must not contain key material. */
|
|
189
233
|
async recordValidation(
|
|
190
234
|
role: GitHubEnterpriseAppRole,
|
|
191
235
|
result: { status: string; error?: string | null },
|
|
236
|
+
accountId?: string | null,
|
|
192
237
|
): Promise<void> {
|
|
193
238
|
assertRole(role);
|
|
194
239
|
await this.prisma.gitHubEnterpriseApp.updateMany({
|
|
195
|
-
where: { role },
|
|
240
|
+
where: { role, accountId: accountId ?? null },
|
|
196
241
|
data: {
|
|
197
242
|
lastValidationStatus: result.status,
|
|
198
243
|
lastValidatedAt: this.clock.now(),
|
|
@@ -79,6 +79,16 @@ describe("GitHub Enterprise key isolation", () => {
|
|
|
79
79
|
]);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
+
it("no source outside the allowlist reaches the key through the Account relation", () => {
|
|
83
|
+
const offenders = files
|
|
84
|
+
.map((f) => relative(REPO, f))
|
|
85
|
+
.filter((rel) => !ALLOWED.has(rel))
|
|
86
|
+
.filter((rel) =>
|
|
87
|
+
/githubEnterpriseApps/.test(readFileSync(join(REPO, rel), "utf-8")),
|
|
88
|
+
);
|
|
89
|
+
expect(offenders).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
82
92
|
it("the config bundle and env serializers never read the enterprise table", () => {
|
|
83
93
|
for (const rel of ["admin/src/agent-envs.ts", "admin/src/api.ts"]) {
|
|
84
94
|
const src = readFileSync(join(REPO, rel), "utf-8");
|
package/src/openapi-schemas.ts
CHANGED
|
@@ -927,6 +927,11 @@ export const AgentMarketplaceSchema = z
|
|
|
927
927
|
name: z.string().openapi({ example: "shipwright" }),
|
|
928
928
|
source: z.string().openapi({ example: "app-vitals/shipwright" }),
|
|
929
929
|
ref: z.string().nullable().openapi({ example: "main" }),
|
|
930
|
+
rowSource: z
|
|
931
|
+
.enum(["template", "custom"])
|
|
932
|
+
.optional()
|
|
933
|
+
.openapi({ example: "custom" }),
|
|
934
|
+
enabled: z.boolean().optional().openapi({ example: true }),
|
|
930
935
|
createdAt: z
|
|
931
936
|
.string()
|
|
932
937
|
.datetime()
|