Comparing version 0.20.2 to 0.20.3
{ | ||
"name": "middy", | ||
"version": "0.20.2", | ||
"version": "0.20.3", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -9,3 +9,3 @@ const middy = require('../../middy') | ||
{ | ||
'eventVersion': '2.0', | ||
'eventVersion': '2.1', | ||
'eventTime': '1970-01-01T00:00:00.000Z', | ||
@@ -63,3 +63,3 @@ 'requestParameters': { | ||
{ | ||
'eventVersion': '2.0', | ||
'eventVersion': '2.1', | ||
'eventTime': '1970-01-01T00:00:00.000Z', | ||
@@ -111,2 +111,53 @@ 'requestParameters': { | ||
test('It should normalize the event if the event version is 2.x', () => { | ||
const event = { | ||
'Records': [ | ||
{ | ||
'eventVersion': '2.3', | ||
'eventTime': '1970-01-01T00:00:00.000Z', | ||
'requestParameters': { | ||
'sourceIPAddress': '127.0.0.1' | ||
}, | ||
's3': { | ||
'configurationId': 'testConfigRule', | ||
'object': { | ||
'sequencer': '0A1B2C3D4E5F678901', | ||
'key': 'This+is+a+picture.jpg' | ||
}, | ||
'bucket': { | ||
'arn': 'arn:aws:s3:::mybucket', | ||
'name': 'sourcebucket', | ||
'ownerIdentity': { | ||
'principalId': 'EXAMPLE' | ||
} | ||
}, | ||
's3SchemaVersion': '1.0' | ||
}, | ||
'responseElements': { | ||
'x-amz-id-2': 'EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH', | ||
'x-amz-request-id': 'EXAMPLE123456789' | ||
}, | ||
'awsRegion': 'us-east-1', | ||
'eventName': 'ObjectRemoved:Delete', | ||
'userIdentity': { | ||
'principalId': 'EXAMPLE' | ||
}, | ||
'eventSource': 'aws:s3' | ||
} | ||
] | ||
} | ||
const handler = middy((event, context, callback) => { | ||
callback(null, event) // returns the event as response | ||
}) | ||
handler | ||
.use(s3KeyNormalizer()) | ||
// invokes the handler | ||
handler(event, {}, (_, response) => { | ||
expect(response.Records[0].s3.object.key).toEqual('This is a picture.jpg') | ||
}) | ||
}) | ||
test('It should not normalize the event if it doesn\'t look like an S3 event', () => { | ||
@@ -113,0 +164,0 @@ const alexaEvent = { |
@@ -7,3 +7,4 @@ const normalizeKey = (key) => decodeURIComponent(key.replace(/\+/g, ' ')) | ||
handler.event.Records = handler.event.Records.map((record) => { | ||
if (record.s3 && record.s3.object && record.eventVersion === '2.0') { | ||
const eventVersion = parseFloat(record.eventVersion) | ||
if (record.s3 && record.s3.object && eventVersion >= 2 && eventVersion < 3) { | ||
record.s3.object.key = normalizeKey(record.s3.object.key) | ||
@@ -10,0 +11,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164121
4150