{"_id":"@casedinc/cased","_rev":"3-05a011dc71ecb0f83ccdc62b9632acfe","name":"@casedinc/cased","dist-tags":{"latest":"0.1.4"},"versions":{"0.1.2":{"name":"@casedinc/cased","version":"0.1.2","description":"Node library for the Cased API","main":"./lib/index.js","types":"./lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/cased/cased-node.git"},"dependencies":{},"devDependencies":{"@types/express":"^4.17.6","@types/jest":"25.2.3","@types/node":"14.0.5","jest":"26.0.1","prettier":"2.0.5","ts-jest":"26.0.0","typescript":"3.9.3"},"scripts":{"build":"tsc","lint":"prettier --check .","test":"jest","prepublishOnly":"tsc"},"license":"MIT","bugs":{"url":"https://github.com/cased/cased-node/issues"},"homepage":"https://github.com/cased/cased-node#readme","directories":{"lib":"lib","test":"test"},"author":{"name":"Cased, Inc."},"gitHead":"38f27142d9e7b36659a7fb37739f23f3ae8f28ca","_id":"@casedinc/cased@0.1.2","_nodeVersion":"14.4.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-VEdRZoDTExRw5fIUKAbUXdJJw5CrRcvNzaojHjNW6bUJbvPidj3zoTKoLJdxaJFD0H+zq00+9HcGgV3YI23/rw==","shasum":"e478f02e461bf4836ef56d0749a18526352490b5","tarball":"https://registry.npmjs.org/@casedinc/cased/-/cased-0.1.2.tgz","fileCount":25,"unpackedSize":59477,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfdQMICRA9TVsSAnZWagAAB9gP+gPk9uPh4Q/kq/zQ/80S\nXOm0cW5eDTTfynkSaB5+mwTDfjf3fMEO6NXcIY5yJ5spTwx7DxGN0p3Fuw53\nXWZru3t0fl1U6m/nrELwuHVA/9zxjsnTXbi5tnRppBmdMPj9gTIuYr0GPVQr\nmZqcLFpDoVdQo9Pj4V5kmV2cjSsROtCPW1cwGRtfg6DZ1IOkduehjIwP/28E\nuQUs4i2U/abtYk81ZX39loDC71/gNcmJdOMAh5H00Y5c1GrAxQatJG2K6WON\nW6d7kr/MnxaNQcsh69DMcakMch67g5bOMLSIWV3M/A/qM6WYEHUmvQNqRUym\nZr7FfUQYkbq3INnShiUP4RSXbw5vwOkcWBDGAEyJvUJ4doxV9WXaxUvG7JrF\nTuPFK7LBBylPLJ+VXt5lGfrd8FLtZciPyxSbOmG7fGxm6khr5+sZQUd54nRM\n8cYs8nUyTqbCJmxnA1O37p1AInu0Irqa+gp2hrYEE4CVKMRiVu01QpXBbroG\nyOaNuSFauuW7Bqc2PeEysHdx10IhBesqo7qydWpZ5Km9JPabF93MTxV0Vn5H\nYcXaaaZw4+5KjPvRND+bUAsUBoPG3Vst3TFfuLKphzjfKB/NPKQofjQciMec\neJmqMi26IpZnoLkf1BARIEixVc000s0cI2JWjJGezT3phr8gwTGMAYnzwRda\nI2n3\r\n=dfJG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD37xgo+IBFPF7gs1inpXjzfKvC5hWhDrXsq0c3yHWyugIhAOKRUcNe8QNCbHgCbhsLf+CTplds2aUpkj9KfVR0CMYH"}]},"maintainers":[{"name":"cased","email":"eng@cased.com"}],"_npmUser":{"name":"cased","email":"eng@cased.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cased_0.1.2_1601504007990_0.9180608626534639"},"_hasShrinkwrap":false},"0.1.3":{"name":"@casedinc/cased","version":"0.1.3","description":"Node library for the Cased API","main":"./lib/index.js","types":"./lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/cased/cased-node.git"},"dependencies":{},"devDependencies":{"@types/express":"^4.17.6","@types/jest":"25.2.3","@types/node":"14.0.5","jest":"26.0.1","prettier":"2.0.5","ts-jest":"26.0.0","typescript":"3.9.3"},"scripts":{"build":"tsc","lint":"prettier --check .","test":"jest","prepublishOnly":"tsc"},"license":"MIT","bugs":{"url":"https://github.com/cased/cased-node/issues"},"homepage":"https://github.com/cased/cased-node#readme","directories":{"lib":"lib","test":"test"},"author":{"name":"Cased, Inc."},"gitHead":"653ef86c462f4da7638413f2b2722f1bd2cc6f3b","_id":"@casedinc/cased@0.1.3","_nodeVersion":"14.4.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-jWf+U3EF1beZ1jcRkmBqWp+YqFnh0DPs/F3yAu3ZsY99rZhriJa5URL8fX/V//XFUKFkz7Fkg7fE9LnfPP/Bfg==","shasum":"c2aebc68bc6d47f6a5df8fe92383aafb5d586814","tarball":"https://registry.npmjs.org/@casedinc/cased/-/cased-0.1.3.tgz","fileCount":25,"unpackedSize":59498,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfdQiyCRA9TVsSAnZWagAA8UYP/3FyX8J0o5yGpLeCQXbT\nd/mkUkZ7ppmG2Hkpx1iQQNNcE/9ztbR2SD+6vL8XnW5w3vcltZwlfNAp1AIt\n5vJkB5hWVwnumFV+P/XlTNhOidQXgTBFsUFkhf6e6aWBuEAgtgAcnBxHH6GM\nHi1qxVKrbclFiITaZKycX8EGhTErS/kZquYy6CCK23KS8v+bzQIC2l6gjTUI\nvkZ3goKbdffQGB2hh3RW63tFpSFNYnbp9NkZZ2JbQ5jadJzsbih/18F/ooC8\nOtu/u9kcmAOwVkcqOY6Ajf9ZWXeFn7zabl+aM23Z3TaSAF3mIhqLRehqdGPQ\nn5b2j99QM9ceWuUHLCMXf5Ot7Th1noDdE2/NRb/J9vZuut8PFw0ftmPi1q0r\n959UCTK+UoioJLCHqjk4uxuI50ANbfeHsZTzYARw2nx1OAnfFocEZ6H2MzW7\nRJWMTu9o2eG9JdKwdGkiJsiYx3K35aEWSypMseKy7rOUV4SeUIPvxIS7OWXm\n7r8Za72UOYfayXvbBqZHNSKEqJBCcjaiMWcWh4Acsn5BV8GlMmTHENv14Aks\n5WxH7Elr4UYY1DD35SaLmxZnTz+UqugglT+9s3BxLpTK6BxJ8qBEn6a/g4TK\n4gGrJwhZgvSitBM6yS6gn4OBuE4UpRtQPRmLC4e2qtIesrL/vFbVmroeY+79\noaHd\r\n=pVAr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCT8Mw4qmZ57/kDZFpyZ9fLB3qYUAqKrLm9/eaasxaTKQIgWNsDAtPPxLD4Ze0b+mcVeXdF/McMiVpyHCSO9/aX2dM="}]},"maintainers":[{"name":"cased","email":"eng@cased.com"}],"_npmUser":{"name":"cased","email":"eng@cased.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cased_0.1.3_1601505458069_0.1951186990011542"},"_hasShrinkwrap":false},"0.1.4":{"name":"@casedinc/cased","version":"0.1.4","description":"Node library for the Cased API","main":"./lib/index.js","types":"./lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/cased/cased-node.git"},"dependencies":{},"devDependencies":{"@types/express":"^4.17.6","@types/jest":"25.2.3","@types/node":"14.0.5","jest":"26.0.1","prettier":"2.0.5","ts-jest":"26.0.0","typescript":"3.9.3"},"scripts":{"build":"tsc","lint":"prettier --check .","test":"jest","prepublishOnly":"tsc"},"license":"MIT","bugs":{"url":"https://github.com/cased/cased-node/issues"},"homepage":"https://github.com/cased/cased-node#readme","directories":{"lib":"lib","test":"test"},"author":{"name":"Cased, Inc."},"gitHead":"0511863e336a4d16be8b90c5c934a5179f30e497","_id":"@casedinc/cased@0.1.4","_nodeVersion":"14.4.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-QU+7aO9MAwPjG9jRVBT/GM5nzziDy+PwFTfbn7xyUFeK3/DucrBTLzH8R4U7O7hJQMU3XdNxEq7BRTKSv7KoiQ==","shasum":"f498ead0e470db8b392ef70091ef476ff99425f0","tarball":"https://registry.npmjs.org/@casedinc/cased/-/cased-0.1.4.tgz","fileCount":25,"unpackedSize":59609,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfdWXtCRA9TVsSAnZWagAAvZgP/i6UK5W5hBU9UYYsroT+\nbXN1nvOJEo+0BSuUw/NzPrC/gD469PaFq/kUTJKsGWHsmyrH2FyJ5PU5IRmb\n9xF80u5JOElEmQA4zrIkbhZnJE43faGYlW2Ux9SvftvU2/vWP1LSWA5BzyPr\nLFn82L4GkMGT9VwmQpjSa0RPQ0ITVAN2PcS2OUqwUeJcylIHPIk9pgv40q5U\nQDyGJtSKlbIDE0sOs1L6j3hxAKeHsC+mHegPmfVqLEDfq0rqkEAAS3tyAYHM\n4URdbE0NvBDHv8zONqwY+PpUCl65c90pS6H7ZIeMh+Tp5mVPJBKqBqsgpDY8\n1ZyuBMPlBmBv6aAiZWjbE+1kV3qdQBm2Qyuna0HElEMWuM4z+q16VzZ0y6Lp\nxYKWkK8syVdj35Ix8PESMsFmTrZkelxjsdfVHMc/h2SImQfwmG2E5t7kssPV\nomnzg2oc88pcum1UeMfZtgj8N0VDe/+y1ioAyUoAAGyuS2SVGcTRBBamXPwG\ng3Akk2LnVWrWxQkNVvDDgfhRA8DxdThw7+HGb1gPMqDtqIjCIsAGFGfWDUp+\ndG7LEB6LqkeCLg89o2qubDwuVG2QX5QHqD5NKlJf6H4J5cE8QA0uHTl931JX\nuBAPgyQJ/nc+CA/+l81adYLPDLLx+f1RYULEXrNdWr7jIot9FBg3CGqKFjP/\nEf5P\r\n=0sxk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDPxP59miEoj42H5iZgj0WB72qa1/+6E9KK2OlZ3XTscAIhANEacJfTFohy7QKgZWIxO1ReOfAdVj3WJbnKrHyJp2H3"}]},"maintainers":[{"name":"cased","email":"eng@cased.com"}],"_npmUser":{"name":"cased","email":"eng@cased.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cased_0.1.4_1601529324692_0.7200075251236309"},"_hasShrinkwrap":false}},"time":{"created":"2020-09-30T22:13:27.989Z","0.1.2":"2020-09-30T22:13:28.171Z","modified":"2022-04-04T22:01:19.128Z","0.1.3":"2020-09-30T22:37:38.328Z","0.1.4":"2020-10-01T05:15:24.926Z"},"maintainers":[{"name":"cased","email":"eng@cased.com"}],"description":"Node library for the Cased API","homepage":"https://github.com/cased/cased-node#readme","repository":{"type":"git","url":"git+https://github.com/cased/cased-node.git"},"author":{"name":"Cased, Inc."},"bugs":{"url":"https://github.com/cased/cased-node/issues"},"license":"MIT","readme":"# cased-node\n\n`cased-node` is the official node client for [Cased](https://cased.com), a web service for adding audit trails to any application in minutes. This node client makes it easy to record and query your Cased audit trail events. The client also includes a robust set of features to mask PII, add client-side resilience, and automatically augment events with more data.\n\n| Contents                         |\n| :------------------------------- |\n| [Installation](##installation)   |\n| [Configuration](##configuration) |\n| [How To Guide](##usage-guide)    |\n| [Tests](##tests)                 |\n\n## Installation\n\nThe recommended way to install the Cased library module is via npm.\n\n```\nnpm install -g @casedinc/cased\n```\n\n## Configuration\n\nThe client can be configured using environment variables or initialized programmatically.\n\nTo start sending events, the client will look for `CASED_PUBLISH_KEY`. This can be found in your [Cased](https://app.cased.com) dashboard.\nThe API key can also be provided programatically and this will take precedence if provided. Example environment variable usage:\n\n```\n$ CASED_PUBLISH_KEY=\"publish_test_c260ffa178db6d5953f11f747ecb7ee3\" node app.js\n```\n\nOr programmatically:\n\n```javascript\nimport { config } from \"@casedinc/cased\";\nconfig.publishKey = \"publish_test_c260ffa178db6d5953f11f747ecb7ee3\";\n```\n\nYou can also send your API key with each request:\n\n```javascript\nimport { Event } from \"@casedinc/cased\";\n\nawait Event.publish(\"user.login\", {\n  publishKey: \"publish_test_c260ffa178db6d5953f11f747ecb7ee3\",\n});\n```\n\n## How To Guide\n\nRecord your first audit trail event using the `publish()` function on the `Event` module.\n\n```javascript\nimport { Event } from \"@casedinc/cased\";\n\nawait Event.publish({\n  event: \"user.login\",\n  location: \"130.25.167.191\",\n  request_id: \"e851b3a7-9a16-4c20-ac7f-cbcdd3a9c183\",\n  server: \"app.fe1.disney.com\",\n  session_id: \"e2bd0d0e-165c-4e2a-b40b-8e2997fd7915\",\n  user_agent:\n    \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\",\n  user_id: \"User;1\",\n  user: \"mickeymouse\",\n});\n```\n\n### Fetch an event\n\nEvent can then be fetched later by their ID.\n\n```javascript\nimport { Event } from \"@casedinc/cased\";\nconfig.policyKey = \"policy_test_f764a5f252aaca986b0526b42a6f7e95\";\n\nawait Event.fetch(\"e19a2032-f841-426c-8a13-5a938e7934a3\");\n```\n\n### Result lists and pagination\n\nMany resources, such as `Event` and `Policy` can return paged result sets.\n\n```javascript\nimport { Event } from \"@casedinc/cased\";\n\nconst events = await Event.search({ action: \"team.update\" });\n\nfor (event of events) {\n  console.log(event);\n}\n```\n\nBy default, 25 items are returned per page. This can be adjusted, with a maximum of 50 items.\n\n```javascript\nconst events = await Event.search({ action: \"team.update\" }, { perPage: 50 });\n```\n\nYou can get metadata:\n\n```javascript\nevents.totalCount; // Total count of objects\nevents.pageCount; // Total number of pages\n```\n\nThen fetch the next, previous, first or last page.\n\n```javascript\nconst nextPageOfEvents = await page.nextPage();\nconst previousPageofEvents = await page.previousPage();\nconst firstPageOfEvents = await page.firstPage();\nconst lastPageOfEvents = await page.lastPage();\n```\n\nAn async iterator is also provided.\n\n```javascript\nconst events = await Event.search({ action: \"team.update\" });\n\nfor async (const event of events) {\n  console.log(event)\n}\n```\n\n### Searching\n\nYou can search for events by using `Event.search` with an object:\n\n```javascript\nimport { Event } from \"@casedinc/cased\";\n\nconst events = await Event.search({ actor: \"jill\" });\n```\n\nYou can use some convenience functions:\n\n```javascript\nawait Event.searchActor(\"jill\");\n\nawait Event.searchAction(\"invite.created\");\n```\n\nYou can also do a raw search, using a string phrase:\n\n```javascript\nawait Event.search(\"actor:jill AND event:invite.created\");\n```\n\n## Event Processors\n\nEvent processors are custom functions that modify or add additional keys to published events.\n\nProcessors are just simple functions that take an audit event and return a new modified event.\n\nHere's an example of the default plugin that ships with this library:\n\n```javascript\nconst defaultEventProcessor = (event) => {\n  return {\n    cased_id: randomBytes(16).toString(\"hex\"),\n    timestamp: new Date().toISOString(),\n    ...event,\n  };\n};\n```\n\nProcessors can be registered globally or passed along as an option to `Event.publish`.\n\n```javascript\nimport { config, Event } from \"@casedinc/cased\";\n\nconst myProcessor = (event) => {};\n\n// run myProcessor on all events\nconfig.eventPipeline.push(myProcessor);\n\n// run myProcessor on just this publish\nawait Event.publish(\"user.login\", { eventPipeline: [myProcessor] });\n```\n\n### Sensitive Data\n\nThere is a special set of event processors designed specifically to help mask sensitive PII.\n\n```javascript\nimport { config, EventProcessor } from \"@casedinc/cased\";\n\nconfig.eventPipeline.push(\n  EventProcessor.sensitiveField(\"username\"),\n  EventProcessor.sensitiveField(\"address\")\n);\n```\n\nAny field, in any audit event, that matches one of those key name will be marked as sensitive when sent to Cased.\n\nYou can also mark _patterns_ in your audit trail as sensitive in order to mask PII.\n\n```javascript\nimport { config, EventProcessor } from \"@casedinc/cased\";\n\nconfig.eventPipeline.push(\n  EventProcessor.sensitivePattern(\"username\", /@([A-Za-z0-9_]+)/g)\n);\n```\n\nA sensitive data handler includes a `label`, which makes it easy to identify what kind of data is being masked. Additionally, it includes a `pattern`, which is a regular expression matching a pattern you want to mark as sensitive.\n\nNow any data you send that matches that pattern with will be marked as PII when sent to Cased.\n\n### Contextual Data\n\nIf you're using a Node v14 and are willing to use an experimental API, Async Hooks provide the ability to attach contextual data to all Cased events.\n\n```javascript\nimport { Context as CasedContext } from \"@casedinc/cased\"\n\napp.use(CasedContext.middleware));\n```\n\nSee the Node documentation on [`AsyncLocalStorage`](https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage) as it's API is subject to change in the future.\n\n## Testing\n\nIn your tests, you'll likely want to disable publishing events. You can do this globally by setting the `mockPublishEvents` config value.\n\n```javascript\nimport { config } from \"@casedinc/cased\";\nconfig.mockPublishEvents = true;\n```\n\nYou can also capture events published during a test to use for your own assertions.\n\n```javascript\nimport { config, Event } from \"@casedinc/cased\";\n\nbeforeEach(() => {\n  config.mockPublishEvents = [];\n});\n\ntest(\"publish\", async () => {\n  expect(config.mockPublishEvents.length).toBe(0);\n  await Event.publish(\"user.login\");\n  expect(config.mockPublishEvents.length).toBe(1);\n});\n```\n\n## Contributing\n\nContributions to this library are welcomed and a complete test suite is available. Tests can be run locally using the following command:\n\n```\n$ npm test\n```\n","readmeFilename":"README.md"}