Files
OmniRoute/src/shared/constants/selfServiceScopes.ts
guanbear fbe140c231 Add self-service API key usage status (#2908)
Integrated into release/v3.8.6
2026-05-29 13:20:08 -03:00

21 lines
801 B
TypeScript

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];
}