{"version":3,"sources":["../../src/utils/response-body.ts"],"sourcesContent":["/**\n * Tolerant JSON body readers for `fetch` responses.\n *\n * A response body can legitimately be empty (204), non-JSON (an HTML error\n * page from a proxy), or JSON that is not an object (`null`, an array, a\n * string). Every SDK code path that indexes into a parsed body must go\n * through these helpers so those shapes degrade to \"no fields\" instead of a\n * `TypeError` that bypasses the typed error the caller expects.\n *\n * @internal\n */\n\n/** The one method the readers need, so custom fetch shims qualify too. */\nexport type JsonBodySource = Pick<Response, \"json\">;\n\n/** True for a non-null, non-array object -- the only shape safe to index. */\nexport function isPlainObject(\n  value: unknown,\n): value is Record<string, unknown> {\n  return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Parse the body as JSON. Resolves `null` when the body is empty or not\n * valid JSON. Never throws.\n */\nexport async function readJsonValue(res: JsonBodySource): Promise<unknown> {\n  try {\n    return (await res.json()) as unknown;\n  } catch {\n    return null;\n  }\n}\n\n/**\n * Parse the body as JSON and return it only when it is a plain object;\n * every other shape (empty, non-JSON, `null`, array, primitive) becomes `{}`.\n * Never throws.\n */\nexport async function readJsonObject(\n  res: JsonBodySource,\n): Promise<Record<string, unknown>> {\n  const value = await readJsonValue(res);\n  return isPlainObject(value) ? value : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,SAAS,cACd,OACkC;AAClC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAMA,eAAsB,cAAc,KAAuC;AACzE,MAAI;AACF,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAOA,eAAsB,eACpB,KACkC;AAClC,QAAM,QAAQ,MAAM,cAAc,GAAG;AACrC,SAAO,cAAc,KAAK,IAAI,QAAQ,CAAC;AACzC;","names":[]}