"use strict";
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPersistenceKeyPolicy = exports.PERSISTENCE_KEY_POLICY = exports.PERSISTENCE_STORAGE_GROUPS = void 0;
var constants_1 = require("./constants");
var persistence_key_transforms_1 = require("./persistence-key-transforms");
var core_1 = require("@posthog/core");
exports.PERSISTENCE_STORAGE_GROUPS = ['flags', 'surveys'];
exports.PERSISTENCE_KEY_POLICY = (_a = {},
    _a[constants_1.PEOPLE_DISTINCT_ID_KEY] = { exposure: 'hidden' },
    _a[constants_1.ALIAS_ID_KEY] = { exposure: 'hidden' },
    _a[constants_1.CAMPAIGN_IDS_KEY] = { exposure: 'hidden' },
    _a[constants_1.EVENT_TIMERS_KEY] = { exposure: 'hidden' },
    _a[constants_1.AUTOCAPTURE_DISABLED_SERVER_SIDE] = { exposure: 'event' },
    _a[constants_1.HEATMAPS_ENABLED_SERVER_SIDE] = { exposure: 'hidden' },
    _a[constants_1.EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE] = { exposure: 'event' },
    _a[constants_1.ERROR_TRACKING_SUPPRESSION_RULES] = { exposure: 'hidden' },
    _a[constants_1.ERROR_TRACKING_CAPTURE_EXTENSION_EXCEPTIONS] = { exposure: 'event' },
    _a[constants_1.WEB_VITALS_ENABLED_SERVER_SIDE] = { exposure: 'event' },
    _a[constants_1.DEAD_CLICKS_ENABLED_SERVER_SIDE] = { exposure: 'event' },
    _a[constants_1.PRODUCT_TOURS_ENABLED_SERVER_SIDE] = { exposure: 'hidden' },
    _a[constants_1.WEB_VITALS_ALLOWED_METRICS] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_REMOTE_CONFIG] = { exposure: 'hidden' },
    _a[constants_1.SESSION_RECORDING_ENABLED_SERVER_SIDE] = { exposure: 'hidden' },
    _a[constants_1.SESSION_ID] = { exposure: 'hidden' },
    _a[constants_1.SESSION_RECORDING_IS_SAMPLED] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_SAMPLE_RATE] = {
        exposure: 'event',
        shouldSkipFromEventProperties: function (value) { return (0, core_1.isNull)(value); },
    },
    _a[constants_1.SESSION_RECORDING_PAST_MINIMUM_DURATION] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_URL_TRIGGER_ACTIVATED_SESSION] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_EVENT_TRIGGER_ACTIVATED_SESSION] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_FIRST_FULL_SNAPSHOT_TIMESTAMP] = { exposure: 'event' },
    _a[constants_1.ENABLED_FEATURE_FLAGS] = {
        exposure: 'derived',
        storageGroup: 'flags',
        shouldSkipFromEventProperties: function (_, shouldSkip) { return shouldSkip(); },
        transformToEventProperties: persistence_key_transforms_1.transformEnabledFeatureFlagsToEventProperties,
    },
    _a[constants_1.PERSISTENCE_ACTIVE_FEATURE_FLAGS] = { exposure: 'event', storageGroup: 'flags' },
    _a[constants_1.PERSISTENCE_EARLY_ACCESS_FEATURES] = { exposure: 'hidden' },
    _a[constants_1.PERSISTENCE_FEATURE_FLAG_DETAILS] = { exposure: 'hidden', storageGroup: 'flags' },
    _a[constants_1.PERSISTENCE_FEATURE_FLAG_PAYLOADS] = { exposure: 'event', storageGroup: 'flags' },
    _a[constants_1.PERSISTENCE_FEATURE_FLAG_REQUEST_ID] = { exposure: 'event', storageGroup: 'flags', volatile: true },
    _a[constants_1.PERSISTENCE_OVERRIDE_FEATURE_FLAGS] = { exposure: 'event' },
    _a[constants_1.PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS] = { exposure: 'hidden' },
    _a[constants_1.STORED_PERSON_PROPERTIES_KEY] = { exposure: 'hidden' },
    _a[constants_1.STORED_GROUP_PROPERTIES_KEY] = { exposure: 'hidden' },
    _a[constants_1.SURVEYS] = { exposure: 'hidden', storageGroup: 'surveys' },
    _a[constants_1.SURVEYS_LOADED_AT] = { exposure: 'hidden', storageGroup: 'surveys', volatile: true },
    _a[constants_1.SURVEYS_ACTIVATED] = { exposure: 'event' },
    _a[constants_1.PRODUCT_TOURS] = { exposure: 'hidden' },
    _a[constants_1.PRODUCT_TOURS_ACTIVATED] = { exposure: 'hidden' },
    _a[constants_1.CONVERSATIONS_LEGACY_WIDGET_SESSION_ID] = { exposure: 'event' },
    _a[constants_1.CONVERSATIONS_LEGACY_TICKET_ID] = { exposure: 'event' },
    _a[constants_1.CONVERSATIONS_LEGACY_WIDGET_STATE] = { exposure: 'event' },
    _a[constants_1.CONVERSATIONS_LEGACY_USER_TRAITS] = { exposure: 'event' },
    _a[constants_1.FLAG_CALL_REPORTED] = { exposure: 'hidden' },
    _a[constants_1.FLAG_CALL_REPORTED_SESSION_ID] = { exposure: 'hidden' },
    _a[constants_1.PERSISTENCE_FEATURE_FLAG_ERRORS] = { exposure: 'hidden' },
    _a[constants_1.PERSISTENCE_FEATURE_FLAG_EVALUATED_AT] = { exposure: 'hidden', storageGroup: 'flags', volatile: true },
    _a[constants_1.USER_STATE] = { exposure: 'hidden' },
    _a[constants_1.CLIENT_SESSION_PROPS] = { exposure: 'hidden' },
    _a[constants_1.CAPTURE_RATE_LIMIT] = { exposure: 'hidden' },
    _a[constants_1.INITIAL_CAMPAIGN_PARAMS] = { exposure: 'hidden' },
    _a[constants_1.INITIAL_REFERRER_INFO] = { exposure: 'hidden' },
    _a[constants_1.INITIAL_PERSON_INFO] = { exposure: 'hidden' },
    _a[constants_1.ENABLE_PERSON_PROCESSING] = { exposure: 'hidden' },
    _a[constants_1.SESSION_RECORDING_OVERRIDE_SAMPLING] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_OVERRIDE_LINKED_FLAG] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_OVERRIDE_URL_TRIGGER] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_OVERRIDE_EVENT_TRIGGER] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_EXTENSIONS_INIT_METHOD] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_EXTENSIONS_INIT_TIME_MS] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_RECORDING_SCRIPT_NOT_LOADED] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_EVENT_TRIGGER_STATUS] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_LINKED_FLAG_TRIGGER_STATUS] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_MATCHED_RECORDING_TRIGGER_GROUPS] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_REMOTE_TRIGGER_MATCHING_CONFIG] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_TRIGGER_GROUPS_COUNT] = { exposure: 'event' },
    _a[constants_1.SDK_DEBUG_REPLAY_URL_TRIGGER_STATUS] = { exposure: 'event' },
    _a[constants_1.SESSION_RECORDING_START_REASON] = { exposure: 'event' },
    _a);
