const fsPromises = require('fs').promises;
const axios = require('axios');
const iexecOut = process.env.IEXEC_OUT;
// get the secret endpoint from requester secrets
const secretNamespace = process.env.IEXEC_REQUESTER_SECRET_1;
const secretKey = process.env.IEXEC_REQUESTER_SECRET_2;
console.log('missing requester secret 1 (namespace)');
console.log('missing requester secret 2 (key)');
// get the hit count from countapi
const hitCount = await axios.get(`https://api.countapi.xyz/hit/${secretNamespace}/${secretKey}`)
.then(({data}) => data.value);
const result = `endpoint hit ${hitCount} times`;
await fsPromises.writeFile(`${iexecOut}/result.txt`, result);
// declare everything is computed
const computedJsonObj = {
'deterministic-output-path': `${iexecOut}/result.txt`,
await fsPromises.writeFile(
`${iexecOut}/computed.json`,
JSON.stringify(computedJsonObj),
// do not log anything that could reveal the requester secrets!
console.log('something went wrong');