"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigFeatureFlagUserKey = exports.RIVET_FEATURE_FLAG_USER_KEY_HEADER = void 0;
exports.RIVET_FEATURE_FLAG_USER_KEY_HEADER = 'x-rivet-feature-flag-user-key';
const normalizeUserKey = (value) => {
    const trimmedValue = value?.trim();
    return trimmedValue && trimmedValue.length > 0 ? trimmedValue : undefined;
};
const getHeaderValue = (value) => {
    if (Array.isArray(value)) {
        return value[0];
    }
    return value;
};
/**
 * Gets the user key used to evaluate request-scoped feature flags.
 */
const getConfigFeatureFlagUserKey = ({ headers, fallbackEmail, }) => normalizeUserKey(getHeaderValue(headers[exports.RIVET_FEATURE_FLAG_USER_KEY_HEADER])) ??
    normalizeUserKey(fallbackEmail);
exports.getConfigFeatureFlagUserKey = getConfigFeatureFlagUserKey;
//# sourceMappingURL=featureFlagUserKey.js.map