const readline = require('readline');
function readAllStdin() {
return new Promise((resolve) => {
let lines = [];
const rl = readline.createInterface({
input: process.stdin,
terminal: false,
});
rl.on('line', (line) => {
lines.push(line);
});
rl.on('close', () => {
resolve(lines.join('\n'));
});
});
}
(async () => {
console.error('⚙ Starting execution...');
const inputRaw = await readAllStdin();
if (!inputRaw) {
console.error('✗ No input received on Stdin!');
process.exit(1);
}
console.error('⚙ Received Input: ' + inputRaw);
let inputs;
try {
inputs = JSON.parse(inputRaw);
} catch (e) {
console.error('✗ Invalid JSON: ' + e.message);
process.exit(1);
}
let output = {};
if (inputs.auth_token === 'secret123') {
console.error('✓ Auth success!');
output = {
branch: 'success',
store: {
user_role: 'admin',
verified: 'true',
},
};
} else {
console.error(`✗ Auth failed. Token was: ${inputs.auth_token}`);
output = {
branch: 'failure',
store: {
error_reason: 'invalid_token',
},
};
}
process.stdout.write(JSON.stringify(output));
})();