Skip to content

Simplify encrypt() API with options object

Latest

Choose a tag to compare

@RomainLanz RomainLanz released this 17 Jan 14:22
v0.2.5
a851c3f

New Features

Options object for encrypt method

The encrypt method now accepts an optional object as its second parameter, making it easier to specify only the options you need without passing undefined for unused parameters.

// Before: had to pass undefined to set only purpose
encryption.encrypt(data, undefined, 'password-reset')

// After: use options object
encryption.encrypt(data, { purpose: 'password-reset' })

Available options:

  • expiresIn - TTL for the encrypted value (e.g., '1h', '30m', 7200)
  • purpose - Purpose-bound encryption identifier

Examples:

// Only purpose
encryption.encrypt(data, { purpose: 'email-verification' })

// Only expiration
encryption.encrypt(data, { expiresIn: '24h' })

// Both options
encryption.encrypt(data, { expiresIn: '1h', purpose: 'password-reset' })

Backward Compatibility

The previous positional arguments syntax remains fully supported:

// Still works
encryption.encrypt(data, '1h', 'purpose')
encryption.encrypt(data, undefined, 'purpose')

Type Export

The new EncryptOptions type is exported for TypeScript users:

import type { EncryptOptions } from '@boringnode/encryption/types'