@app-vitals/agent-admin 1.58.0 → 1.59.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.58.0",
3
+ "version": "1.59.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.137.0",
45
- "@app-vitals/agent-lib": "1.58.0",
45
+ "@app-vitals/agent-lib": "1.59.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
@@ -94,5 +94,36 @@
94
94
  "authTest_missing_user_id": {
95
95
  "status": 200,
96
96
  "body": { "ok": true, "team_id": "T0123456789" }
97
+ },
98
+ "rotateConfigToken_success": {
99
+ "status": 200,
100
+ "body": {
101
+ "ok": true,
102
+ "token": "xoxb-rotated-access-token",
103
+ "refresh_token": "xoxe-1-rotated-refresh-token",
104
+ "team_id": "T0123456789",
105
+ "user_id": "U0AALR8M69X",
106
+ "iat": 1234567890,
107
+ "exp": 1234571490
108
+ }
109
+ },
110
+ "rotateConfigToken_invalid_refresh_token": {
111
+ "status": 200,
112
+ "body": { "ok": false, "error": "invalid_refresh_token" }
113
+ },
114
+ "rotateConfigToken_token_revoked": {
115
+ "status": 200,
116
+ "body": { "ok": false, "error": "token_revoked" }
117
+ },
118
+ "rotateConfigToken_http_error": {
119
+ "status": 500,
120
+ "body": { "ok": false, "error": "internal_error" }
121
+ },
122
+ "rotateConfigToken_missing_fields": {
123
+ "status": 200,
124
+ "body": {
125
+ "ok": true,
126
+ "token": "xoxb-rotated-access-token"
127
+ }
97
128
  }
98
129
  }
@@ -295,6 +295,94 @@ describe("HttpSlackProvisioningClient — authTest", () => {
295
295
  });
296
296
  });
297
297
 
298
+ // ─── rotateConfigToken ──────────────────────────────────────────────────────
299
+
300
+ describe("HttpSlackProvisioningClient — rotateConfigToken", () => {
301
+ it("POSTs form-encoded refresh_token to tooling.tokens.rotate and returns rotated tokens", async () => {
302
+ const { client, lastRequest } = makeClient("rotateConfigToken_success");
303
+ const result = await client.rotateConfigToken("xoxe-1-test-refresh-token");
304
+
305
+ const req = lastRequest();
306
+ expect(req.method).toBe("POST");
307
+ expect(req.url).toBe("https://slack.com/api/tooling.tokens.rotate");
308
+ expect(req.headers.get("content-type")).toBe(
309
+ "application/x-www-form-urlencoded",
310
+ );
311
+ const params = new URLSearchParams(req.body);
312
+ expect(params.get("refresh_token")).toBe("xoxe-1-test-refresh-token");
313
+
314
+ expect(result).toEqual({
315
+ accessToken: "xoxb-rotated-access-token",
316
+ refreshToken: "xoxe-1-rotated-refresh-token",
317
+ teamId: "T0123456789",
318
+ userId: "U0AALR8M69X",
319
+ iat: 1234567890,
320
+ exp: 1234571490,
321
+ });
322
+ });
323
+
324
+ it("throws SlackConfigTokenError with invalid_refresh_token code when Slack returns that error", async () => {
325
+ const { client } = makeClient("rotateConfigToken_invalid_refresh_token");
326
+ try {
327
+ await client.rotateConfigToken("xoxe-1-test-refresh-token");
328
+ expect.unreachable("Should have thrown");
329
+ } catch (err: unknown) {
330
+ expect(err instanceof Error).toBe(true);
331
+ const error = err as Error;
332
+ expect(error.message).not.toContain("xoxe-1-test-refresh-token");
333
+ if (err && typeof err === "object" && "code" in err) {
334
+ expect((err as any).code).toBe("invalid_refresh_token");
335
+ }
336
+ }
337
+ });
338
+
339
+ it("throws SlackConfigTokenError with token_revoked code when Slack returns that error", async () => {
340
+ const { client } = makeClient("rotateConfigToken_token_revoked");
341
+ try {
342
+ await client.rotateConfigToken("xoxe-1-test-refresh-token");
343
+ expect.unreachable("Should have thrown");
344
+ } catch (err: unknown) {
345
+ expect(err instanceof Error).toBe(true);
346
+ const error = err as Error;
347
+ expect(error.message).not.toContain("xoxe-1-test-refresh-token");
348
+ if (err && typeof err === "object" && "code" in err) {
349
+ expect((err as any).code).toBe("token_revoked");
350
+ }
351
+ }
352
+ });
353
+
354
+ it("throws SlackConfigTokenError with http_error code on HTTP error", async () => {
355
+ const { client } = makeClient("rotateConfigToken_http_error");
356
+ try {
357
+ await client.rotateConfigToken("xoxe-1-test-refresh-token");
358
+ expect.unreachable("Should have thrown");
359
+ } catch (err: unknown) {
360
+ expect(err instanceof Error).toBe(true);
361
+ const error = err as Error;
362
+ expect(error.message).toMatch(/Slack tooling\.tokens\.rotate HTTP error: 500/);
363
+ if (err && typeof err === "object" && "code" in err) {
364
+ expect((err as any).code).toBe("http_error");
365
+ }
366
+ }
367
+ });
368
+
369
+ it("throws SlackConfigTokenError when response is missing required fields", async () => {
370
+ const { client } = makeClient("rotateConfigToken_missing_fields");
371
+ try {
372
+ await client.rotateConfigToken("xoxe-1-test-refresh-token");
373
+ expect.unreachable("Should have thrown");
374
+ } catch (err: unknown) {
375
+ expect(err instanceof Error).toBe(true);
376
+ const error = err as Error;
377
+ expect(error.message).toContain("response missing required fields");
378
+ expect(error.message).not.toContain("xoxe-1-test-refresh-token");
379
+ if (err && typeof err === "object" && "code" in err) {
380
+ expect((err as any).code).toBe("missing_response_fields");
381
+ }
382
+ }
383
+ });
384
+ });
385
+
298
386
  // ─── Default construction (no opts) ─────────────────────────────────────────