var PERSISTENCE_KEY_PREFIX_POLICY = [
    [constants_1.SESSION_RECORDING_TRIGGER_V2_GROUP_EVENT_PREFIX, { exposure: 'hidden' }],
    [constants_1.SESSION_RECORDING_TRIGGER_V2_GROUP_URL_PREFIX, { exposure: 'hidden' }],
    [constants_1.SESSION_RECORDING_TRIGGER_V2_GROUP_SAMPLING_PREFIX, { exposure: 'hidden' }],
];
var getPersistenceKeyPolicy = function (key) {
    var e_1, _a;
    var exactMatch = exports.PERSISTENCE_KEY_POLICY[key];
    if (exactMatch) {
        return exactMatch;
    }
    try {
        for (var PERSISTENCE_KEY_PREFIX_POLICY_1 = __values(PERSISTENCE_KEY_PREFIX_POLICY), PERSISTENCE_KEY_PREFIX_POLICY_1_1 = PERSISTENCE_KEY_PREFIX_POLICY_1.next(); !PERSISTENCE_KEY_PREFIX_POLICY_1_1.done; PERSISTENCE_KEY_PREFIX_POLICY_1_1 = PERSISTENCE_KEY_PREFIX_POLICY_1.next()) {
            var _b = __read(PERSISTENCE_KEY_PREFIX_POLICY_1_1.value, 2), prefix = _b[0], policy = _b[1];
            if (key.indexOf(prefix) === 0) {
                return policy;
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (PERSISTENCE_KEY_PREFIX_POLICY_1_1 && !PERSISTENCE_KEY_PREFIX_POLICY_1_1.done && (_a = PERSISTENCE_KEY_PREFIX_POLICY_1.return)) _a.call(PERSISTENCE_KEY_PREFIX_POLICY_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return undefined;
};
exports.getPersistenceKeyPolicy = getPersistenceKeyPolicy;
//# sourceMappingURL=persistence-key-policy.js.map