← back to Gmc 425 Supplemental Feed
inspect-overrides.mjs
21 lines
import fs from 'node:fs'; import crypto from 'node:crypto';
const HOME=process.env.HOME, ACCT='146735262';
const SA_PATH=HOME+'/Projects/secrets-manager/gmc-sa-146735262.json';
const b64=b=>Buffer.from(b).toString('base64').replace(/=/g,'').replace(/\+/g,'-').replace(/\//g,'_');
const SA=JSON.parse(fs.readFileSync(SA_PATH,'utf8'));const now=Math.floor(Date.now()/1000);
const si=b64(JSON.stringify({alg:'RS256',typ:'JWT'}))+'.'+b64(JSON.stringify({iss:SA.client_email,scope:'https://www.googleapis.com/auth/content',aud:'https://oauth2.googleapis.com/token',iat:now,exp:now+3600}));
const s=crypto.createSign('RSA-SHA256');s.update(si);const jwt=si+'.'+b64(s.sign(SA.private_key));
const tr=await fetch('https://oauth2.googleapis.com/token',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams({grant_type:'urn:ietf:params:oauth:grant-type:jwt-bearer',assertion:jwt})});
const tok=(await tr.json()).access_token; const H={Authorization:`Bearer ${tok}`};
const list=await (await fetch(`https://merchantapi.googleapis.com/datasources/v1/accounts/${ACCT}/dataSources`,{headers:H})).json();
const rp=(list.dataSources||[]).filter(d=>/Real-Price/i.test(d.displayName||''));
console.log(`${rp.length} "DW Real-Price Overrides" supplemental sources. Detail of first 2:`);
for(const d of rp.slice(0,2)){
console.log('\n', JSON.stringify(d,null,1).slice(0,900));
const id=d.name.split('/').pop();
// fileUploads status
const fu=await fetch(`https://merchantapi.googleapis.com/datasources/v1/accounts/${ACCT}/dataSources/${id}/fileUploads/latest`,{headers:H});
const fj=await fu.json();
console.log(' latest fileUpload:',fu.status, JSON.stringify(fj).slice(0,300));
}