import camelCase from 'lodash/camelCase';
import upperFirst from 'lodash/upperFirst';
import { getAllScopeMap } from './scopes';
export const parseScope = (scope) => {
    const [action, predicate] = scope.split(':');
    const [subjectPart, modifier] = predicate.split('@');
    const subject = upperFirst(camelCase(subjectPart));
    return [
        action,
        subject,
        modifier,
    ];
};
export const normalizeScopeName = (scope) => {
    const [action, subject, modifier] = parseScope(scope);
    return `${action}:${subject}${modifier ? `@${modifier}` : ''}`;
};
export const parseScopes = ({ scopes, isEnterprise, }) => {
    const scopeMap = getAllScopeMap({ isEnterprise });
    const valid = new Set();
    const invalid = [];
    scopes.forEach((rawScope) => {
        const normalized = normalizeScopeName(rawScope);
        if (scopeMap[normalized]) {
            valid.add(normalized);
        }
        else {
            invalid.push(normalized);
        }
    });
    return { valid, invalid };
};
//# sourceMappingURL=parseScopes.js.map