:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { parseJSON } from '~/common/utils/json-parse'
import { SerializedSessionKey, SessionKey } from '~/ingestion/pipelines/sessionreplay/shared/types'
export function serializeSessionKey(key: SessionKey): string {
const serialized: SerializedSessionKey = {
plaintextKey: key.plaintextKey.toString('base64'),
encryptedKey: key.encryptedKey.toString('base64'),
sessionState: key.sessionState,
deletedAt: key.deletedAt,
deletedBy: key.deletedBy,
}
return JSON.stringify(serialized)
}
export function deserializeSessionKey(json: string): SessionKey {
const parsed = parseJSON(json) as SerializedSessionKey
return {
plaintextKey: Buffer.from(parsed.plaintextKey, 'base64'),
encryptedKey: Buffer.from(parsed.encryptedKey, 'base64'),
sessionState: parsed.sessionState,
deletedAt: parsed.deletedAt,
deletedBy: parsed.deletedBy,
}
}