@exodus/error-tracking 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @exodus/error-tracking
2
+
3
+ A simple namespaces error tracking package to let any feature collect errors and create the report
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ yarn add @exodus/error-tracking
9
+ ```
10
+
11
+ ## Methods
12
+
13
+ `#errorTracking.track({ namespace: string, error: Error | string, context: Object })`
14
+
15
+ Collects tracked error to the provided namespaced error list.
16
+
17
+ ## Usage
18
+
19
+ ### With a dependency injection container
20
+
21
+ ```js
22
+ import errorTracking from '@exodus/error-tracking'
23
+
24
+ const ioc = createIocContainer()
25
+
26
+ const config = { maxErrorsCount: 20 }
27
+ ioc.use(errorTracking(config))
28
+
29
+ ioc.resolve()
30
+ ```
package/api/index.js ADDED
@@ -0,0 +1,38 @@
1
+ const errorTrackingApiDefinition = {
2
+ id: 'errorTrackingApi',
3
+ type: 'api',
4
+ factory: ({ errorsAtom, config }) => {
5
+ if (
6
+ !config.maxErrorsCount ||
7
+ typeof config.maxErrorsCount !== 'number' ||
8
+ config.maxErrorsCount < 1 ||
9
+ config.maxErrorsCount > 9999
10
+ ) {
11
+ throw new Error('`maxErrorsCount` is required config and must be a number [0-9999]')
12
+ }
13
+
14
+ return {
15
+ errors: {
16
+ track: async ({ namespace, error, context }) => {
17
+ if (!namespace) {
18
+ throw new Error('`namespace` is required to track/collect errors')
19
+ }
20
+
21
+ return errorsAtom.set((namespaces) => {
22
+ const errors = namespaces[namespace] || []
23
+ return {
24
+ ...namespaces,
25
+ [namespace]: [{ namespace, error, context, time: Date.now() }, ...errors].slice(
26
+ 0,
27
+ config.maxErrorsCount
28
+ ),
29
+ }
30
+ })
31
+ },
32
+ },
33
+ }
34
+ },
35
+ dependencies: ['config', 'errorsAtom'],
36
+ }
37
+
38
+ export default errorTrackingApiDefinition
package/atoms/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { createInMemoryAtom } from '@exodus/atoms'
2
+
3
+ /* errorsAtom schema:
4
+ {
5
+ `namespace`: [{ `namespace`, `error`, `context`, `time` }, ...]
6
+ }
7
+ */
8
+ const errorsAtomDefinition = {
9
+ id: 'errorsAtom',
10
+ private: true,
11
+ type: 'atom',
12
+ factory: () => createInMemoryAtom({ defaultValue: {} }),
13
+ dependencies: [],
14
+ }
15
+
16
+ export default errorsAtomDefinition
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import errorTrackingApiDefinition from './api/index.js'
2
+ import errorTrackingAtomDefinition from './atoms/index.js'
3
+ import errorTrackingReportDefinition from './report/index.js'
4
+
5
+ const errorTracking = ({ maxErrorsCount = 10 } = Object.create(null)) => ({
6
+ id: 'errorTracking',
7
+ definitions: [
8
+ {
9
+ definition: errorTrackingApiDefinition,
10
+ config: { maxErrorsCount },
11
+ },
12
+ {
13
+ definition: errorTrackingAtomDefinition,
14
+ },
15
+ {
16
+ definition: errorTrackingReportDefinition,
17
+ },
18
+ ],
19
+ })
20
+
21
+ export default errorTracking
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@exodus/error-tracking",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "A simple error tracking package to let any feature collect errors and create the report",
6
+ "author": "Exodus Movement, Inc.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
10
+ },
11
+ "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/features/error-tracking",
12
+ "license": "UNLICENSED",
13
+ "bugs": {
14
+ "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aerror-tracking"
15
+ },
16
+ "main": "index.js",
17
+ "exports": "./index.js",
18
+ "files": [
19
+ ".",
20
+ "api",
21
+ "atoms",
22
+ "report",
23
+ "CHANGELOG.md",
24
+ "README.md",
25
+ "!**/__tests__/**"
26
+ ],
27
+ "scripts": {
28
+ "test": "run -T jest",
29
+ "lint": "run -T eslint . --ignore-path ../../.gitignore",
30
+ "lint:fix": "yarn lint --fix"
31
+ },
32
+ "dependencies": {
33
+ "@exodus/atoms": "^7.5.0"
34
+ },
35
+ "gitHead": "5618f82730d7fab9716a974488d2d96afbe99922"
36
+ }
@@ -0,0 +1,13 @@
1
+ const errorTrackingReportDefinition = {
2
+ type: 'report',
3
+ id: 'errorTrackingReport',
4
+ factory: ({ errorsAtom }) => ({
5
+ namespace: 'errorTracking',
6
+ export: async () => {
7
+ return errorsAtom.get()
8
+ },
9
+ }),
10
+ dependencies: ['errorsAtom'],
11
+ }
12
+
13
+ export default errorTrackingReportDefinition