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','Accept':'*/*'}},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}`; } function docsToObjects(docs) { return docs.map(doc => { const o = {}; (doc.fields||[]).forEach(f => o[f.key]=f.value); return o; }); } (async()=>{ // Carrefour const cr = await httpGet(buildVtexGraphqlUrl('www.carrefour.com.ar','GetPromotions','cdedb2142b133164ce61b85e94287592451ebee4a2fbede815e09336d40d29ae','valtech.carrefourar-bank-promotions@0.x','carrefourar')); const cdocs = docsToObjects(JSON.parse(cr.data)?.data?.documents||[]); console.log('=== CARREFOUR all field keys ==='); const ckeys = [...new Set(cdocs.flatMap(d=>Object.keys(d)))]; console.log(ckeys.join(', ')); console.log('\nSample validTexts:'); cdocs.slice(0,10).forEach(d=>console.log(' -', d.discount_percentage+'%', '|', d.validText, '|', d.title?.slice(0,60))); // Changomas const mr = await httpGet(buildVtexGraphqlUrl('www.masonline.com.ar','GetPromos','1a071ebc5dc407a3f65e687b0f4c0a3b8d12a0c45d8d11370075c3b2a505251c','valtech.gdn-banks-promotions@0.x','masonlineprod')); const mdocs = docsToObjects(JSON.parse(mr.data)?.data?.documents||[]); console.log('\n=== CHANGOMAS all field keys ==='); const mkeys = [...new Set(mdocs.flatMap(d=>Object.keys(d)))]; console.log(mkeys.join(', ')); console.log('\nSample validTexts:'); mdocs.slice(0,10).forEach(d=>console.log(' -', d.discount_percentage+'%', '|', d.validText, '|', d.title?.slice(0,60))); // Check if there are legals fields const cWithLegals = cdocs.filter(d=>d.legal || d.legals || d.legal_text || d.text_legal); console.log('\nCarrefour docs with legal field:', cWithLegals.length); if (cWithLegals.length) console.log(' keys:', Object.keys(cWithLegals[0]).join(', ')); // Full sample console.log('\n=== CARREFOUR doc 1 full ==='); console.log(JSON.stringify(cdocs[0],null,2).slice(0,1000)); console.log('\n=== CHANGOMAS doc 1 full ==='); console.log(JSON.stringify(mdocs[0],null,2).slice(0,1000)); })().catch(e=>console.error(e));