Skip to content

Commit

Permalink
Merge pull request #557 from MiguelNazMor/add_support_for_arrays
Browse files Browse the repository at this point in the history
Add lodash cloneDeep to support arrays in omitPaths
  • Loading branch information
willfarrell authored Aug 30, 2020
2 parents 3e5fbc5 + f1efcad commit 3625b1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/input-output-logger/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,23 @@ describe('📦 Middleware Input Output Logger', () => {
expect(logger).toHaveBeenCalledWith({ event: { foo: 'bar', fuu: 'baz' } })
expect(logger).toHaveBeenCalledWith({ response: 'yo' })
})

test('Skipped parts should be present in the response', async () => {
const logger = jest.fn()

const handler = middy((event, context, cb) => {
cb(null, { foo: [{ foo: 'bar', fuu: 'baz' }] })
})

handler
.use(inputOutputLogger({ logger, omitPaths: ['event.zooloo', 'event.foo.hoo', 'response.foo[0].foo'] }))

const response = await invoke(handler, { foo: 'bar', fuu: 'baz' })

expect(logger).toHaveBeenCalledWith({ event: { foo: 'bar', fuu: 'baz' } })
expect(logger).toHaveBeenCalledWith({ response: { foo: [{ fuu: 'baz' }] } })

expect(response).toMatchObject({ foo: [{ foo: 'bar', fuu: 'baz' }] })
})
})
})
5 changes: 4 additions & 1 deletion packages/input-output-logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ module.exports = (opts) => {

const { logger, omitPaths } = Object.assign({}, defaults, opts)

const cloneMessage = message => JSON.parse(JSON.stringify(message))

const omitAndLog = message => {
const redactedMessage = omit(message, omitPaths)
const messageClone = cloneMessage(message)
const redactedMessage = omit(messageClone, omitPaths)
logger(redactedMessage)
}

Expand Down

0 comments on commit 3625b1e

Please sign in to comment.