const jwt = require('jsonwebtoken'); const http = require('http'); const fs = require('fs'); const KEY = 'user:1022172:47'; const SECRET = 'da4e4367277668aa6e048b0a04d1a417ba8bad630f4ac37ccdcea064a9de151e'; function makeJWT() { return jwt.sign({ iss: KEY, jti: Math.random().toString(36).slice(2), iat: Math.floor(Date.now()/1000), exp: Math.floor(Date.now()/1000) + 300 }, SECRET); } function proxyRequest(method, url, headers) { return new Promise((resolve, reject) => { const u = new URL(url); const req = http.request({ hostname: 'localhost', port: 12334, path: url, method: method, headers: Object.assign({ 'Host': u.hostname }, headers) }, res => { let d = ''; res.on('data', c => d += c); res.on('end', () => resolve({ status: res.statusCode, body: d, headers: res.headers })); }); req.on('error', reject); req.end(); }); } async function main() { const token = makeJWT(); const auth = 'JWT ' + token; const addon = 'verstak-bridge@verstak.app'; // List versions console.log('==> Listing versions...'); const vRes = await proxyRequest('GET', `https://addons.mozilla.org/api/v5/addons/${addon}/versions/`, { 'Authorization': auth }); console.log(` Status: ${vRes.status}`); if (vRes.status === 200) { const data = JSON.parse(vRes.body); if (data.results) { for (const v of data.results) { const f = v.files?.[0]; console.log(` v${v.version} id=${v.id} status=${f?.status || 'no file'} download=${f?.download_url || 'none'}`); } } } else { console.log(vRes.body.substring(0, 300)); // Maybe the addon doesn't exist yet, let's check the upload status from web-ext // web-ext said: "Version 1.0.0 already exists" and "This upload has already been submitted" // So the addon DOES exist. Let's try listing addons for this user console.log('\n==> Trying to list addons by slug...'); const sRes = await proxyRequest('GET', `https://addons.mozilla.org/api/v5/addons/addon/verstak-bridge/`, { 'Authorization': auth }); console.log(` Status: ${sRes.status}`); if (sRes.status === 200) { const sData = JSON.parse(sRes.body); console.log(` Slug: ${sData.slug} ID: ${sData.id} Name: ${sData.name}`); } else { console.log(sRes.body.substring(0, 200)); } } } main().catch(e => console.error(e.message));