Skip to content

Commit a93d7f2

Browse files
committed
refactor(console): the access records' shared columns and expiry rule live in accessRecords.ts
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e794ddd commit a93d7f2

3 files changed

Lines changed: 54 additions & 36 deletions

File tree

‎ui/packages/app-shell/src/console/connect/AuthorizedAccessList.tsx‎

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,13 @@ import { AlertCircle, Bot, KeyRound, ShieldCheck } from 'lucide-react';
5353
import { useAuth } from '@object-ui/auth';
5454
import { formatDate, formatDateTime, useObjectTranslation } from '@object-ui/i18n';
5555
import { notifyDataChanged, useAdapter, useDataInvalidation } from '@object-ui/react';
56-
57-
/** The `sys_api_key` columns the list reads; the key's secret is never among them. */
58-
export const API_KEY_LIST_FIELDS = [
59-
'id',
60-
'name',
61-
'prefix',
62-
'created_at',
63-
'last_used_at',
64-
'expires_at',
65-
'revoked',
66-
] as const;
67-
68-
export interface ApiKeyRow {
69-
id: string;
70-
name?: string | null;
71-
prefix?: string | null;
72-
created_at?: string | null;
73-
last_used_at?: string | null;
74-
expires_at?: string | null;
75-
revoked?: boolean | null;
76-
}
77-
78-
type ShellClient = ReturnType<NonNullable<ReturnType<typeof useAdapter>>['getClient']>;
79-
/** What `oauth.authorizedClients.list()` answers, read off the adapter's own client. */
80-
export type AuthorizedClientsList = Awaited<ReturnType<ShellClient['oauth']['authorizedClients']['list']>>;
81-
export type AuthorizedClient = AuthorizedClientsList['clients'][number];
56+
import {
57+
API_KEY_LIST_FIELDS,
58+
isExpired,
59+
type ApiKeyRow,
60+
type AuthorizedClient,
61+
type AuthorizedClientsList,
62+
} from './accessRecords.js';
8263

8364
type Translate = (key: string, options?: Record<string, unknown>) => string;
8465

@@ -103,18 +84,11 @@ function describeGrantedScope(scope: string, t: Translate): string {
10384
return key ? t(key) : t('oauth.consent.scope.unrecognised', { scope });
10485
}
10586

106-
/** A key past its `expires_at` no longer authenticates, revoked or not. */
107-
export function isExpired(row: ApiKeyRow, now: number): boolean {
108-
if (!row.expires_at) return false;
109-
const at = Date.parse(row.expires_at);
110-
return Number.isFinite(at) && at <= now;
111-
}
112-
113-
export function errorText(e: unknown): string {
87+
function errorText(e: unknown): string {
11488
return e instanceof Error ? e.message : String(e);
11589
}
11690

117-
export function assistantName(c: AuthorizedClient, t: Translate): string {
91+
function assistantName(c: AuthorizedClient, t: Translate): string {
11892
return c.name ?? t('connectAgent.access.unnamed');
11993
}
12094

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The two records that say what can act as the signed-in person, as the
5+
* Connect an AI Assistant page reads them: the AI assistants they authorized
6+
* (`oauth.authorizedClients`) and their API keys (`sys_api_key`). Shared by the
7+
* "What can act as you" list and `useConnectedAccess`, so both read the same
8+
* columns and judge a key's expiry the same way.
9+
*/
10+
11+
import type { useAdapter } from '@object-ui/react';
12+
13+
/** The `sys_api_key` columns the list reads; the key's secret is never among them. */
14+
export const API_KEY_LIST_FIELDS = [
15+
'id',
16+
'name',
17+
'prefix',
18+
'created_at',
19+
'last_used_at',
20+
'expires_at',
21+
'revoked',
22+
] as const;
23+
24+
export interface ApiKeyRow {
25+
id: string;
26+
name?: string | null;
27+
prefix?: string | null;
28+
created_at?: string | null;
29+
last_used_at?: string | null;
30+
expires_at?: string | null;
31+
revoked?: boolean | null;
32+
}
33+
34+
type ShellClient = ReturnType<NonNullable<ReturnType<typeof useAdapter>>['getClient']>;
35+
/** What `oauth.authorizedClients.list()` answers, read off the adapter's own client. */
36+
export type AuthorizedClientsList = Awaited<ReturnType<ShellClient['oauth']['authorizedClients']['list']>>;
37+
export type AuthorizedClient = AuthorizedClientsList['clients'][number];
38+
39+
/** A key past its `expires_at` no longer authenticates, revoked or not. */
40+
export function isExpired(row: ApiKeyRow, now: number): boolean {
41+
if (!row.expires_at) return false;
42+
const at = Date.parse(row.expires_at);
43+
return Number.isFinite(at) && at <= now;
44+
}

‎ui/packages/app-shell/src/console/connect/connectedAccess.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
isExpired,
4040
type ApiKeyRow,
4141
type AuthorizedClient,
42-
} from './AuthorizedAccessList.js';
42+
} from './accessRecords.js';
4343

4444
export interface ConnectedEntry {
4545
kind: 'assistant' | 'apiKey';

0 commit comments

Comments
 (0)