@app-vitals/agent-admin 1.60.0 → 1.62.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.platform.json +75 -0
- package/package.json +2 -2
- package/prisma/client/browser.ts +5 -0
- package/prisma/client/client.ts +5 -0
- package/prisma/client/internal/class.ts +14 -4
- package/prisma/client/internal/prismaNamespace.ts +94 -1
- package/prisma/client/internal/prismaNamespaceBrowser.ts +18 -0
- package/prisma/client/models/Account.ts +164 -0
- package/prisma/client/models/SlackConfigToken.ts +1574 -0
- package/prisma/client/models.ts +1 -0
- package/prisma/migrations/20261115000000_add_slack_config_token/migration.sql +34 -0
- package/prisma/schema/schema.prisma +33 -1
- package/src/admin-ui-github-enterprise-pages.ts +88 -16
- package/src/admin-ui-github-enterprise.smoke.test.ts +135 -12
- package/src/admin-ui-github-enterprise.ts +59 -18
- package/src/admin-ui.ts +2 -1
- package/src/agents-api.ts +4 -1
- package/src/github-access-preview.ts +2 -0
- package/src/github-enterprise-api.smoke.test.ts +171 -27
- package/src/github-enterprise-api.ts +63 -25
- package/src/github-installation-wiring.ts +15 -13
- package/src/github-lookup-repositories.integration.test.ts +136 -6
- package/src/github-lookup-repositories.ts +4 -1
- package/src/github-sync.ts +1 -1
- package/src/installation-ports.ts +16 -3
- package/src/installation-repos-service.ts +9 -3
- package/src/slack-config-token.integration.test.ts +208 -0
- package/src/slack-config-token.ts +181 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/slack-config-token.ts
|
|
3
|
+
* SlackConfigTokenService — storage for the Slack app-configuration token
|
|
4
|
+
* (refresh token plus short-lived access token), scoped like AgentTemplate:
|
|
5
|
+
* accountId null = deployment-wide default, an account row overrides it.
|
|
6
|
+
*
|
|
7
|
+
* Tokens are encrypted on write (AES-256-GCM via a strict TokenCrypto) and are
|
|
8
|
+
* never returned by any read path: reads return metadata plus `*Set` flags.
|
|
9
|
+
* save() refuses when no encryption key is configured (no plain-text fallback).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
13
|
+
import { type Clock, SystemClock } from "./clock.ts";
|
|
14
|
+
import { UnprocessableEntityError } from "./errors.ts";
|
|
15
|
+
import type { TokenCrypto } from "./token-crypto.ts";
|
|
16
|
+
|
|
17
|
+
export interface SlackConfigTokenMetadata {
|
|
18
|
+
id: string;
|
|
19
|
+
/** null = deployment-wide default. */
|
|
20
|
+
accountId: string | null;
|
|
21
|
+
refreshTokenSet: boolean;
|
|
22
|
+
accessTokenSet: boolean;
|
|
23
|
+
accessTokenExpiresAt: Date | null;
|
|
24
|
+
slackTeamId: string | null;
|
|
25
|
+
slackUserId: string | null;
|
|
26
|
+
lastRotatedAt: Date | null;
|
|
27
|
+
lastError: string | null;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SaveSlackConfigTokenInput {
|
|
33
|
+
/** Encrypted before it is stored. */
|
|
34
|
+
refreshToken: string;
|
|
35
|
+
/** Encrypted before it is stored. */
|
|
36
|
+
accessToken?: string | null;
|
|
37
|
+
accessTokenExpiresAt?: Date | null;
|
|
38
|
+
slackTeamId?: string | null;
|
|
39
|
+
slackUserId?: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface SlackConfigTokenRow {
|
|
43
|
+
id: string;
|
|
44
|
+
accountId: string | null;
|
|
45
|
+
refreshTokenEncrypted: string;
|
|
46
|
+
accessTokenEncrypted: string | null;
|
|
47
|
+
accessTokenExpiresAt: Date | null;
|
|
48
|
+
slackTeamId: string | null;
|
|
49
|
+
slackUserId: string | null;
|
|
50
|
+
lastRotatedAt: Date | null;
|
|
51
|
+
lastError: string | null;
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
updatedAt: Date;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class SlackConfigTokenEncryptionUnavailableError extends UnprocessableEntityError {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(
|
|
59
|
+
"SHIPWRIGHT_ENCRYPTION_KEY is not configured; refusing to store a Slack config token unencrypted. Set it to a 64-character hex string (openssl rand -hex 32) and retry.",
|
|
60
|
+
);
|
|
61
|
+
this.name = "SlackConfigTokenEncryptionUnavailableError";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Serializer: metadata plus set flags. Never includes token material. */
|
|
66
|
+
export function toSlackConfigTokenMetadata(
|
|
67
|
+
row: SlackConfigTokenRow,
|
|
68
|
+
): SlackConfigTokenMetadata {
|
|
69
|
+
return {
|
|
70
|
+
id: row.id,
|
|
71
|
+
accountId: row.accountId,
|
|
72
|
+
refreshTokenSet: row.refreshTokenEncrypted.length > 0,
|
|
73
|
+
accessTokenSet: !!row.accessTokenEncrypted,
|
|
74
|
+
accessTokenExpiresAt: row.accessTokenExpiresAt,
|
|
75
|
+
slackTeamId: row.slackTeamId,
|
|
76
|
+
slackUserId: row.slackUserId,
|
|
77
|
+
lastRotatedAt: row.lastRotatedAt,
|
|
78
|
+
lastError: row.lastError,
|
|
79
|
+
createdAt: row.createdAt,
|
|
80
|
+
updatedAt: row.updatedAt,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isUniqueViolation(err: unknown): boolean {
|
|
85
|
+
return (
|
|
86
|
+
typeof err === "object" &&
|
|
87
|
+
err !== null &&
|
|
88
|
+
(err as { code?: unknown }).code === "P2002"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class SlackConfigTokenService {
|
|
93
|
+
constructor(
|
|
94
|
+
private prisma: PrismaClient,
|
|
95
|
+
/** Strict crypto (see makeStrictTokenCrypto); null when no encryption key is configured. */
|
|
96
|
+
private crypto: TokenCrypto | null,
|
|
97
|
+
private clock: Clock = SystemClock(),
|
|
98
|
+
) {}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Create or replace the token for a scope (accountId null = deployment-wide
|
|
102
|
+
* default). Resets lastError; stamps lastRotatedAt.
|
|
103
|
+
*/
|
|
104
|
+
async save(
|
|
105
|
+
accountId: string | null,
|
|
106
|
+
input: SaveSlackConfigTokenInput,
|
|
107
|
+
): Promise<SlackConfigTokenMetadata> {
|
|
108
|
+
if (!this.crypto) throw new SlackConfigTokenEncryptionUnavailableError();
|
|
109
|
+
if (!input.refreshToken) {
|
|
110
|
+
throw new UnprocessableEntityError("refreshToken is required");
|
|
111
|
+
}
|
|
112
|
+
const now = this.clock.now();
|
|
113
|
+
const data = {
|
|
114
|
+
refreshTokenEncrypted: this.crypto.encrypt(input.refreshToken),
|
|
115
|
+
accessTokenEncrypted: input.accessToken
|
|
116
|
+
? this.crypto.encrypt(input.accessToken)
|
|
117
|
+
: null,
|
|
118
|
+
accessTokenExpiresAt: input.accessTokenExpiresAt ?? null,
|
|
119
|
+
slackTeamId: input.slackTeamId ?? null,
|
|
120
|
+
slackUserId: input.slackUserId ?? null,
|
|
121
|
+
lastRotatedAt: now,
|
|
122
|
+
lastError: null,
|
|
123
|
+
updatedAt: now,
|
|
124
|
+
};
|
|
125
|
+
// Prisma has no upsert for a nullable-scoped partial unique index, so
|
|
126
|
+
// update-then-create; a concurrent create loses on the index and retries
|
|
127
|
+
// as an update.
|
|
128
|
+
const update = async () => {
|
|
129
|
+
const existing = await this.prisma.slackConfigToken.findFirst({
|
|
130
|
+
where: { accountId },
|
|
131
|
+
});
|
|
132
|
+
if (!existing) return null;
|
|
133
|
+
return this.prisma.slackConfigToken.update({
|
|
134
|
+
where: { id: existing.id },
|
|
135
|
+
data,
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
let row = await update();
|
|
139
|
+
if (!row) {
|
|
140
|
+
try {
|
|
141
|
+
row = await this.prisma.slackConfigToken.create({
|
|
142
|
+
data: { accountId, ...data },
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (!isUniqueViolation(err)) throw err;
|
|
146
|
+
row = await update();
|
|
147
|
+
if (!row) throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return toSlackConfigTokenMetadata(row);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Metadata for exactly this scope (no fallback), or null. */
|
|
154
|
+
async get(
|
|
155
|
+
accountId: string | null,
|
|
156
|
+
): Promise<SlackConfigTokenMetadata | null> {
|
|
157
|
+
const row = await this.prisma.slackConfigToken.findFirst({
|
|
158
|
+
where: { accountId },
|
|
159
|
+
});
|
|
160
|
+
return row ? toSlackConfigTokenMetadata(row) : null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Account row, else the deployment-wide default row, else null. */
|
|
164
|
+
async resolveForAccount(
|
|
165
|
+
accountId: string,
|
|
166
|
+
): Promise<SlackConfigTokenMetadata | null> {
|
|
167
|
+
return (await this.get(accountId)) ?? (await this.get(null));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async list(): Promise<SlackConfigTokenMetadata[]> {
|
|
171
|
+
const rows = await this.prisma.slackConfigToken.findMany({
|
|
172
|
+
orderBy: { createdAt: "asc" },
|
|
173
|
+
});
|
|
174
|
+
return rows.map(toSlackConfigTokenMetadata);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Delete the token for a scope. No-ops if absent. */
|
|
178
|
+
async clear(accountId: string | null): Promise<void> {
|
|
179
|
+
await this.prisma.slackConfigToken.deleteMany({ where: { accountId } });
|
|
180
|
+
}
|
|
181
|
+
}
|