File size: 821 Bytes
6111b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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];
}