import { AsyncLocalStorage } from 'node:async_hooks'; type Ctx = { sessionId: string | null }; export const als = new AsyncLocalStorage(); export const runWithAlsSession = ( sid: string | null | undefined, fn: () => Promise, ) => als.run({ sessionId: sid || null }, fn); export const getAlsSessionId = () => als.getStore()?.sessionId ?? null;