PageSourceSearch

https://www.consensuspulse.com/js/integrations/mtur.js

js consensuspulse.com collected 2026-10-02 00:48:35 UTC 3,752 bytes, 80 lines download raw bytes

1// ===== INTEGRAÇÃO: MTur — Chegadas de Turistas Internacionais (dado oficial) =====
2// Fonte real por trás do módulo Mercados Emissores. Chama a Edge Function
3// `mtur-arrivals` (dados.turismo.gov.br). Granularidade país × UF de entrada × mês.
4// NÃO é dado municipal — a UI rotula "chegadas pela UF de X, base ANO".
5// Sem dado → retorna { available:false } (a tela mostra "sem dado", nunca inventa).
6
7// Extrai a UF (sigla de 2 letras) do destino "Cidade, UF, País".
8function _ufFromDest(dest) {
9  if (!dest) return '';
10  var parts = String(dest).split(',').map(function (s) { return s.trim(); });
11  for (var i = 0; i < parts.length; i++) {
12    if (/^[A-Z]{2}$/.test(parts[i])) return parts[i];   // "SC", "BA"...
13  }
14  return '';
15}
16
17// Chama a Edge Function mtur-arrivals. `markets` = códigos ISO (['AR','PT','UY']).
18async function fetchMturArrivals(dest, markets) {
19  try {
20    var uf = _ufFromDest(dest);
21    if (!uf) return { available: false, reason: 'no_uf_in_dest' };
22    var supabase = await getSupabase();
23    var sess = await supabase.auth.getSession();
24    var token = sess && sess.data && sess.data.session ? sess.data.session.access_token : null;
25    if (!token) return { available: false, reason: 'no_session' };
26
27    var res = await fetch(SUPABASE_URL + '/functions/v1/mtur-arrivals', {
28      method: 'POST',
29      headers: {
30        'Content-Type': 'application/json',
31        'Authorization': 'Bearer ' + token,
32        'apikey': SUPABASE_ANON_KEY
33      },
34      body: JSON.stringify({ uf: uf, markets: markets || [] })
35    });
36    if (!res.ok) return { available: false, reason: 'http_' + res.status };
37    return await res.json();
38  } catch (e) {
39    console.warn('[MTur] Falhou:', e && e.message);
40    return { available: false, reason: 'exception' };
41  }
42}
43
44// Monta o bloco de contexto REAL para o prompt a partir do payload do MTur.
45// Só descreve o que existe; campos sem dado ficam de fora (o prompt é instruído
46// a devolver null para eles). Retorna '' se não houver dado.
47function buildMturContext(mtur) {
48  if (!mtur || !mtur.available || !Array.isArray(mtur.per_market)) return '';
49  var lines = [];
50  lines.push('DADOS OFICIAIS DE CHEGADAS INTERNACIONAIS (' + mtur.source + '):');
51  lines.push(mtur.granularity_note);
52  lines.push('Total de chegadas internacionais pela UF em ' + mtur.year + ': ' + mtur.total_arrivals.toLocaleString('pt-BR') + '.');
53  lines.push('Por mercado selecionado (REAL — use estes números, não estime):');
54  mtur.per_market.forEach(function (m) {
55    if (!m.has_data) {
56      lines.push('- ' + m.pais + ': sem chegadas registradas por esta UF em ' + mtur.year + ' (participação indisponível).');
57      return;
58    }
59    var parts = ['- ' + m.pais + ': ' + m.chegadas.toLocaleString('pt-BR') + ' chegadas'];
60    if (m.share_pct != null) parts.push(m.share_pct + '% do total da UF');
61    if (m.yoy_pct != null) parts.push('variação ' + (m.yoy_pct >= 0 ? '+' : '') + m.yoy_pct + '% vs ' + mtur.prev_year);
62    if (m.mes_pico) parts.push('pico em ' + m.mes_pico);
63    if (m.mes_baixa) parts.push('baixa em ' + m.mes_baixa);
64    lines.push(parts.join('; ') + '.');
65  });
66  if (mtur.ranking_top && mtur.ranking_top.length) {
67    lines.push('Ranking real dos maiores mercados desta UF: ' +
68      mtur.ranking_top.slice(0, 5).map(function (r) { return r.pais + ' (' + r.share_pct + '%)'; }).join(', ') + '.');
69  }
70  if (mtur.espanhol_share_pct != null) {
71    lines.push('Chegadas de países hispanofalantes: ' + mtur.espanhol_share_pct + '% do total da UF (real).');
72  }
73  return lines.join('\n');
74}
75
76if (typeof window !== 'undefined') {
77  window.fetchMturArrivals = fetchMturArrivals;
78  window.buildMturContext = buildMturContext;
79  window._ufFromDest = _ufFromDest;
80}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.