<mxfile host="app.diagrams.net" agent="tempest-react-sdk" version="24.0.0">
  <diagram name="request-flow" id="request-flow">
    <mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="826" math="0" shadow="0">
      <root>
        <mxCell id="0" />
        <mxCell id="1" parent="0" />
        <mxCell id="title" value="createApiClient — fluxo de request" style="text;html=1;align=center;fontSize=18;fontStyle=1;" vertex="1" parent="1">
          <mxGeometry x="380" y="20" width="400" height="30" as="geometry" />
        </mxCell>
        <mxCell id="caller" value="Service / hook chama api.get(&quot;/users/me&quot;)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
          <mxGeometry x="60" y="80" width="240" height="60" as="geometry" />
        </mxCell>
        <mxCell id="buildUrl" value="buildUrl(baseURL, path, params)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
          <mxGeometry x="380" y="80" width="240" height="60" as="geometry" />
        </mxCell>
        <mxCell id="headers" value="Headers&#10;• Content-Type: application/json (se não for FormData)&#10;• Authorization: Bearer {getToken()}" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;align=left;" vertex="1" parent="1">
          <mxGeometry x="700" y="80" width="300" height="60" as="geometry" />
        </mxCell>
        <mxCell id="fetch" value="fetch(url, init)" style="rhombus;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1">
          <mxGeometry x="450" y="200" width="180" height="80" as="geometry" />
        </mxCell>
        <mxCell id="ok" value="response.ok === true" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
          <mxGeometry x="120" y="340" width="200" height="60" as="geometry" />
        </mxCell>
        <mxCell id="status401" value="status === 401?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
          <mxGeometry x="450" y="330" width="180" height="80" as="geometry" />
        </mxCell>
        <mxCell id="errthrow" value="throw ApiError" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1">
          <mxGeometry x="780" y="340" width="200" height="60" as="geometry" />
        </mxCell>
        <mxCell id="refresh" value="refresh() configurado?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="1">
          <mxGeometry x="450" y="450" width="180" height="80" as="geometry" />
        </mxCell>
        <mxCell id="retry" value="await refresh() + retry 1x" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
          <mxGeometry x="120" y="460" width="200" height="60" as="geometry" />
        </mxCell>
        <mxCell id="unauth" value="onUnauthorized(response)&#10;throw ApiError" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1">
          <mxGeometry x="780" y="460" width="200" height="60" as="geometry" />
        </mxCell>
        <mxCell id="parseJson" value="Content-Type JSON?&#10;→ response.json()&#10;Caso contrário → text()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;align=left;" vertex="1" parent="1">
          <mxGeometry x="60" y="580" width="300" height="60" as="geometry" />
        </mxCell>
        <mxCell id="optionalParse" value="(opcional) parseResponse(schema, raw, context)&#10;valida com zod, lança em dev com path do campo" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;align=left;" vertex="1" parent="1">
          <mxGeometry x="420" y="580" width="380" height="60" as="geometry" />
        </mxCell>
        <mxCell id="result" value="Retorna T tipado pro caller" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
          <mxGeometry x="860" y="580" width="240" height="60" as="geometry" />
        </mxCell>
        <mxCell id="e1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="caller" target="buildUrl">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e2" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="buildUrl" target="headers">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e3" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="1" source="headers" target="fetch">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e4" value="ok" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.5;" edge="1" parent="1" source="fetch" target="ok">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e5" value="!ok" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="1" source="fetch" target="status401">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e6" value="não" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="status401" target="errthrow">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e7" value="sim" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="1" source="status401" target="refresh">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e8" value="sim" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.5;" edge="1" parent="1" source="refresh" target="retry">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e9" value="não" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="refresh" target="unauth">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;" edge="1" parent="1" source="ok" target="parseJson">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="parseJson" target="optionalParse">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="e12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;entryX=0;entryY=0.5;" edge="1" parent="1" source="optionalParse" target="result">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>
