{"id":20740923,"url":"https://github.com/rollbar/rollbar-redux-middleware","last_synced_at":"2025-04-24T02:42:39.389Z","repository":{"id":49560520,"uuid":"92348473","full_name":"rollbar/rollbar-redux-middleware","owner":"rollbar","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-14T15:56:09.000Z","size":990,"stargazers_count":5,"open_issues_count":2,"forks_count":2,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-22T17:47:31.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rollbar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-25T00:33:28.000Z","updated_at":"2021-06-14T15:56:12.000Z","dependencies_parsed_at":"2022-09-15T21:31:18.204Z","dependency_job_id":null,"html_url":"https://github.com/rollbar/rollbar-redux-middleware","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollbar%2Frollbar-redux-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollbar%2Frollbar-redux-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollbar%2Frollbar-redux-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollbar%2Frollbar-redux-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rollbar","download_url":"https://codeload.github.com/rollbar/rollbar-redux-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250551038,"owners_count":21449121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T06:31:14.373Z","updated_at":"2025-04-24T02:42:39.373Z","avatar_url":"https://github.com/rollbar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rollbar-redux-middleware\n\nRedux middleware that integrates with [Rollbar](https://rollbar.com/docs/notifier/rollbar.js/). This middleware assumes the use of \nactions that conform to the [Flux Standard Action](https://github.com/acdlite/flux-standard-action) pattern. Essentially this means\nthat actions of the following form\n\n```js\n{\n    error: true,\n    payload: new Error()\n}\n```\n\nare considered errors to be reported to Rollbar where the error is in the payload field.\nWe include the payload as well as the entire redux store state.\nAdditionally, we provide a configuration option to wrap all actions in a try/catch block rather than\nsimply using FSA style actions to denote errors.\n\n__We provide mechanisms for easily santizing the store before logging (e.g. if you store access tokens in the redux store).__\n\n## Installation\n\nRun `npm install --save rollbar-redux-middleware`.\n\n## Usage\n\nImport `rollbarMiddleware` function from package:\n\n```js\nimport rollbarMiddleware from 'rollbar-redux-middleware';\n```\n\nImport `rollbar` and configure:\n```js\nimport rollbar from 'rollbar';\nvar Rollbar = new rollbar({accessToken: 'POST_CLIENT_ITEM_ACCESS_TOKEN'});\n```\n\nCreate middleware in your store creator:\n```js\nexport default function configureStore(initialState) {\n  const rollbarRedux = rollbarMiddleware(Rollbar);\n\n  return createStore(\n    rootReducer,\n    initialState,\n    applyMiddleware(rollbarRedux)\n  );\n}\n```\n\n## Wrapping actions in a try/catch\n\nIn order to wrap actions in a try/catch block, you must pass three parameters to the function\nexported by this package:\n\n```js\nimport rollbarMiddleware from 'rollbar-redux-middleware';\nconst rollbarRedux = rollbarMiddleware(Rollbar, keyPaths, true);\n```\n\nThe second parameter is used for state sanitization described below. If you do not need or want that\nfunctionality, simply pass an empty array, null, or the identity function as the second parameter.\nThe third parameter of `true` indicates that you do want to wrap actions in a try/catch block. The\nfirst parameter is a configured Rollbar instance to use for reporting.\n\n## State sanitization\nConsider the following state:\n\n```js\n{\n  user: {\n    credentials: {\n      token: 'ABC123',\n      name: 'Bob User'\n    },\n    (...)\n  },\n  billing: {\n    number: '1234 1234 1234 1234',\n    (...)\n  },\n  (...)\n}\n```\n\nIf you want to sanitize the state before sending to Rollbar, we provide two mechanisms. The first is\nto include an array of keypaths that you wish to redact:\n\n```js\nconst keyPaths = [\n  'billing.number',\n  'user.credentials.token'\n]\n```\n\nThen just pass this as the second parameter to `rollbarMiddleware`:\n\n```js\nconst rollbarRedux = rollbarMiddleware(Rollbar, keyPaths)\n```\n\nAlternatively, you can pass a function as the second argument to the `rollbarMiddleware` function.\nIt accepts current application state and should return a state that will be sent to Rollbar.\n\nTo sanitize the example state above the same as the given keypaths, the function provided should be \nsimilar to:\n\n```js\nconst stateSanitizer = function(state) {\n  // make sure you don't change state tree\n  const stateCopy = Object.assign({}, state);\n  // make sure you don't change billing object (by reference)\n  const billingCopy = Object.assign({}, stateCopy.billing);\n  // override number in billing copy\n  billingCopy.number = '********';\n  // pass billing copy to state copy\n  stateCopy.billing = billingCopy;\n\n  // similarly\n  const userCopy = Object.assign({}, stateCopy.user);\n  const credentialsCopy = Object.assign({}, userCopy.credentials)\n  credentialsCopy.token = '********'\n  userCopy.credentials = credentialsCopy;\n  stateCopy.user = userCopy;\n\n  // return sanitized state\n  return stateCopy;\n}\n\nexport default function configureStore(initialState) {\n  const rollbarRedux = rollbarMiddleware(Rollbar, stateSanitizer);\n\n  return createStore(\n    rootReducer,\n    initialState,\n    applyMiddleware(rollbarRedux)\n  );\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frollbar%2Frollbar-redux-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frollbar%2Frollbar-redux-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frollbar%2Frollbar-redux-middleware/lists"}