@marteye/studio-cli
Version:
CLI for MartEye Studio API
35 lines (31 loc) • 1.35 kB
JavaScript
;
var commander = require('commander');
var studio = require('../utils/studio.js');
var output = require('../utils/output.js');
function webhooksCommand() {
const webhooks = new commander.Command('webhooks')
.description('Webhook operations');
webhooks
.command('validate')
.description('Validate webhook signature')
.requiredOption('--body <body>', 'Request body')
.requiredOption('--signature <signature>', 'Signature from header')
.requiredOption('--secret <secret>', 'Endpoint secret')
.action(async (options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const bodyBuffer = Buffer.from(options.body, 'utf-8');
const event = await studio$1.webhooks.constructEvent(bodyBuffer, options.signature, options.secret);
output.success('Webhook signature is valid');
output.output(event, globalOptions);
}
catch (err) {
output.error('Invalid webhook signature', err.message);
process.exit(1);
}
});
return webhooks;
}
exports.webhooksCommand = webhooksCommand;
//# sourceMappingURL=webhooks.js.map