@apolitical/error-reporting 0.0.1 → 0.0.3-beta.3

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/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.3] - 2022-01-31
9
+ ### Fixed
10
+ - Node.js version
11
+ ### Removed
12
+ - Buffer dependency
13
+
14
+ ## [0.0.2] - 2022-01-14
15
+ ### Updated
16
+ - Dependencies
17
+
8
18
  ## [0.0.1] - 2021-06-14
9
19
  ### Added
10
20
  - Initial setup
package/README.md CHANGED
@@ -6,7 +6,7 @@ Browser (and Node.js) library to report errors to GCP
6
6
 
7
7
  Requires the following to run:
8
8
 
9
- - [node.js][node] 12.20.1+
9
+ - [node.js][node] 16.13.0+
10
10
  - [yarn][yarn]
11
11
 
12
12
  [node]: https://nodejs.org/en/download/
@@ -53,15 +53,5 @@ setContext({
53
53
  And then, you can report the error to GCP like this:
54
54
 
55
55
  ```js
56
- await reportError({
57
- error: new Error('somthing went wrong'),
58
- userId: 'some-user',
59
- });
56
+ await reportError(new Error('Something went wrong'));
60
57
  ```
61
-
62
- ## Troubleshooting
63
-
64
- ### Usage of other libraries within your library
65
-
66
- - Add the library as a dependency in `package.json` (effectively requiring the calling project to provide this dependency)
67
- - Add the Stackdriver library as a dependency in `package.json`. By default, only the library code is published, meaning that the Stackdriver library needs to be installed separately.
package/build/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("stackdriver-errors-js")):"function"==typeof define&&define.amd?define(["stackdriver-errors-js"],r):"object"==typeof exports?exports.ApoliticalErrorReporting=r(require("stackdriver-errors-js")):e.ApoliticalErrorReporting=r(e["stackdriver-errors-js"])}(this,(function(e){return function(){"use strict";var r={800:function(r){r.exports=e}},t={};function o(e){var n=t[e];if(void 0!==n)return n.exports;var i=t[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,{a:r}),r},o.d=function(e,r){for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){o.r(n),o.d(n,{reportError:function(){return p},setContext:function(){return u}});var e=o(800),r=o.n(e);const{APOLITICAL:{WEBSITES:t},GCP:{ENVIRONMENTS:i,PROJECT_ID:c}}={APOLITICAL:{WEBSITES:{BETA:"https://beta.apolitical.co",LIVE:"https://apolitical.co",RC:"https://rc.apolitical.co"}},GCP:{ENVIRONMENTS:{BETA:"beta",RC:"rc",LIVE:"live"},PROJECT_ID:"hazel-tea-194609"}},a=e=>{let r;switch(e){case t.BETA:r=i.BETA;break;case t.LIVE:r=i.LIVE;break;case t.RC:r=i.RC;break;default:r=i.BETA}return r};let s={key:null,environment:a(),projectId:c};const u=({accessToken:e,environment:r,origin:t,projectId:o,serviceName:n,isEncodedToken:i=!0})=>{var u;s.key=i?(u=e)&&Buffer.from(u,"base64").toString("ascii"):e,s.environment=r||a(t),s.projectId=o||c,n&&(s.service=`${n}:${s.environment}`)},p=async(e,t)=>{try{const o=new(r());o.start(s),t&&o.setUser(t),await o.report(e)}catch(e){console.warn(`Cannot report error: ${e.message}`)}}}(),n}()}));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("stackdriver-errors-js")):"function"==typeof define&&define.amd?define(["stackdriver-errors-js"],r):"object"==typeof exports?exports.ApoliticalErrorReporting=r(require("stackdriver-errors-js")):e.ApoliticalErrorReporting=r(e["stackdriver-errors-js"])}(this,(function(e){return function(){"use strict";var r={542:function(r){r.exports=e}},t={};function o(e){var n=t[e];if(void 0!==n)return n.exports;var i=t[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,{a:r}),r},o.d=function(e,r){for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){o.r(n),o.d(n,{reportError:function(){return u},setContext:function(){return s}});var e=o(542),r=o.n(e);const{APOLITICAL:{WEBSITES:t},GCP:{ENVIRONMENTS:i,PROJECT_ID:c}}={APOLITICAL:{WEBSITES:{BETA:"https://beta.apolitical.co",BETA_2:"https://beta-2.apolitical.co",LIVE:"https://apolitical.co",RC:"https://rc.apolitical.co"}},GCP:{ENVIRONMENTS:{BETA:"beta",BETA_2:"beta-2",RC:"rc",LIVE:"live"},PROJECT_ID:"hazel-tea-194609"}};let a={key:null,environment:null,projectId:c};const s=({apiKey:e,environment:r,origin:o=null,projectId:n,serviceName:s})=>{a.key=e,a.environment=r||(e=>{let r=null,o=null;switch(o="undefined"!=typeof window?window.origin||window.location.origin:e,o){case t.BETA:r=i.BETA;break;case t.BETA_2:r=i.BETA_2;break;case t.LIVE:r=i.LIVE;break;case t.RC:r=i.RC;break;default:r=i.BETA}return r})(o),a.projectId=n||c,s&&(a.service=`${s}:${a.environment}`)},u=async(e,t)=>{try{const o=new(r());o.start(a),t&&o.setUser(t),await o.report(e)}catch(e){console.warn(`Cannot report error: ${e.message}`)}}}(),n}()}));
package/package.json CHANGED
@@ -1,71 +1,57 @@
1
1
  {
2
2
  "name": "@apolitical/error-reporting",
3
- "version": "0.0.1",
4
- "description": "Browser (and Node.js) library to report errors to GCP",
3
+ "version": "0.0.3-beta.3",
4
+ "description": "Browser library to report errors to GCP",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
- "contributors": [
7
- "Anouska Hopkins <anouska.hopkins@apolitical.co>",
8
- "Antonio Cordasco <antonio.cordasco@apolitical.co>",
9
- "Dorothy Yau <dorothy.yau@apolitical.co>",
10
- "Laura Hanna-White <laura.hanna-white@apolitical.co>",
11
- "Fatimat Gbajabiamila <fatimat.gbajabiamila@apolitical.co>",
12
- "Renzo Rozza <renzo.rozza@apolitical.co>",
13
- "Rihards Jukna <rihards.jukna@apolitical.co>"
14
- ],
15
6
  "license": "MIT",
16
7
  "main": "build/index.js",
8
+ "files": [
9
+ "build/**"
10
+ ],
17
11
  "scripts": {
18
12
  "test": "jest --runInBand",
13
+ "unit-test": "jest test/unit/* --bail --runInBand --passWithNoTests",
14
+ "integration-test": "jest test/integration/* --bail --runInBand --passWithNoTests",
19
15
  "build": "webpack --config webpack.config.js",
20
16
  "lint": "eslint --ext .js ./lib",
21
- "format": "prettier --write 'lib/**/*.+(js|json)'"
17
+ "format": "prettier --write 'lib/**/*.+(js|json)'",
18
+ "lint-format": "lint-staged",
19
+ "prepare": "husky install"
22
20
  },
23
21
  "keywords": [
24
22
  "JavaScript",
25
- "Library",
23
+ "Browser",
26
24
  "Error Reporting"
27
25
  ],
28
26
  "dependencies": {
29
- "stackdriver-errors-js": "0.8.0"
27
+ "stackdriver-errors-js": "0.12.0"
30
28
  },
31
29
  "peerDependencies": {
32
- "stackdriver-errors-js": "0.8.0"
30
+ "stackdriver-errors-js": "0.12.0"
33
31
  },
34
32
  "devDependencies": {
35
- "@babel/core": "7.14.5",
36
- "babel-eslint": "10.1.0",
37
- "babel-loader": "8.2.2",
38
- "babel-preset-react-app": "10.0.0",
39
- "eslint": "7.22.0",
40
- "eslint-config-prettier": "8.1.0",
41
- "eslint-plugin-jest": "24.3.2",
42
- "eslint-plugin-prettier": "3.3.1",
43
- "husky": "4.3.8",
44
- "jest": "27.0.4",
45
- "lint-staged": "11.0.0",
46
- "prettier": "2.3.1",
47
- "webpack": "5.38.1",
48
- "webpack-cli": "4.7.2"
33
+ "@apolitical/eslint-config": "1.0.2-beta.1",
34
+ "@babel/core": "7.16.12",
35
+ "@babel/eslint-parser": "7.16.5",
36
+ "@babel/plugin-transform-runtime": "7.16.10",
37
+ "@babel/preset-env": "7.16.11",
38
+ "husky": "7.0.4",
39
+ "jest": "27.4.7",
40
+ "jest-junit": "13.0.0",
41
+ "lint-staged": "12.3.2",
42
+ "webpack": "5.67.0",
43
+ "webpack-cli": "4.9.2"
49
44
  },
50
45
  "eslintConfig": {
51
46
  "extends": [
52
- "eslint:recommended",
53
- "plugin:prettier/recommended",
54
- "plugin:jest/recommended"
47
+ "@apolitical/eslint-config/base.config"
55
48
  ],
56
49
  "env": {
57
- "node": true,
58
- "es6": true,
59
- "jest": true
50
+ "browser": true
60
51
  },
61
- "plugins": [
62
- "jest"
63
- ],
64
- "parser": "babel-eslint"
65
- },
66
- "prettier": {
67
- "singleQuote": true
52
+ "parser": "@babel/eslint-parser"
68
53
  },
54
+ "prettier": "@apolitical/eslint-config/prettier.config",
69
55
  "browserslist": {
70
56
  "production": [
71
57
  ">0.2%",
@@ -83,23 +69,33 @@
83
69
  ],
84
70
  "coveragePathIgnorePatterns": [
85
71
  "<rootDir>/node_modules/"
86
- ]
72
+ ],
73
+ "setupFiles": [
74
+ "./test/setupTests.js"
75
+ ],
76
+ "reporters": [
77
+ "default",
78
+ "jest-junit"
79
+ ],
80
+ "testResultsProcessor": "jest-junit"
87
81
  },
