const pako = require('pako');


const value = "[encoded data, 4956 characters]"
const URL = 'https://d3ii0wo49og5mi.cloudfront.net/economics/szlttr?span=max&v=20250619074600&key=20240229:nazare'

const key = 'tradingeconomics-charts-core-api-key'

const testFunc = function(e, k) {
  console.log('testFunc called with:', e, k);
    const a = atob(e)
        , n = new Uint8Array(a.length);
    console.log('Decoded base64 string:', a);
    for (let e = 0; e < a.length; e++)
        {n[e] = a.charCodeAt(e);}
    const i = (new TextEncoder).encode(k);
    console.log('Encoded key:', i);
    for (let e = 0; e < n.length; e++)
        {n[e] ^= i[e % i.length];}
    console.log('XORed data:', n);
    return pako.inflate(n, {to :'string'});
}

fetch(URL, {
  proxy: 'http://5.79.66.2:13010',
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome'
  }
}).then(async response => {
  const resp = await response.text();
  const result = testFunc(resp.replaceAll('"', ""), key);
  // console.log(result.toString());
  console.log(JSON.stringify(JSON.parse(result.toString())));
})

