import type { KibanaExecutionContext } from '../../types' ; const BAGGAGE_HEADER = 'x-kbn-context' ; export const BAGGAGE_MAX_PER_NAME_VALUE_PAIRS = 4096 ; const MAX_BAGGAGE_LENGTH = BAGGAGE_MAX_PER_NAME_VALUE_PAIRS / 4 ; function enforceMaxLength ( header ) { return header . slice ( 0 , MAX_BAGGAGE_LENGTH ) ; } public export interface IExecutionContextContainer { toHeader : ( ) => Record < string , string > ; toJSON : ( ) => Readonly < KibanaExecutionContext > ; } export class ExecutionContextContainer implements IExecutionContextContainer { readonly #context : Readonly < KibanaExecutionContext > ; constructor ( context ) { this . #context = context ; } private toString ( ) { const value = JSON . stringify ( this . #context ) ; return enforceMaxLength ( encodeURIComponent ( value ) ) ; } toHeader ( ) { return { [ BAGGAGE_HEADER ] : this . toString ( ) } ; } toJSON ( ) { return this . #context ; } }