Add self-service API key usage status (#2908)

Integrated into release/v3.8.6
This commit is contained in:
guanbear
2026-05-30 00:16:53 +08:00
committed by diegosouzapw
parent 8b74fb48ca
commit fbe140c231
61 changed files with 2179 additions and 9 deletions

View File

@@ -0,0 +1,20 @@
export const SELF_USAGE_SCOPE = "self:usage";
export const SELF_ACCOUNT_QUOTA_SCOPE = "self:account-quota";
export const DEFAULT_SELF_SERVICE_SCOPES = [SELF_USAGE_SCOPE] as const;
export function hasSelfUsageScope(scopes: readonly string[] | null | undefined): boolean {
return Array.isArray(scopes) && scopes.includes(SELF_USAGE_SCOPE);
}
export function hasSelfAccountQuotaScope(scopes: readonly string[] | null | undefined): boolean {
return Array.isArray(scopes) && scopes.includes(SELF_ACCOUNT_QUOTA_SCOPE);
}
export function normalizeSelfServiceScopesForCreate(
scopes: readonly string[] | null | undefined
): string[] {
const normalized = new Set((scopes ?? []).filter((scope) => typeof scope === "string" && scope));
normalized.add(SELF_USAGE_SCOPE);
return [...normalized];
}

View File

@@ -491,7 +491,7 @@ export const importAgyAuthBulkSchema = z.object({
export const createKeySchema = z.object({
name: z.string().min(1, "Name is required").max(200),
noLog: z.boolean().optional(),
scopes: z.array(z.string().trim().min(1).max(64)).max(16).optional(),
scopes: z.array(z.string().trim().min(1).max(64)).max(32).optional(),
});
export const createSyncTokenSchema = z.object({
@@ -1826,7 +1826,7 @@ export const updateKeyPermissionsSchema = z
z.null(),
])
.optional(),
scopes: z.array(z.string().trim().min(1).max(64)).max(16).optional(),
scopes: z.array(z.string().trim().min(1).max(64)).max(32).optional(),
allowedEndpoints: z.array(z.string().trim().min(1).max(64)).max(20).optional(),
})
.superRefine((value, ctx) => {