@strapi/plugin-sentry 4.16.2 → 4.18.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.
Files changed (115) hide show
  1. package/dist/_chunks/{dk-00b47489.js → dk-ACiZv75I.js} +1 -1
  2. package/dist/_chunks/dk-ACiZv75I.js.map +1 -0
  3. package/dist/_chunks/{dk-b05451b4.mjs → dk-Ht5BJvwV.mjs} +1 -1
  4. package/dist/_chunks/dk-Ht5BJvwV.mjs.map +1 -0
  5. package/dist/_chunks/{en-70258e03.mjs → en--hlKpBzk.mjs} +1 -1
  6. package/dist/_chunks/en--hlKpBzk.mjs.map +1 -0
  7. package/dist/_chunks/{en-2dbaca4a.js → en-vyox7ZSC.js} +1 -1
  8. package/dist/_chunks/en-vyox7ZSC.js.map +1 -0
  9. package/dist/_chunks/{es-0812c06d.mjs → es-21jfFVzQ.mjs} +1 -1
  10. package/dist/_chunks/es-21jfFVzQ.mjs.map +1 -0
  11. package/dist/_chunks/{es-4352c0b3.js → es-tPYrS3N2.js} +1 -1
  12. package/dist/_chunks/es-tPYrS3N2.js.map +1 -0
  13. package/dist/_chunks/{fr-81925960.js → fr-2usi50FD.js} +1 -1
  14. package/dist/_chunks/fr-2usi50FD.js.map +1 -0
  15. package/dist/_chunks/{fr-22b3a920.mjs → fr-8muIKZms.mjs} +1 -1
  16. package/dist/_chunks/fr-8muIKZms.mjs.map +1 -0
  17. package/dist/_chunks/{ko-f357ad11.mjs → ko-NdEnkB5D.mjs} +1 -1
  18. package/dist/_chunks/ko-NdEnkB5D.mjs.map +1 -0
  19. package/dist/_chunks/{ko-5ab994e9.js → ko-nuQP7I5M.js} +1 -1
  20. package/dist/_chunks/ko-nuQP7I5M.js.map +1 -0
  21. package/dist/_chunks/{pl-91ad3b57.mjs → pl-5DTLh5PW.mjs} +1 -1
  22. package/dist/_chunks/pl-5DTLh5PW.mjs.map +1 -0
  23. package/dist/_chunks/{pl-5065555b.js → pl-cdsG7ySn.js} +1 -1
  24. package/dist/_chunks/pl-cdsG7ySn.js.map +1 -0
  25. package/dist/_chunks/{ru-c00f24a0.js → ru-KtwsGCNm.js} +1 -1
  26. package/dist/_chunks/ru-KtwsGCNm.js.map +1 -0
  27. package/dist/_chunks/{ru-ea18416d.mjs → ru-_BJx1_V5.mjs} +1 -1
  28. package/dist/_chunks/ru-_BJx1_V5.mjs.map +1 -0
  29. package/dist/_chunks/{sv-a8d028fb.js → sv-QDPLOKcT.js} +1 -1
  30. package/dist/_chunks/sv-QDPLOKcT.js.map +1 -0
  31. package/dist/_chunks/{sv-8f50eca3.mjs → sv-YocrQXH3.mjs} +1 -1
  32. package/dist/_chunks/sv-YocrQXH3.mjs.map +1 -0
  33. package/dist/_chunks/{tr-de905f5b.js → tr-W6PupknE.js} +1 -1
  34. package/dist/_chunks/tr-W6PupknE.js.map +1 -0
  35. package/dist/_chunks/{tr-dca6c197.mjs → tr-nkbjyt2S.mjs} +1 -1
  36. package/dist/_chunks/tr-nkbjyt2S.mjs.map +1 -0
  37. package/dist/_chunks/{vi-22d50e0e.mjs → vi-10CsgDK2.mjs} +1 -1
  38. package/dist/_chunks/vi-10CsgDK2.mjs.map +1 -0
  39. package/dist/_chunks/{vi-6d3d2db0.js → vi-hEp1hNio.js} +1 -1
  40. package/dist/_chunks/vi-hEp1hNio.js.map +1 -0
  41. package/dist/_chunks/{zh-9ec5b9b1.mjs → zh-WWNi5hqs.mjs} +1 -1
  42. package/dist/_chunks/zh-WWNi5hqs.mjs.map +1 -0
  43. package/dist/_chunks/{zh-ac6dac24.js → zh-uRG2X3qF.js} +1 -1
  44. package/dist/_chunks/zh-uRG2X3qF.js.map +1 -0
  45. package/dist/admin/index.js +23 -18
  46. package/dist/admin/index.js.map +1 -1
  47. package/dist/admin/index.mjs +23 -18
  48. package/dist/admin/index.mjs.map +1 -1
  49. package/dist/admin/src/index.d.ts +16 -0
  50. package/dist/admin/src/pluginId.d.ts +1 -0
  51. package/dist/server/index.js +124 -0
  52. package/dist/server/index.js.map +1 -0
  53. package/dist/server/index.mjs +106 -0
  54. package/dist/server/index.mjs.map +1 -0
  55. package/dist/server/src/bootstrap.d.ts +6 -0
  56. package/dist/server/src/bootstrap.d.ts.map +1 -0
  57. package/dist/server/src/config.d.ts +16 -0
  58. package/dist/server/src/config.d.ts.map +1 -0
  59. package/dist/server/src/index.d.ts +24 -0
  60. package/dist/server/src/index.d.ts.map +1 -0
  61. package/dist/server/src/middlewares/sentry.d.ts +9 -0
  62. package/dist/server/src/middlewares/sentry.d.ts.map +1 -0
  63. package/dist/server/src/services/index.d.ts +11 -0
  64. package/dist/server/src/services/index.d.ts.map +1 -0
  65. package/dist/server/src/services/sentry.d.ts +20 -0
  66. package/dist/server/src/services/sentry.d.ts.map +1 -0
  67. package/package.json +20 -14
  68. package/strapi-server.js +1 -1
  69. package/.eslintignore +0 -1
  70. package/.eslintrc +0 -14
  71. package/.gitattributes +0 -103
  72. package/admin/src/index.js +0 -38
  73. package/admin/src/pluginId.js +0 -5
  74. package/admin/src/translations/dk.json +0 -5
  75. package/admin/src/translations/en.json +0 -5
  76. package/admin/src/translations/es.json +0 -5
  77. package/admin/src/translations/fr.json +0 -5
  78. package/admin/src/translations/ko.json +0 -5
  79. package/admin/src/translations/pl.json +0 -5
  80. package/admin/src/translations/ru.json +0 -5
  81. package/admin/src/translations/sv.json +0 -5
  82. package/admin/src/translations/tr.json +0 -5
  83. package/admin/src/translations/vi.json +0 -5
  84. package/admin/src/translations/zh.json +0 -6
  85. package/dist/_chunks/dk-00b47489.js.map +0 -1
  86. package/dist/_chunks/dk-b05451b4.mjs.map +0 -1
  87. package/dist/_chunks/en-2dbaca4a.js.map +0 -1
  88. package/dist/_chunks/en-70258e03.mjs.map +0 -1
  89. package/dist/_chunks/es-0812c06d.mjs.map +0 -1
  90. package/dist/_chunks/es-4352c0b3.js.map +0 -1
  91. package/dist/_chunks/fr-22b3a920.mjs.map +0 -1
  92. package/dist/_chunks/fr-81925960.js.map +0 -1
  93. package/dist/_chunks/ko-5ab994e9.js.map +0 -1
  94. package/dist/_chunks/ko-f357ad11.mjs.map +0 -1
  95. package/dist/_chunks/pl-5065555b.js.map +0 -1
  96. package/dist/_chunks/pl-91ad3b57.mjs.map +0 -1
  97. package/dist/_chunks/ru-c00f24a0.js.map +0 -1
  98. package/dist/_chunks/ru-ea18416d.mjs.map +0 -1
  99. package/dist/_chunks/sv-8f50eca3.mjs.map +0 -1
  100. package/dist/_chunks/sv-a8d028fb.js.map +0 -1
  101. package/dist/_chunks/tr-dca6c197.mjs.map +0 -1
  102. package/dist/_chunks/tr-de905f5b.js.map +0 -1
  103. package/dist/_chunks/vi-22d50e0e.mjs.map +0 -1
  104. package/dist/_chunks/vi-6d3d2db0.js.map +0 -1
  105. package/dist/_chunks/zh-9ec5b9b1.mjs.map +0 -1
  106. package/dist/_chunks/zh-ac6dac24.js.map +0 -1
  107. package/jest.config.js +0 -6
  108. package/packup.config.ts +0 -42
  109. package/server/bootstrap.js +0 -8
  110. package/server/config.js +0 -10
  111. package/server/index.js +0 -11
  112. package/server/middlewares/sentry.js +0 -40
  113. package/server/services/__tests__/sentry.test.js +0 -102
  114. package/server/services/index.js +0 -7
  115. package/server/services/sentry/index.js +0 -85
