Skip to content

Commit

Permalink
fix: fixed browser environment of omittedFields
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 17, 2022
1 parent 1cd4041 commit 3592791
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ See [Browser](#browser-1) usage below for more information.
| `meta` | Object | See below | Stores all meta config information (see the following nested properties below). | |
| `meta.show` | Boolean | `true` | Attempts to parse a boolean value from `process.env.AXE_SHOW_META` – meaning you can pass a flag `AXE_SHOW_META=true node app.js` when needed for debugging), whether or not to output metadata to logger methods. If set to `false`, then fields will not be omitted nor picked; the entire meta object will be hidden from logger output. | |
| `meta.remappedFields` | Object | `{}` | Attempts to parse an Object mapping from `process.env.AXE_REMAPPED_META_FIELDS` (`,` and `:` delimited, e.g. `REMAPPED_META_FIELDS=foo:bar,beep.boop:beepBoop` to remap `meta.foo` to `meta.bar` and `meta.beep.boop` to `meta.beepBoop`). Note that this will clean up empty objects by default unless you set the option `meta.cleanupRemapping` to `false`). Supports dot-notation. | |
| `meta.omittedFields` | Array | `['level','err','app', 'args']` | Attempts to parse an array value from `process.env.AXE_OMIT_META_FIELDS` (`,` delimited) - meaning you can pass a flag `OMIT_META_FIELDS=user,id node app.js`), determining which fields to omit in the metadata passed to logger methods. Supports dot-notation. | |
| `meta.omittedFields` | Array | `['level','err','app', 'args']` in Node environments and `[]` in Browser environments | Attempts to parse an array value from `process.env.AXE_OMIT_META_FIELDS` (`,` delimited) - meaning you can pass a flag `OMIT_META_FIELDS=user,id node app.js`), determining which fields to omit in the metadata passed to logger methods. Supports dot-notation. | |
| `meta.pickedFields` | Array | `[]` | Attempts to parse an array value from `process.env.AXE_PICK_META_FIELDS` (`,` delimited) - meaning you can pass a flag, e.g. `PICK_META_FIELDS=request.headers,response.headers node app.js` which would pick from `meta.request` and `meta.response` *only* `meta.request.headers` and `meta.response.headers`), **This takes precedence after fields are omitted, which means this acts as a whitelist.** Supports dot-notation. | |
| `meta.cleanupRemapping` | Boolean | `true` | Whether or not to cleanup empty objects after remapping operations are completed) | |
| `silent` | Boolean | `false` | Whether or not to invoke logger methods. Pre and post hooks will still run even if this option is set to `false`. | |
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ function isFunction(value) {
return typeof value === 'function';
}

const isBrowser =
typeof window !== 'undefined' && typeof window.document !== 'undefined';

class Axe {
// eslint-disable-next-line complexity
constructor(config = {}) {
const remappedFields = {};
if (process.env.AXE_REMAPPED_META_FIELDS) {
Expand All @@ -118,7 +122,10 @@ class Axe {
remappedFields,
omittedFields: process.env.AXE_OMIT_META_FIELDS
? process.env.AXE_OMIT_META_FIELDS.split(',').map((s) => s.trim())
: ['level', 'err', 'app', 'args'],
: // browser environments should send client-side payload with all metadata
isBrowser
? ['level', 'err', 'app', 'args']
: [],
pickedFields: process.env.AXE_PICK_META_FIELDS
? process.env.AXE_PICK_META_FIELDS.split(',').map((s) => s.trim())
: [],
Expand Down

0 comments on commit 3592791

Please sign in to comment.