import { createRailDeckPublicClient } from '@raildeck/frontend-sdk/public'; /** * Redeem a guest code and read only its authorised layout with an in-memory token. * @param baseUrl - Explicit caller-owned value for this operation. * @param guestSessionId - Explicit caller-owned value for this operation. * @param code - Explicit caller-owned value for this operation. * @param signal - Caller-owned cancellation signal. * @returns The scoped decoded snapshot; no token is returned, logged or persisted. */ export async function readGuestLayoutOnce( baseUrl: string, guestSessionId: string, code: string, signal: AbortSignal, ) { let guestToken: string | null = null; const client = createRailDeckPublicClient({ baseUrl, getGuestAccessToken: () => guestToken, }); try { const redemption = await client.sharing.redeemGuestSession(guestSessionId, { code }); guestToken = redemption.guestAccessToken.accessToken; const { accountId, layoutId } = redemption.guestAccess; return await client.currentState.getLayoutSnapshot(accountId, layoutId, { signal, timeoutMs: 15_000, }); } finally { // Clear the capability after this one read, including cancellation or decode failure. guestToken = null; } }