@@ -1 +0,0 @@
1
- {"version":3,"file":"vi-22d50e0e.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"vi-6d3d2db0.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"zh-9ec5b9b1.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"zh-ac6dac24.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- preset: '../../../jest-preset.unit.js',
5
- displayName: 'Sentry plugin',
6
- };
package/packup.config.ts DELETED
@@ -1,42 +0,0 @@
1
- import { Config, defineConfig } from '@strapi/pack-up';
2
- import { transformWithEsbuild } from 'vite';
3
-
4
- const config: Config = defineConfig({
5
- bundles: [
6
- {
7
- source: './admin/src/index.js',
8
- import: './dist/admin/index.mjs',
9
- require: './dist/admin/index.js',
10
- runtime: 'web',
11
- },
12
- ],
13
- dist: './dist',
14
- /**
15
- * Because we're exporting a server & client package
16
- * which have different runtimes we want to ignore
17
- * what they look like in the package.json
18
- */
19
- exports: {},
20
- plugins: [
21
- {
22
- name: 'treat-js-files-as-jsx',
23
- async transform(code, id) {
24
- /**
25
- * Matches all files in src/ and ee/ that end with .js
26
- */
27
- if (!id.match(/src\/.*\.js$/) && !id.match(/ee\/.*\.js$/)) {
28
- return null;
29
- }
30
-
31
- // Use the exposed transform from vite, instead of directly
32
- // transforming with esbuild
33
- return transformWithEsbuild(code, id, {
34
- loader: 'tsx',
35
- jsx: 'automatic',
36
- });
37
- },
38
- },
39
- ],
40
- });
41
-
42
- export default config;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- const initSentryMiddleware = require('./middlewares/sentry');
4
-
5
- module.exports = async ({ strapi }) => {
6
- // Initialize the Sentry service exposed by this plugin
7
- initSentryMiddleware({ strapi });
8
- };
package/server/config.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- default: {
5
- dsn: null,
6
- sendMetadata: true,
7
- init: {},
8
- },
9
- validator() {},
10
- };
package/server/index.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- const bootstrap = require('./bootstrap');
4
- const services = require('./services');
5
- const config = require('./config');
6
-
7
- module.exports = () => ({
8
- bootstrap,
9
- config,
10
- services,
11
- });
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Programmatic sentry middleware. We do not want to expose it in the plugin
5
- * @param {{ strapi: import('@strapi/strapi').Strapi }}
6
- */
7
- module.exports = ({ strapi }) => {
8
- const sentryService = strapi.plugin('sentry').service('sentry');
9
- sentryService.init();
10
- const sentry = sentryService.getInstance();
11
-
12
- if (!sentry) {
13
- // initialization failed
14
- return;
15
- }
16
-
17
- strapi.server.use(async (ctx, next) => {
18
- try {
19
- await next();
20
- } catch (error) {
21
- sentryService.sendError(error, (scope, sentryInstance) => {
22
- scope.addEventProcessor((event) => {
23
- // Parse Koa context to add error metadata
24
- return sentryInstance.Handlers.parseRequest(event, ctx.request, {
25
- // Don't parse the transaction name, we'll do it manually
26
- transaction: false,
27
- });
28
- });
29
-
30
- // Manually add transaction name
31
- scope.setTag('transaction', `${ctx.method} ${ctx._matchedRoute}`);
32
- // Manually add Strapi version
33
- scope.setTag('strapi_version', strapi.config.info.strapi);
34
- scope.setTag('method', ctx.method);
35
- });
36
-
37
- throw error;
38
- }
39
- });
40
- };
@@ -1,102 +0,0 @@
1
- 'use strict';
2
-
3
- const INVALID_DSN = 'an_invalid_dsn';
4
- const VALID_DSN = 'a_valid_dsn';
5
- const mockCaptureException = jest.fn();
6
-
7
- // FIXME
8
- /* eslint-disable import/extensions */
9
- jest.mock('@sentry/node', () => {
10
- return {
11
- init(options = {}) {
12
- if (options.dsn !== VALID_DSN) {
13
- throw Error();
14
- }
15
- },
16
- captureException: mockCaptureException,
17
- withScope(configureScope) {
18
- configureScope();
19
- },
20
- };
21
- });
22
-
23
- const sentryServiceLoader = require('../sentry');
24
- const defaultConfig = require('../../config').default;
25
-
26
- describe('Sentry service', () => {
27
- beforeEach(() => {
28
- // Reset Strapi state
29
- global.strapi = {
30
- config: {
31
- get: () => defaultConfig,
32
- },
33
- log: {
34
- warn: jest.fn(),
35
- info: jest.fn(),
36
- },
37
- };
38
- });
39
-
40
- afterEach(() => {
41
- // Reset the plugin resource state
42
- jest.resetModules();
43
- });
44
-
45
- it('disables Sentry when no DSN is provided', () => {
46
- const sentryService = sentryServiceLoader({ strapi });
47
- sentryService.init();
48
- expect(strapi.log.info).toHaveBeenCalledWith(expect.stringMatching(/disabled/i));
49
-
50
- const instance = sentryService.getInstance();
51
- expect(instance).toBeNull();
52
- });
53
-
54
- it('disables Sentry when an invalid DSN is provided', () => {
55
- global.strapi.config.get = () => ({ dsn: INVALID_DSN });
56
- const sentryService = sentryServiceLoader({ strapi });
57
- sentryService.init();
58
- expect(strapi.log.warn).toHaveBeenCalledWith(expect.stringMatching(/could not set up sentry/i));
59
-
60
- const instance = sentryService.getInstance();
61
- expect(instance).toBeNull();
62
- });
63
-
64
- it("doesn't send events before init", () => {
65
- const sentryService = sentryServiceLoader({ strapi });
66
- sentryService.sendError(Error());
67
- expect(strapi.log.warn).toHaveBeenCalledWith(expect.stringMatching(/cannot send event/i));
68
- });
69
-
70
- it('initializes and sends errors', () => {
71
- global.strapi.config.get = () => ({ dsn: VALID_DSN, sendMetadata: true });
72
- const sentryService = sentryServiceLoader({ strapi });
73
- sentryService.init();
74
-
75
- // Saves the instance correctly
76
- const instance = sentryService.getInstance();
77
- expect(instance).not.toBeNull();
78
-
79
- // Doesn't allow re-init
80
- sentryService.init();
81
-
82
- // Send error
83
- const error = Error('an error');
84
- const configureScope = jest.fn();
85
- sentryService.sendError(error, configureScope);
86
- expect(configureScope).toHaveBeenCalled();
87
- expect(mockCaptureException).toHaveBeenCalled();
88
- });
89
-
90
- it('does not not send metadata when the option is disabled', () => {
91
- // Init with metadata option disabled
92
- global.strapi.config.get = () => ({ dsn: VALID_DSN, sendMetadata: false });
93
- const sentryService = sentryServiceLoader({ strapi });
94
- sentryService.init();
95
-
96
- // Send error
97
- const error = Error('an error');
98
- const configureScope = jest.fn();
99
- sentryService.sendError(error, configureScope);
100
- expect(configureScope).not.toHaveBeenCalled();
101
- });
102
- });
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- const sentry = require('./sentry');
4
-
5
- module.exports = {
6
- sentry,
7
- };
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- // FIXME
4
- /* eslint-disable import/extensions */
5
- const Sentry = require('@sentry/node');
6
-
7
- const createSentryService = (strapi) => {
8
- let isReady = false;
9
- let instance = null;
10
- let settings = {};
11
-
12
- return {
13
- /**
14
- * Initialize Sentry service
15
- */
16
- init() {
17
- // Make sure there isn't a Sentry instance already running
18
- if (instance !== null) {
19
- return this;
20
- }
21
-
22
- // Retrieve user settings and merge them with the default ones
23
- settings = strapi.config.get('plugin.sentry');
24
-
25
- try {
26
- // Don't init Sentry if no DSN was provided
27
- if (settings.dsn) {
28
- Sentry.init({
29
- dsn: settings.dsn,
30
- environment: strapi.config.get('environment'),
31
- ...settings.init,
32
- });
33
- // Store the successfully initialized Sentry instance
34
- instance = Sentry;
35
- isReady = true;
36
- } else {
37
- strapi.log.info('@strapi/plugin-sentry is disabled because no Sentry DSN was provided');
38
- }
39
- } catch (error) {
40
- strapi.log.warn('Could not set up Sentry, make sure you entered a valid DSN');
41
- }
42
-
43
- return this;
44
- },
45
-
46
- /**
47
- * Expose Sentry instance through a getter
48
- * @returns {Sentry}
49
- */
50
- getInstance() {
51
- return instance;
52
- },
53
-
54
- /**
55
- * Callback to [configure an instance of Sentry's scope]{@link https://docs.sentry.io/platforms/node/enriching-events/scopes/#configuring-the-scope}
56
- * @callback configureScope
57
- * @param {Sentry.scope} scope
58
- * @param {Sentry=} instance An initialized Sentry instance
59
- */
60
-
61
- /**
62
- * Higher level method to send exception events to Sentry
63
- * @param {Error} error An error object
64
- * @param {configureScope=} configureScope
65
- */
66
- sendError(error, configureScope) {
67
- // Make sure Sentry is ready
68
- if (!isReady) {
69
- strapi.log.warn("Sentry wasn't properly initialized, cannot send event");
70
- return;
71
- }
72
-
73
- instance.withScope((scope) => {
74
- // Configure the Sentry scope using the provided callback
75
- if (configureScope && settings.sendMetadata) {
76
- configureScope(scope, instance);
77
- }
78
- // Actually send the Error to Sentry
79
- instance.captureException(error);
80
- });
81
- },
82
- };
83
- };
84
-
85
- module.exports = ({ strapi }) => createSentryService(strapi);