Hook utilities

While hooks typically rely on external packages or libraries, direct package imports are disabled for security and performance reasons. Instead, Cloudhooks provides pre-approved utility packages and functions through the built-in hookUtils object.

Available Utilities

Currently, hookUtils includes:

Name Type Description
crypto package The built-in crypto package of NodeJS.

Note: Additional utility packages will be added in future releases based on common usage patterns and security requirements.

Using the Crypto Package

The crypto package provides cryptographic functions from the NodeJS crypto module. With this utility, you can perform various cryptographic operations including:

  • Message hashing (MD5, SHA-1, SHA-256, etc.)
  • HMAC generation
  • Symmetric encryption/decryption
  • Random number generation
  • Key pair generation

Here's an example of generating a hash:

module.exports = async function(payload, actions, context) {

  const secret = 'abcdefg';
  const hash = hookUtils.crypto.createHmac('sha256', secret)
                 .update('I love cupcakes')
                 .digest('hex');

  console.log('Generated hash: ', hash);
}