mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 21:52:21 +03:00
Add self-service API key usage status (#2908)
Integrated into release/v3.8.6
This commit is contained in:
20
src/shared/constants/selfServiceScopes.ts
Normal file
20
src/shared/constants/selfServiceScopes.ts
Normal 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];
|
||||
}
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user