Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MessageValidator
✓ const MessageValidator = require('sns-validator')
✗ import MessageValidator from 'sns-validator'
Package uses CommonJS. No default ES module export. Use require() or dynamic import().
new MessageValidator
✓ const validator = new MessageValidator()
✗ const validator = new MessageValidator({})
Constructor does not accept options in current version.
validate method
✓ validator.validate(messageObj, (err, message) => {})
✗ validator.validate(messageObj).then()
validate uses callback pattern, not Promises.
Shows how to validate an inbound SNS notification message using callback pattern.
const MessageValidator = require('sns-validator');
const validator = new MessageValidator();
// Example SNS message object (from HTTP POST body parsed as JSON)
const message = {
Type: 'Notification',
MessageId: 'da41e39f-ea4d-435a-b922-c6aae3915ebe',
TopicArn: 'arn:aws:sns:us-west-2:123456789012:MyTopic',
Message: 'Hello from SNS!',
Timestamp: '2012-05-03T23:42:17.000Z',
SignatureVersion: '1',
Signature: 'tcc6faL2yUC6dgZdmrwh1Y4cGa/ebXEkAi6RibDsvpi+tE/1+82j...',
SigningCertUrl: 'https://sns.us-west-2.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem',
UnsubscribeUrl: 'https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55'
};
validator.validate(message, (err, validatedMessage) => {
if (err) {
console.error('Validation failed:', err.message);
process.exit(1);
}
console.log('Validated message:', validatedMessage);
});
Errors
Common errors & fixes
TypeError: validator.validate is not a function
Imported incorrectly (e.g., using ES import instead of require).
fixUse const MessageValidator = require('sns-validator'); TypeError: Cannot read property 'SigningCertUrl' of undefined
Passed raw HTTP body string instead of parsed object.
fixCall JSON.parse(body) before passing to validate.
TypeError: callback is not a function
Called validate without a callback function.
fixProvide a callback: validator.validate(message, (err, msg) => { ... }); Audit
Dependencies
No dependency data recorded yet.