const https = require('https'); function httpGet(url) { return new Promise((res,rej)=>{ const u=new URL(url); https.request({hostname:u.hostname,path:u.pathname+u.search,headers:{'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/120.0','Accept':'application/json,*/*'}},r=>{ let d=''; r.on('data',c=>d+=c); r.on('end',()=>res({status:r.statusCode,data:d})); }).on('error',rej).end(); }); } function nowIso() { return new Date().toISOString().replace(/\.\d+Z$/,''); } function buildVtexGraphqlUrl(host, operationName, hash, sender, account) { const now = nowIso(); const innerVars = { where: `active=true AND ((active_from < ${now}) AND (active_to > ${now}))`, account }; const ext = { persistedQuery: {version:1, sha256Hash:hash, sender, provider:'vtex.store-graphql@2.x'}, variables: Buffer.from(JSON.stringify(innerVars)).toString('base64') }; const params = new URLSearchParams({ workspace:'master', maxAge:'short', appsEtag:'remove', domain:'store', locale:'es-AR', operationName, variables:'{}', extensions: JSON.stringify(ext) }); return `https://${host}/_v/public/graphql/v1?${params}`; } (async()=>{ // Analyze Carrefour documents structure console.log('=== CARREFOUR full structure ==='); const curl = buildVtexGraphqlUrl( 'www.carrefour.com.ar', 'GetPromotions', 'cdedb2142b133164ce61b85e94287592451ebee4a2fbede815e09336d40d29ae', 'valtech.carrefourar-bank-promotions@0.x', 'carrefourar' ); const cr = await httpGet(curl); const cd = JSON.parse(cr.data); const cdocs = cd?.data?.documents || []; console.log('Total docs:', cdocs.length); // Extract all field keys from first 3 docs cdocs.slice(0,3).forEach((doc, i) => { const fields = {}; (doc.fields||[]).forEach(f => fields[f.key] = f.value); console.log(`\nDoc ${i+1}:`, JSON.stringify(fields).slice(0,600)); }); // Analyze Changomas structure console.log('\n\n=== CHANGOMAS full structure ==='); const murl = buildVtexGraphqlUrl( 'www.masonline.com.ar', 'GetPromos', '1a071ebc5dc407a3f65e687b0f4c0a3b8d12a0c45d8d11370075c3b2a505251c', 'valtech.gdn-banks-promotions@0.x', 'masonlineprod' ); const mr = await httpGet(murl); const md = JSON.parse(mr.data); const mdocs = md?.data?.documents || []; console.log('Total docs:', mdocs.length); mdocs.slice(0,3).forEach((doc, i) => { const fields = {}; (doc.fields||[]).forEach(f => fields[f.key] = f.value); console.log(`\nDoc ${i+1}:`, JSON.stringify(fields).slice(0,600)); }); })().catch(e=>console.error(e));