/** * Helper function for copying specific field values * from a given source. This is called to collect browser * information if available. * * Example usage: * const copied = copyFields({ a: 1, b: 2, c: 3 }, ['a', 'b']) * console.log(copied) * // expected output: { a: 1, b: 2 } */ declare function copyFields(source: object | null | undefined, fields: string[]): Record; declare function keystamp(prefix?: string): string; declare function fullyQualifiedWebsocketURL(defaultRelativeUrl?: string, defaultBaseServer?: string): string; declare function setVerboseEvents(value: boolean): void; /** * Example usage: * event = { event: 'ADD', data: 'stuff' } * timestampEvent(event) * event * // { event: 'ADD', data: 'stuff', metadata: { ts, human_ts, iso_ts, sessionIndex, sessionTag } } */ declare function timestampEvent(event: Record): void; /** * We provide an id for each system that is stored * locally with the client. This allows us to more easily * parse events when debugging in specific contexts. * * Example usage: * const debugMetadata = await fetchDebuggingIdentifier(); * console.log(debugMetadata); * // Expected output: { logger_id: } */ declare function fetchDebuggingIdentifier(): Promise>; /** * Deeply merge `source` into `target`. * `target` should be passed by reference * * This is a helper function for `mergeMetadata`. * * Example usage: * const obj1 = { a: 1, b: { c: 3 } }; * const obj2 = { b: { d: 4 }, e: 5 }; * util.mergeDictionary(obj1, obj2); * obj1 * // { a: 1, b: { c: 3, d: 4 }, e: 5 } */ declare function mergeDictionary(target: Record, source: Record): void; /** * Merges the output of dictionaries, sync functions, and async * functions into a single master dictionary. * * Functions and async functions should return dictionaries. * * @param {Array} inputList - List of dictionaries, sync functions, and async functions * @returns {Promise} - A Promise that resolves to the compiled master dictionary * * Example usage: * const metadata = await mergeMetadata([ browserInfo(), { source: '0.0.1' }, extraMetadata() ]) * console.log(metadata); * // { browserInfo: {}, source: '0.0.1', metadata: { extra: 'extra data' }} */ type MetadataInput = Record | (() => Record | Promise>); declare function mergeMetadata(inputList: MetadataInput[]): Promise>; declare function delay(ms: number): Promise; /** * Append a failure record to a bounded, ring-buffered localStorage log * (NDJSON, newest last). Deliberately NOT wired to every debug.error — only * call it for notable failures worth persisting, so the log can't grow * exponentially. No-op (console remains the record) outside a browser or if * storage is unavailable/full. */ declare function recordFailure(entry: Record): void; declare const TERMINATION_POLICY: { readonly DIE: "DIE"; readonly RETRY: "RETRY"; }; /** * This function repeatedly tries to run another function * until it returns a truthy value while waiting a set amount * of time inbetween each attempt. * * The system will either terminate when we have await each * delay amount in the `delays` list (TERMINATION_POLICY.DIE) * OR we continue retrying using the last item in our `delays` * list until we reach the `maxRetries` (TERMINATION_POLICY.RETRY). * * Example usage: * util.backoff(checkCondition, 'Condition not met after retries.') * .then(() => console.log('Condition met.')) * .catch(error => console.error(error.message)); * * @param {*} predicate function that returns truthy value * @param {*} errorMessage message to be thrown when we run out of delays * @param {*} delays list of MS values to be await in order * @default delays defaults to [100ms, 1sec, 1min, 5min, 30min] * @param {*} terminationPolicy when to be done retrying * @default terminationPolicy defaults to TERMINATION_POLICY.DIE * @param {*} maxRetries number of maximum retries when terminationPolicy is set to RETRY * @default maxRetries defaults to Infinity * @returns returns when predicate is true or throws errorMessage */ declare function backoff(predicate: () => unknown | Promise, errorMessage?: string, delays?: number[], terminationPolicy?: typeof TERMINATION_POLICY[keyof typeof TERMINATION_POLICY], maxRetries?: number): Promise; declare function once any>(func: T): T; declare function treeget(tree: Record, key: string): unknown; /** * Takes a number of seconds and converts it into a human-friendly time string in the format HH:MM:SS. * * @param {number} seconds - The number of seconds to format into a time string * @returns {string} The formatted time string * * Will do things like omit hours (and perhaps be smarter in the future) */ declare function formatTime(seconds: number): string; /** * This function dispatches an event in the appropriate context for * our environment. * * When working in an extension, we want to send a message via the * `chrome.runtime` object. * * When working in a browser, we want to dispatch the event via the * `window` object. */ declare function dispatchCustomEvent(eventName: string, detail: CustomEventInit): void; /** * This function consumes a custom event in the appropriate context for * our environment. * * When working in an extension, it listens for messages via the * `chrome.runtime.onMessage` object. * * When working in a browser, it listens for events on the * `window` object. */ declare function consumeCustomEvent(eventName: string, callback: (detail: unknown, sender?: unknown) => void): () => void; /** * Convert seconds to a time string. * * Compact representation. * 10 ==> 10s * 125 ==> 2m * 3600 ==> 1h * 7601 ==> 2h * 764450 ==> 8d */ declare function renderTime(t: number): string; export { TERMINATION_POLICY, backoff, consumeCustomEvent, copyFields, delay, dispatchCustomEvent, fetchDebuggingIdentifier, formatTime, fullyQualifiedWebsocketURL, keystamp, mergeDictionary, mergeMetadata, once, recordFailure, renderTime, setVerboseEvents, timestampEvent, treeget };