{"version":3,"file":"parse-response.cjs","names":[],"sources":["../../src/http/parse-response.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nimport { isDevBuild } from \"../utils/dev-mode\";\n\n/**\n * Validate an unknown response payload against a zod schema.\n *\n * A development build throws a detailed error naming every divergent field path\n * and embedding the raw payload; every other build throws a generic sentence, so\n * server internals never reach a user's screen or an error tracker.\n *\n * Which one you get comes from `isDevBuild()`, the SDK's single answer to that\n * question, rather than from a check written here. This function used to ask\n * `typeof process !== \"undefined\" && process.env?.NODE_ENV === \"development\"`,\n * and a browser has no `process` identifier at all — so the guard short-circuited\n * and the detailed branch was dead in exactly the build it was written for, no\n * matter what the bundler substituted behind it.\n *\n * The rule `isDevBuild()` applies is `NODE_ENV !== \"production\"`, which is wider\n * than the old `\"development\" || \"test\"`: a staging build that never sets\n * `NODE_ENV=production` gets the drift report, raw payload included.\n *\n * @param schema - The zod schema to parse against.\n * @param raw - The raw response payload.\n * @param context - A label used in error messages, e.g. \"POST /auth/login\".\n * @returns The parsed, typed payload.\n * @throws Error When the payload does not match the schema: `[parseResponse]\n * Contract drift on <context>` with the field paths and the raw payload in a\n * development build, `Resposta inválida do servidor (<context>).` otherwise.\n */\nexport function parseResponse<TSchema extends z.ZodTypeAny>(\n    schema: TSchema,\n    raw: unknown,\n    context: string,\n): z.infer<TSchema> {\n    const result = schema.safeParse(raw);\n    if (result.success) {\n        return result.data;\n    }\n\n    if (isDevBuild()) {\n        const issues = result.error.issues\n            .map((i) => `  - ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n            .join(\"\\n\");\n        throw new Error(\n            `[parseResponse] Contract drift on ${context}:\\n${issues}\\n\\nRaw payload: ${JSON.stringify(raw, null, 2)}`,\n        );\n    }\n    throw new Error(`Resposta inválida do servidor (${context}).`);\n}\n"],"mappings":"yCA8BA,SAAgB,EACZ,EACA,EACA,EACgB,CAChB,IAAM,EAAS,EAAO,UAAU,CAAG,EACnC,GAAI,EAAO,QACP,OAAO,EAAO,KAGlB,GAAI,EAAA,WAAW,EAAG,CACd,IAAM,EAAS,EAAO,MAAM,OACvB,IAAK,GAAM,OAAO,EAAE,KAAK,KAAK,GAAG,GAAK,SAAS,IAAI,EAAE,SAAS,CAAC,CAC/D,KAAK;CAAI,EACd,MAAU,MACN,qCAAqC,EAAQ,KAAK,EAAO,mBAAmB,KAAK,UAAU,EAAK,KAAM,CAAC,GAC3G,CACJ,CACA,MAAU,MAAM,kCAAkC,EAAQ,GAAG,CACjE"}