(args: Record<string, unknown> | null | undefined)
| 2 | import { createClient } from "@supabase/supabase-js"; |
| 3 | |
| 4 | function extractSessionToken(args: Record<string, unknown> | null | undefined): string { |
| 5 | if (!args || typeof args !== "object") return ""; |
| 6 | const direct = args.session_id ?? args.sessionId ?? args.session ?? args.cgc_session_id; |
| 7 | if (direct != null && String(direct).trim()) return String(direct).trim().toLowerCase(); |
| 8 | const sessionLabel = /\bsession[:\s]+([a-z0-9]{6})\b/i; |
| 9 | for (const value of Object.values(args)) { |
| 10 | if (typeof value !== "string" || !value.trim()) continue; |
| 11 | const labeled = value.match(sessionLabel); |
| 12 | if (labeled?.[1]) return labeled[1].toLowerCase(); |
| 13 | } |
| 14 | for (const value of Object.values(args)) { |
| 15 | if (typeof value !== "string") continue; |
| 16 | const trimmed = value.trim().toLowerCase(); |
| 17 | if (/^[a-z0-9]{6}$/.test(trimmed)) return trimmed; |
| 18 | } |
| 19 | return ""; |
| 20 | } |
| 21 | |
| 22 | const MISSING_SESSION_PAYLOAD = { |
| 23 | status: "missing_session", |
no test coverage detected