299
387
 
300
388
  describe("HttpSlackProvisioningClient — default construction", () => {
@@ -9,6 +9,23 @@
9
9
  * directly in the response — no separate oauth.v2.access exchange needed.
10
10
  */
11
11
 
12
+ // ─── Errors ───────────────────────────────────────────────────────────────────
13
+
14
+ /**
15
+ * Typed error for Slack config token rotation failures.
16
+ * Errors include Slack API errors and HTTP errors.
17
+ * Error messages never contain token values.
18
+ */
19
+ export class SlackConfigTokenError extends Error {
20
+ constructor(
21
+ public readonly code: string,
22
+ message: string,
23
+ ) {
24
+ super(message);
25
+ this.name = "SlackConfigTokenError";
26
+ }
27
+ }
28
+
12
29
  // ─── Types ────────────────────────────────────────────────────────────────────
13
30
 
14
31
  interface AppManifestDisplayInfo {
@@ -112,6 +129,31 @@ export interface SlackProvisioningClient {
112
129
  authTest(botToken: string): Promise<{ userId: string }>;
113
130
  }
114
131
 
132
+ // ─── SlackConfigTokenClient ───────────────────────────────────────────────────
133
+
134
+ /**
135
+ * Client for Slack config token rotation operations.
136
+ * Used to refresh expired or rotating OAuth tokens via tooling.tokens.rotate.
137
+ */
138
+ export interface SlackConfigTokenClient {
139
+ /**
140
+ * Call tooling.tokens.rotate with a refresh token to get a new access token.
141
+ * Returns the new access token, refresh token, team ID, user ID, and timestamps.
142
+ * Throws SlackConfigTokenError on Slack API errors (invalid_refresh_token, token_revoked, etc.)
143
+ * or on HTTP errors.
144
+ */
145
+ rotateConfigToken(
146
+ refreshToken: string,
147
+ ): Promise<{
148
+ accessToken: string;
149
+ refreshToken: string;
150
+ teamId: string;
151
+ userId: string;
152
+ iat: number;
153
+ exp: number;
154
+ }>;
155
+ }
156
+
115
157
  // ─── Agent manifest ───────────────────────────────────────────────────────────
116
158
 
117
159
  /**
@@ -199,7 +241,9 @@ export function buildAgentManifest(
199
241
  *
200
242
  * The constructor takes optional Slack API URL overrides for testing/staging.
201
243
  */
202
- export class HttpSlackProvisioningClient implements SlackProvisioningClient {
244
+ export class HttpSlackProvisioningClient
245
+ implements SlackProvisioningClient, SlackConfigTokenClient
246
+ {
203
247
  private readonly apiBase: string;
204
248
  private readonly fetchFn: typeof fetch;
205
249
 
@@ -408,4 +452,76 @@ export class HttpSlackProvisioningClient implements SlackProvisioningClient {
408
452
  signingSecret: data.credentials.signing_secret,
409
453
  };
410
454
  }
455
+
456
+ async rotateConfigToken(
457
+ refreshToken: string,
458
+ ): Promise<{
459
+ accessToken: string;
460
+ refreshToken: string;
461
+ teamId: string;
462
+ userId: string;
463
+ iat: number;
464
+ exp: number;
465
+ }> {
466
+ const url = `${this.apiBase}/tooling.tokens.rotate`;
467
+ const params = new URLSearchParams({
468
+ refresh_token: refreshToken,
469
+ });
470
+
471
+ const resp = await this.fetchFn(url, {
472
+ method: "POST",
473
+ headers: {
474
+ "Content-Type": "application/x-www-form-urlencoded",
475
+ },
476
+ body: params.toString(),
477
+ });
478
+
479
+ if (!resp.ok) {
480
+ throw new SlackConfigTokenError(
481
+ "http_error",
482
+ `Slack tooling.tokens.rotate HTTP error: ${resp.status} ${resp.statusText}`,
483
+ );
484
+ }
485
+
486
+ const data = (await resp.json()) as {
487
+ ok: boolean;
488
+ error?: string;
489
+ token?: string;
490
+ refresh_token?: string;
491
+ team_id?: string;
492
+ user_id?: string;
493
+ iat?: number;
494
+ exp?: number;
495
+ };
496
+
497
+ if (!data.ok) {
498
+ throw new SlackConfigTokenError(
499
+ data.error ?? "unknown_error",
500
+ `Slack tooling.tokens.rotate failed: ${data.error}`,
501
+ );
502
+ }
503
+
504
+ if (
505
+ !data.token ||
506
+ !data.refresh_token ||
507
+ !data.team_id ||
508
+ !data.user_id ||
509
+ data.iat === undefined ||
510
+ data.exp === undefined
511
+ ) {
512
+ throw new SlackConfigTokenError(
513
+ "missing_response_fields",
514
+ "Slack tooling.tokens.rotate response missing required fields",
515
+ );
516
+ }
517
+
518
+ return {
519
+ accessToken: data.token,
520
+ refreshToken: data.refresh_token,
521
+ teamId: data.team_id,
522
+ userId: data.user_id,
523
+ iat: data.iat,
524
+ exp: data.exp,
525
+ };
526
+ }
411
527
  }