(url, token, body)
| 14 | } |
| 15 | |
| 16 | function postJson(url, token, body) { |
| 17 | return new Promise((resolve, reject) => { |
| 18 | const u = new URL(url); |
| 19 | const payload = JSON.stringify(body || {}); |
| 20 | const req = http.request({ |
| 21 | hostname: u.hostname, |
| 22 | port: u.port, |
| 23 | path: u.pathname, |
| 24 | method: 'POST', |
| 25 | headers: { |
| 26 | Authorization: 'Bearer ' + token, |
| 27 | 'Content-Type': 'application/json', |
| 28 | 'Content-Length': Buffer.byteLength(payload), |
| 29 | 'x-api-key': 'sk-test', |
| 30 | }, |
| 31 | }, (res) => { |
| 32 | const chunks = []; |
| 33 | res.on('data', (c) => chunks.push(c)); |
| 34 | res.on('end', () => resolve({ |
| 35 | status: res.statusCode, |
| 36 | body: Buffer.concat(chunks).toString(), |
| 37 | })); |
| 38 | }); |
| 39 | req.on('error', reject); |
| 40 | req.write(payload); |
| 41 | req.end(); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | function readJsonl(file) { |
| 46 | return fs.readFileSync(file, 'utf8').trim().split('\n').map((line) => JSON.parse(line)); |
no outgoing calls
no test coverage detected