/**
 * `/api/user` should return `permissions` as JSON array; normalize anything else
 * (empty object from quirky encoding, keyed object, etc.) for router + settings redirect.
 *
 * @param {unknown} raw
 * @returns {string[]}
 */
export function normalizePermissionList(raw) {
  if (raw == null) {
    return [];
  }

  if (Array.isArray(raw)) {
    return raw.filter((item) => typeof item === "string");
  }

  if (typeof raw === "object") {
    return Object.values(raw).filter((item) => typeof item === "string");
  }

  return [];
}
