mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
30 lines
719 B
TypeScript
30 lines
719 B
TypeScript
import type { Scope, ScopeLevels, GlobalScopes, ScopeOptions } from './types';
|
|
|
|
export function hasScope(
|
|
scope: Scope | Scope[],
|
|
userScopes: GlobalScopes,
|
|
options?: ScopeOptions,
|
|
): boolean;
|
|
export function hasScope(
|
|
scope: Scope | Scope[],
|
|
userScopes: ScopeLevels,
|
|
options?: ScopeOptions,
|
|
): boolean;
|
|
export function hasScope(
|
|
scope: Scope | Scope[],
|
|
userScopes: unknown,
|
|
options: ScopeOptions = { mode: 'oneOf' },
|
|
): boolean {
|
|
if (!Array.isArray(scope)) {
|
|
scope = [scope];
|
|
}
|
|
|
|
const userScopeSet = new Set(Object.values(userScopes ?? {}).flat());
|
|
|
|
if (options.mode === 'allOf') {
|
|
return !!scope.length && scope.every((s) => userScopeSet.has(s));
|
|
}
|
|
|
|
return scope.some((s) => userScopeSet.has(s));
|
|
}
|