(c: Credentials)
| 412 | } |
| 413 | |
| 414 | function serializeCredentials(c: Credentials): Record<string, unknown> { |
| 415 | // Re-emit unrecognized top-level keys first so the known fields below |
| 416 | // are authoritative (collectUnknown already excludes known keys, so |
| 417 | // there's no real collision — this is belt-and-suspenders). |
| 418 | const out: Record<string, unknown> = { ...(c[UNKNOWN] ?? {}) }; |
| 419 | if (c.api_key) out["api_key"] = c.api_key; |
| 420 | if (c.oauth) out["oauth"] = serializeOAuth(c.oauth); |
| 421 | if (c.user) { |
| 422 | const user = serializeUser(c.user); |
| 423 | // Omit an all-empty user block entirely (no empty `"user": {}` litter). |
| 424 | if (Object.keys(user).length > 0) out["user"] = user; |
| 425 | } |
| 426 | return out; |
| 427 | } |
| 428 | |
| 429 | function serializeOAuth(o: OAuthTokens): Record<string, unknown> { |
| 430 | const oauth: Record<string, unknown> = { ...(o[UNKNOWN] ?? {}) }; |
no test coverage detected