| 1 |
/** |
| 2 |
* Normalize REST JSON that may be either a plain payload (e.g. settings) |
| 3 |
* or wrapped as { success: true, data: T } (e.g. Email Automation). |
| 4 |
*/ |
| 5 |
export function unwrapApiPayload<T>(raw: unknown): T { |
| 6 |
if (raw !== null && typeof raw === "object") { |
| 7 |
const r = raw as Record<string, unknown>; |
| 8 |
if (r.success === true && "data" in r) { |
| 9 |
return r.data as T; |
| 10 |
} |
| 11 |
} |
| 12 |
return raw as T; |
| 13 |
} |
| 14 |
|