88
82
  "babel": {
89
83
  "presets": [
90
- "react-app"
91
- ]
84
+ "@babel/preset-env"
85
+ ],
86
+ "env": {
87
+ "test": {
88
+ "plugins": [
89
+ "@babel/plugin-transform-runtime"
90
+ ]
91
+ }
92
+ }
92
93
  },
93
94
  "engines": {
94
- "node": ">=12.20.1"
95
- },
96
- "husky": {
97
- "hooks": {
98
- "pre-commit": "lint-staged && yarn build && yarn test"
99
- }
95
+ "node": ">=16.13.0"
100
96
  },
101
97
  "lint-staged": {
102
- "*.js": "eslint --cache --fix",
103
- "*.+(js|json)": "prettier --write"
98
+ "*.js": "eslint --cache --fix --ignore-path .gitignore",
99
+ "*.+(js|json)": "prettier --write --ignore-path .gitignore"
104
100
  }
105
101
  }
package/.gitlab-ci.yml DELETED
@@ -1,81 +0,0 @@
1
- default:
2
- image: node:12.20.1-alpine3.11
3
-
4
- # Pipeline stages
5
- stages:
6
- - cache
7
- - test
8
- - build
9
- - publish
10
-
11
- # Cache jobs
12
-
13
- fill-cache:
14
- stage: cache
15
- only:
16
- changes:
17
- - yarn.lock
18
- cache:
19
- key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
20
- paths:
21
- - node_modules/
22
- - .yarn
23
- script:
24
- - yarn install --cache-folder .yarn --production=false
25
-
26
- # Test jobs
27
-
28
- .use-cache:
29
- cache:
30
- key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
31
- paths:
32
- - node_modules/
33
- - .yarn
34
- policy: pull
35
-
36
- .lib-image:
37
- extends: .use-cache
38
- cache:
39
- key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
40
- paths:
41
- - node_modules/
42
- before_script:
43
- - yarn install --cache-folder .yarn --production=false
44
-
45
- outdated:
46
- extends: .lib-image
47
- stage: test
48
- allow_failure: true
49
- script:
50
- - yarn outdated
51
-
52
- test:
53
- extends: .lib-image
54
- stage: test
55
- allow_failure: false
56
- script:
57
- - yarn test
58
-
59
- # Build jobs
60
-
61
- build:
62
- extends: .lib-image
63
- stage: build
64
- allow_failure: false
65
- script:
66
- - yarn build
67
-
68
- # Publish jobs
69
-
70
- publish-module:
71
- extends: .lib-image
72
- stage: publish
73
- allow_failure: false
74
- only:
75
- - tags
76
- - /^v\d+\.\d+\.\d+$/
77
- before_script:
78
- - yarn build
79
- script:
80
- - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc
81
- - yarn publish --access=public
package/default.env DELETED
@@ -1 +0,0 @@
1
- CONTENTFUL_CDA_TOKEN=cda-token-base64-encoded
package/lib/config.js DELETED
@@ -1,19 +0,0 @@
1
- const config = {
2
- APOLITICAL: {
3
- WEBSITES: {
4
- BETA: 'https://beta.apolitical.co',
5
- LIVE: 'https://apolitical.co',
6
- RC: 'https://rc.apolitical.co',
7
- },
8
- },
9
- GCP: {
10
- ENVIRONMENTS: {
11
- BETA: 'beta',
12
- RC: 'rc',
13
- LIVE: 'live',
14
- },
15
- PROJECT_ID: 'hazel-tea-194609',
16
- },
17
- };
18
-
19
- export default config;
@@ -1,51 +0,0 @@
1
- import config from '../config';
2
-
3
- const {
4
- APOLITICAL: { WEBSITES },
5
- GCP: { ENVIRONMENTS, PROJECT_ID },
6
- } = config;
7
-
8
- const decodeBase64 = (value) =>
9
- value && Buffer.from(value, 'base64').toString('ascii');
10
-
11
- const getEnvironment = (origin) => {
12
- let environment;
13
- switch (origin) {
14
- case WEBSITES.BETA:
15
- environment = ENVIRONMENTS.BETA;
16
- break;
17
- case WEBSITES.LIVE:
18
- environment = ENVIRONMENTS.LIVE;
19
- break;
20
- case WEBSITES.RC:
21
- environment = ENVIRONMENTS.RC;
22
- break;
23
- default:
24
- environment = ENVIRONMENTS.BETA;
25
- }
26
- return environment;
27
- };
28
-
29
- let context = {
30
- key: null,
31
- environment: getEnvironment(),
32
- projectId: PROJECT_ID,
33
- };
34
-
35
- export const setContext = ({
36
- accessToken,
37
- environment,
38
- origin,
39
- projectId,
40
- serviceName,
41
- isEncodedToken = true,
42
- }) => {
43
- context.key = isEncodedToken ? decodeBase64(accessToken) : accessToken;
44
- context.environment = environment || getEnvironment(origin);
45
- context.projectId = projectId || PROJECT_ID;
46
- if (serviceName) {
47
- context.service = `${serviceName}:${context.environment}`;
48
- }
49
- };
50
-
51
- export const getContext = () => context;
@@ -1 +0,0 @@
1
- export { getContext, setContext } from './context';
package/lib/index.js DELETED
@@ -1,21 +0,0 @@
1
- import StackdriverErrorReporter from 'stackdriver-errors-js';
2
-
3
- import { getContext } from './helpers';
4
-
5
- export const reportError = async (error, userId) => {
6
- try {
7
- // Create error handler
8
- const errorHandler = new StackdriverErrorReporter();
9
- errorHandler.start(getContext());
10
- if (userId) {
11
- errorHandler.setUser(userId);
12
- }
13
- // Report error to GCP
14
- await errorHandler.report(error);
15
- } catch (err) {
16
- // Something went wrong
17
- console.warn(`Cannot report error: ${err.message}`);
18
- }
19
- };
20
-
21
- export { setContext } from './helpers';
@@ -1,10 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Apolitical Error Reporting Report Error should use context 1`] = `
4
- Object {
5
- "environment": "live",
6
- "key": "some-key",
7
- "projectId": "hazel-tea-194609",
8
- "service": "some-service:live",
9
- }
10
- `;
@@ -1,70 +0,0 @@
1
- const mockStart = jest.fn();
2
- const mockSetUser = jest.fn();
3
- const mockReport = jest.fn();
4
-
5
- jest.mock('stackdriver-errors-js', () => {
6
- class StackdriverErrorReporter {
7
- constructor() {
8
- this.start = mockStart;
9
- this.setUser = mockSetUser;
10
- this.report = mockReport;
11
- }
12
- }
13
- return StackdriverErrorReporter;
14
- });
15
-
16
- jest.mock('stackdriver-errors-js');
17
-
18
- import { setContext, reportError } from '../../lib';
19
-
20
- describe('Apolitical Error Reporting', () => {
21
- beforeAll(() => {
22
- setContext({
23
- accessToken: 'c29tZS1rZXk=',
24
- serviceName: 'some-service',
25
- origin: 'https://apolitical.co',
26
- });
27
- });
28
-
29
- describe('Report Error', () => {
30
- test('should report error', async () => {
31
- await reportError(new Error('Something went wrong'));
32
- expect(mockReport).toHaveBeenCalledTimes(1);
33
- });
34
-
35
- test('should use context', async () => {
36
- await reportError(new Error('Something went wrong'));
37
- expect(mockStart).toHaveBeenCalledTimes(1);
38
- expect(mockStart.mock.calls[0][0]).toMatchSnapshot();
39
- });
40
-
41
- test('should set user', async () => {
42
- await reportError(new Error('Something went wrong'), 'some-user');
43
- expect(mockSetUser).toHaveBeenCalledTimes(1);
44
- expect(mockSetUser.mock.calls[0][0]).toEqual('some-user');
45
- });
46
-
47
- describe('Error handling', () => {
48
- const { warn } = console;
49
- const mockWarn = jest.fn();
50
-
51
- beforeAll(() => {
52
- delete console.warn;
53
- console.warn = mockWarn;
54
- });
55
-
56
- afterAll(() => {
57
- console.warn = warn;
58
- });
59
-
60
- test('should catch error', async () => {
61
- mockReport.mockRejectedValueOnce(new Error('Some other error'));
62
- await reportError(new Error('Something went wrong'), 'some-user');
63
- expect(mockWarn).toHaveBeenCalledTimes(1);
64
- expect(mockWarn.mock.calls[0][0]).toEqual(
65
- 'Cannot report error: Some other error'
66
- );
67
- });
68
- });
69
- });
70
- });
package/webpack.config.js DELETED
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- module.exports = {
6
- mode: 'production',
7
- entry: {
8
- index: path.resolve(__dirname, 'lib', 'index.js'),
9
- },
10
- output: {
11
- path: path.resolve(__dirname, 'build'),
12
- filename: 'index.js',
13
- library: {
14
- name: 'ApoliticalErrorReporting',
15
- type: 'umd',
16
- },
17
- globalObject: 'this',
18
- },
19
- externals: {
20
- ['stackdriver-errors-js']: 'stackdriver-errors-js',
21
- },
22
- optimization: {
23
- splitChunks: {
24
- chunks: 'all',
25
- },
26
- minimize: true,
27
- },
28
- };