diff --git a/src/mail.js b/src/mail.js index eead642..4996b6f 100644 --- a/src/mail.js +++ b/src/mail.js @@ -40,6 +40,7 @@ export const mail = async ({ env = {}, ...rest }) => { attachments: !!rest.attachments, contentType: rest.type, status: response.status, + userAgent: rest.userAgent, }, }); if (response.status > 299) { diff --git a/src/mail.test.js b/src/mail.test.js index f4d3c69..898ba00 100644 --- a/src/mail.test.js +++ b/src/mail.test.js @@ -47,7 +47,11 @@ describe('mail', () => { }); it('logs', async () => { global.fetch.mockResolvedValue({ json: () => '{}', status: 200 }); - await mail({ ...input, to: 'one@example.com,two@example.com' }); + await mail({ + ...input, + to: 'one@example.com,two@example.com', + userAgent: 'custom-user-agent 1.0', + }); expect(global.fetch).toHaveBeenCalledWith( 'https://api.logsnag.com/v1/log', expect.objectContaining({ @@ -61,6 +65,7 @@ describe('mail', () => { attachments: true, contentType: 'text/html', status: 200, + userAgent: 'custom-user-agent 1.0', }, }), }), diff --git a/src/params.js b/src/params.js index 759cb11..01a4922 100644 --- a/src/params.js +++ b/src/params.js @@ -34,6 +34,8 @@ export const params = async (request) => { // pass } + data.userAgent = request.headers.get('user-agent'); + data.errors = required.reduce( (acc, el) => data?.[el] ? acc : [...acc, `missing required parameter '${el}'`], diff --git a/src/params.test.js b/src/params.test.js index de2eef1..24f4bbb 100644 --- a/src/params.test.js +++ b/src/params.test.js @@ -20,6 +20,7 @@ describe.each(['application/json', 'application/x-www-form-urlencoded'])( method: 'POST', headers: { 'Content-Type': contentType, + 'User-Agent': 'custom-user-agent 1.0', }, body: (format[contentType] ?? ((d) => d))(body), }); @@ -27,6 +28,7 @@ describe.each(['application/json', 'application/x-www-form-urlencoded'])( expect(await params(request)).toEqual({ errors: [], ...body, + userAgent: 'custom-user-agent 1.0', }); });