@payloadcms/plugin-sentry 0.0.1
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/LICENSE.md +22 -0
- package/README.md +122 -0
- package/dist/captureException.d.ts +1 -0
- package/dist/captureException.js +32 -0
- package/dist/captureException.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/mocks/mockFile.d.ts +2 -0
- package/dist/mocks/mockFile.js +6 -0
- package/dist/mocks/mockFile.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.js +86 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.spec.d.ts +1 -0
- package/dist/plugin.spec.js +53 -0
- package/dist/plugin.spec.js.map +1 -0
- package/dist/startSentry.d.ts +3 -0
- package/dist/startSentry.js +86 -0
- package/dist/startSentry.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +32 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +67 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2023 Payload CMS, LLC <info@payloadcms.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
🚧 **WAIT! This repo is in the process of being built and not been tested for production use yet.**
|
|
2
|
+
|
|
3
|
+
# Sentry Plugin for Payload
|
|
4
|
+
|
|
5
|
+
This plugin seamlessly integrates [Sentry](https://sentry.io/) with [Payload](https://github.com/payloadcms/payload) for performance monitoring and error tracking.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add @payloadcms/plugin-sentry
|
|
11
|
+
# OR
|
|
12
|
+
npm i @payloadcms/plugin-sentry
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Basic Usage
|
|
16
|
+
|
|
17
|
+
1. Import `sentry` from `'@payloadcms/plugin-sentry'`
|
|
18
|
+
2. Add it to the `plugins` array of your [Payload config](https://payloadcms.com/docs/configuration/overview)
|
|
19
|
+
3. Pass in your Data Source Name (DSN)
|
|
20
|
+
4. Pass [additional options](#additional-options) - *not required*
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { buildConfig } from 'payload/config';
|
|
24
|
+
import sentry from '@payloadcms/plugin-sentry';
|
|
25
|
+
import { Pages, Media } from './collections';
|
|
26
|
+
|
|
27
|
+
const config = buildConfig({
|
|
28
|
+
collections: [Pages, Media],
|
|
29
|
+
plugins: [
|
|
30
|
+
sentry({
|
|
31
|
+
dsn: 'https://61edebas777889984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
|
|
32
|
+
}),
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export default config;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
### Data Source Name (DSN) and where to find it
|
|
42
|
+
|
|
43
|
+
- `dsn` : string | required
|
|
44
|
+
|
|
45
|
+
Sentry automatically assigns a DSN when you create a project, the unique DSN informs Sentry where to send events so they are associated with the correct project.
|
|
46
|
+
|
|
47
|
+
#### :rotating_light: You can find the DSN in your project settings by navigating to [Project] > Settings > Client Keys (DSN) in [sentry.io](sentry.io).
|
|
48
|
+
|
|
49
|
+
### Additional Options
|
|
50
|
+
|
|
51
|
+
- `enabled`: boolean | optional
|
|
52
|
+
|
|
53
|
+
Set to false to disable the plugin. Defaults to true.
|
|
54
|
+
|
|
55
|
+
- `init` : ClientOptions | optional
|
|
56
|
+
|
|
57
|
+
Sentry allows a variety of options to be passed into the Sentry.init() function, see the full list of options [here](https://docs.sentry.io/platforms/node/guides/express/configuration/options).
|
|
58
|
+
|
|
59
|
+
- `requestHandler` : RequestHandlerOptions | optional
|
|
60
|
+
|
|
61
|
+
Accepts options that let you decide what data should be included in the event sent to Sentry, checkout the options [here](https://docs.sentry.io/platforms/node/guides/express/configuration/options).
|
|
62
|
+
|
|
63
|
+
- `captureErrors`: number[] | optional
|
|
64
|
+
|
|
65
|
+
By default, `Sentry.errorHandler` will capture only errors with a status code of 500 or higher. To capture additional error codes, pass the values as numbers in an array.
|
|
66
|
+
|
|
67
|
+
You can configure any of these options by passing them to the plugin under options:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { buildConfig } from 'payload/config';
|
|
71
|
+
import seo from '@payloadcms/plugin-sentry';
|
|
72
|
+
import { Pages, Media } from './collections';
|
|
73
|
+
|
|
74
|
+
const config = buildConfig({
|
|
75
|
+
collections: [Pages, Media],
|
|
76
|
+
plugins: [
|
|
77
|
+
sentry({
|
|
78
|
+
dsn: 'https://61edebas777889984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
|
|
79
|
+
options: {
|
|
80
|
+
init: {
|
|
81
|
+
debug: true,
|
|
82
|
+
environment: 'development',
|
|
83
|
+
tracesSampleRate: 1.0,
|
|
84
|
+
},
|
|
85
|
+
requestHandler: {
|
|
86
|
+
serverName: false,
|
|
87
|
+
user: ["email"],
|
|
88
|
+
},
|
|
89
|
+
captureErrors: [400, 403, 404],
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export default config;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
To learn more about these options and when to use them, visit the [Sentry Docs](https://docs.sentry.io/platforms/node/guides/express/configuration/options).
|
|
99
|
+
|
|
100
|
+
## TypeScript
|
|
101
|
+
|
|
102
|
+
All types can be directly imported:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { PluginOptions } from '@payloadcms/plugin-sentry/types';
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
To actively develop or debug this plugin you can either work directly within the demo directory of this repo, or link your own project.
|
|
111
|
+
|
|
112
|
+
#### Internal Demo
|
|
113
|
+
|
|
114
|
+
This repo includes a demo of Payload that installs the plugin directly from the source code. This is the easiest way to get started. To spin up this demo, follow these steps:
|
|
115
|
+
|
|
116
|
+
1. First clone the repo
|
|
117
|
+
2. Then, `cd plugin-sentry && yarn && cd dev && yarn && yarn dev`
|
|
118
|
+
3. Now open `http://localhost:3000/admin` in your browser
|
|
119
|
+
4. Create a new user and sign in
|
|
120
|
+
5. Use the buttons to throw test errors
|
|
121
|
+
|
|
122
|
+
That's it! Changes made in `./src` will be reflected in the demo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const captureException: (err: Error) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.captureException = void 0;
|
|
27
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
28
|
+
var captureException = function (err) {
|
|
29
|
+
Sentry.captureException(err);
|
|
30
|
+
};
|
|
31
|
+
exports.captureException = captureException;
|
|
32
|
+
//# sourceMappingURL=captureException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureException.js","sourceRoot":"","sources":["../src/captureException.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAsC;AAE/B,IAAM,gBAAgB,GAAG,UAAC,GAAU;IACzC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sentry = void 0;
|
|
4
|
+
var plugin_1 = require("./plugin");
|
|
5
|
+
Object.defineProperty(exports, "sentry", { enumerable: true, get: function () { return plugin_1.sentry; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAAxB,gGAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockFile.js","sourceRoot":"","sources":["../../src/mocks/mockFile.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,WAAW,EAAE,cAAO,CAAC;IACrB,gBAAgB,EAAE,cAAO,CAAC;CAC3B,CAAA"}
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.sentry = void 0;
|
|
51
|
+
var captureException_1 = require("./captureException");
|
|
52
|
+
var startSentry_1 = require("./startSentry");
|
|
53
|
+
var webpack_1 = require("./webpack");
|
|
54
|
+
var sentry = function (pluginOptions) {
|
|
55
|
+
return function (incomingConfig) {
|
|
56
|
+
var config = __assign({}, incomingConfig);
|
|
57
|
+
var webpack = (0, webpack_1.extendWebpackConfig)(incomingConfig);
|
|
58
|
+
config.admin = __assign(__assign({}, (config.admin || {})), { webpack: webpack });
|
|
59
|
+
if (pluginOptions.enabled === false || !pluginOptions.dsn) {
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
config.hooks = __assign(__assign({}, (incomingConfig.hooks || {})), {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
+
afterError: function (err) {
|
|
65
|
+
(0, captureException_1.captureException)(err);
|
|
66
|
+
} });
|
|
67
|
+
config.onInit = function (payload) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!incomingConfig.onInit) return [3 /*break*/, 2];
|
|
72
|
+
return [4 /*yield*/, incomingConfig.onInit(payload)];
|
|
73
|
+
case 1:
|
|
74
|
+
_a.sent();
|
|
75
|
+
_a.label = 2;
|
|
76
|
+
case 2:
|
|
77
|
+
(0, startSentry_1.startSentry)(pluginOptions, payload);
|
|
78
|
+
return [2 /*return*/];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}); };
|
|
82
|
+
return config;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.sentry = sentry;
|
|
86
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,uDAAqD;AACrD,6CAA2C;AAE3C,qCAA+C;AAExC,IAAM,MAAM,GACjB,UAAC,aAA4B;IAC7B,OAAA,UAAC,cAAsB;QACrB,IAAI,MAAM,gBAAQ,cAAc,CAAE,CAAA;QAClC,IAAM,OAAO,GAAG,IAAA,6BAAmB,EAAC,cAAc,CAAC,CAAA;QAEnD,MAAM,CAAC,KAAK,yBACP,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,KACvB,OAAO,SAAA,GACR,CAAA;QAED,IAAI,aAAa,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;YACzD,OAAO,MAAM,CAAA;SACd;QAED,MAAM,CAAC,KAAK,yBACP,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC;YAC/B,8DAA8D;YAC9D,UAAU,EAAE,UAAC,GAAQ;gBACnB,IAAA,mCAAgB,EAAC,GAAG,CAAC,CAAA;YACvB,CAAC,GACF,CAAA;QAED,MAAM,CAAC,MAAM,GAAG,UAAM,OAAO;;;;6BACvB,cAAc,CAAC,MAAM,EAArB,wBAAqB;wBAAE,qBAAM,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;wBAApC,SAAoC,CAAA;;;wBAC/D,IAAA,yBAAW,EAAC,aAAa,EAAE,OAAO,CAAC,CAAA;;;;aACpC,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;AA3BD,CA2BC,CAAA;AA7BU,QAAA,MAAM,UA6BhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var defaults_1 = require("payload/dist/config/defaults");
|
|
15
|
+
var plugin_1 = require("./plugin");
|
|
16
|
+
describe('plugin', function () {
|
|
17
|
+
it('should run the plugin', function () {
|
|
18
|
+
var plugin = (0, plugin_1.sentry)({ enabled: true, dsn: 'asdf' });
|
|
19
|
+
var config = plugin(createConfig());
|
|
20
|
+
assertPluginRan(config);
|
|
21
|
+
});
|
|
22
|
+
it('should default enable: true', function () {
|
|
23
|
+
var plugin = (0, plugin_1.sentry)({ dsn: 'asdf' });
|
|
24
|
+
var config = plugin(createConfig());
|
|
25
|
+
assertPluginRan(config);
|
|
26
|
+
});
|
|
27
|
+
it('should not run if dsn is not provided', function () {
|
|
28
|
+
var plugin = (0, plugin_1.sentry)({ enabled: true, dsn: null });
|
|
29
|
+
var config = plugin(createConfig());
|
|
30
|
+
assertPluginDidNotRun(config);
|
|
31
|
+
});
|
|
32
|
+
it('should respect enabled: false', function () {
|
|
33
|
+
var plugin = (0, plugin_1.sentry)({ enabled: false, dsn: null });
|
|
34
|
+
var config = plugin(createConfig());
|
|
35
|
+
assertPluginDidNotRun(config);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
function assertPluginRan(config) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
expect((_a = config.admin) === null || _a === void 0 ? void 0 : _a.webpack).toBeDefined();
|
|
41
|
+
expect((_b = config.hooks) === null || _b === void 0 ? void 0 : _b.afterError).toBeDefined();
|
|
42
|
+
expect(config.onInit).toBeDefined();
|
|
43
|
+
}
|
|
44
|
+
function assertPluginDidNotRun(config) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
expect((_a = config.admin) === null || _a === void 0 ? void 0 : _a.webpack).toBeDefined();
|
|
47
|
+
expect((_b = config.hooks) === null || _b === void 0 ? void 0 : _b.afterError).toBeUndefined();
|
|
48
|
+
expect(config.onInit).toBeUndefined();
|
|
49
|
+
}
|
|
50
|
+
function createConfig(overrides) {
|
|
51
|
+
return __assign(__assign({}, defaults_1.defaults), overrides);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=plugin.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.spec.js","sourceRoot":"","sources":["../src/plugin.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,yDAAuD;AAEvD,mCAAiC;AAEjC,QAAQ,CAAC,QAAQ,EAAE;IACjB,EAAE,CAAC,uBAAuB,EAAE;QAC1B,IAAM,MAAM,GAAG,IAAA,eAAM,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;QACrD,IAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAA;QAErC,eAAe,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6BAA6B,EAAE;QAChC,IAAM,MAAM,GAAG,IAAA,eAAM,EAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;QACtC,IAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAA;QAErC,eAAe,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE;QAC1C,IAAM,MAAM,GAAG,IAAA,eAAM,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;QACnD,IAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAA;QAErC,qBAAqB,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+BAA+B,EAAE;QAClC,IAAM,MAAM,GAAG,IAAA,eAAM,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;QACpD,IAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAA;QAErC,qBAAqB,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,SAAS,eAAe,CAAC,MAAc;;IACrC,MAAM,CAAC,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;IAC3C,MAAM,CAAC,MAAA,MAAM,CAAC,KAAK,0CAAE,UAAU,CAAC,CAAC,WAAW,EAAE,CAAA;IAC9C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAA;AACrC,CAAC;AAED,SAAS,qBAAqB,CAAC,MAAc;;IAC3C,MAAM,CAAC,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;IAC3C,MAAM,CAAC,MAAA,MAAM,CAAC,KAAK,0CAAE,UAAU,CAAC,CAAC,aAAa,EAAE,CAAA;IAChD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAA;AACvC,CAAC;AAED,SAAS,YAAY,CAAC,SAA2B;IAC/C,6BACK,mBAAQ,GACR,SAAS,EACb;AACH,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
37
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
38
|
+
if (ar || !(i in from)) {
|
|
39
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
40
|
+
ar[i] = from[i];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.startSentry = void 0;
|
|
47
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
48
|
+
/* eslint-disable no-console */
|
|
49
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
50
|
+
var startSentry = function (pluginOptions, payload) {
|
|
51
|
+
var _a;
|
|
52
|
+
var dsn = pluginOptions.dsn, options = pluginOptions.options;
|
|
53
|
+
var app = payload.express;
|
|
54
|
+
if (!dsn || !app)
|
|
55
|
+
return;
|
|
56
|
+
try {
|
|
57
|
+
Sentry.init(__assign(__assign({}, options === null || options === void 0 ? void 0 : options.init), { dsn: dsn, integrations: __spreadArray(__spreadArray(__spreadArray([], (((_a = options === null || options === void 0 ? void 0 : options.init) === null || _a === void 0 ? void 0 : _a.integrations) || []), true), [
|
|
58
|
+
new Sentry.Integrations.Http({ tracing: true }),
|
|
59
|
+
new Sentry.Integrations.Express({ app: app })
|
|
60
|
+
], false), Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(), true) }));
|
|
61
|
+
app.use(Sentry.Handlers.requestHandler((options === null || options === void 0 ? void 0 : options.requestHandler) || {}));
|
|
62
|
+
app.use(Sentry.Handlers.tracingHandler());
|
|
63
|
+
app.use(Sentry.Handlers.errorHandler({
|
|
64
|
+
shouldHandleError: function (error) {
|
|
65
|
+
if (error.status === 500) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if ((options === null || options === void 0 ? void 0 : options.captureErrors) &&
|
|
69
|
+
typeof error.status === 'number' &&
|
|
70
|
+
options.captureErrors.includes(error.status)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
app.use(function onError(_err, _req, res, _next) {
|
|
77
|
+
res.statusCode = 500;
|
|
78
|
+
res.end(res.sentry + '\n');
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
console.log('There was an error initializing Sentry, please ensure you entered a valid DSN');
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.startSentry = startSentry;
|
|
86
|
+
//# sourceMappingURL=startSentry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startSentry.js","sourceRoot":"","sources":["../src/startSentry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,+BAA+B;AAC/B,mDAAsC;AAO/B,IAAM,WAAW,GAAG,UAAC,aAA4B,EAAE,OAAgB;;IAChE,IAAA,GAAG,GAAc,aAAa,IAA3B,EAAE,OAAO,GAAK,aAAa,QAAlB,CAAkB;IAC9B,IAAS,GAAG,GAAK,OAAO,QAAZ,CAAY;IAEhC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG;QAAE,OAAM;IAExB,IAAI;QACF,MAAM,CAAC,IAAI,uBACN,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,KAChB,GAAG,EAAE,GAAG,EACR,YAAY,gDACP,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,YAAY,KAAI,EAAE,CAAC;gBACtC,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC/C,IAAI,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC;uBACrC,MAAM,CAAC,iDAAiD,EAAE,WAE/D,CAAA;QAEF,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,KAAI,EAAE,CAA2B,CAAC,CAAA;QAChG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAA;QAEzC,GAAG,CAAC,GAAG,CACL,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC;YAC3B,iBAAiB,YAAC,KAAK;gBACrB,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE;oBACxB,OAAO,IAAI,CAAA;iBACZ;gBACD,IACE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa;oBACtB,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;oBAChC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAC5C;oBACA,OAAO,IAAI,CAAA;iBACZ;gBACD,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAgC,CAClC,CAAA;QAED,GAAG,CAAC,GAAG,CAAC,SAAS,OAAO,CACtB,IAAa,EACb,IAAa,EACb,GAAmC,EACnC,KAAmB;YAEnB,GAAG,CAAC,UAAU,GAAG,GAAG,CAAA;YACpB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;KACH;IAAC,OAAO,GAAY,EAAE;QACrB,OAAO,CAAC,GAAG,CAAC,+EAA+E,CAAC,CAAA;KAC7F;AACH,CAAC,CAAA;AAnDY,QAAA,WAAW,eAmDvB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RequestHandlerOptions } from '@sentry/node/types/handlers';
|
|
2
|
+
import type { ClientOptions } from '@sentry/types';
|
|
3
|
+
export interface PluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Sentry DSN (Data Source Name)
|
|
6
|
+
* This is required unless enabled is set to false.
|
|
7
|
+
* Sentry automatically assigns a DSN when you create a project.
|
|
8
|
+
* If you don't have a DSN yet, you can create a new project here: https://sentry.io
|
|
9
|
+
*/
|
|
10
|
+
dsn: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Enable or disable Sentry plugin
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Options passed directly to Sentry
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
options?: {
|
|
21
|
+
/**
|
|
22
|
+
* Passes any valid options to Sentry.init()
|
|
23
|
+
*/
|
|
24
|
+
init?: Partial<ClientOptions>;
|
|
25
|
+
/**
|
|
26
|
+
* Passes any valid options to Sentry.Handlers.requestHandler()
|
|
27
|
+
*/
|
|
28
|
+
requestHandler?: RequestHandlerOptions;
|
|
29
|
+
/**
|
|
30
|
+
* Sentry will only capture 500 errors by default.
|
|
31
|
+
* If you want to capture other errors, you can add them as an array here.
|
|
32
|
+
*/
|
|
33
|
+
captureErrors?: number[];
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.extendWebpackConfig = void 0;
|
|
18
|
+
var path_1 = __importDefault(require("path"));
|
|
19
|
+
var extendWebpackConfig = function (config) {
|
|
20
|
+
return function (webpackConfig) {
|
|
21
|
+
var _a;
|
|
22
|
+
var _b, _c;
|
|
23
|
+
var existingWebpackConfig = typeof ((_b = config.admin) === null || _b === void 0 ? void 0 : _b.webpack) === 'function'
|
|
24
|
+
? config.admin.webpack(webpackConfig)
|
|
25
|
+
: webpackConfig;
|
|
26
|
+
var mockModulePath = path_1.default.resolve(__dirname, './mocks/mockFile.js');
|
|
27
|
+
var newWebpack = __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_c = existingWebpackConfig.resolve) === null || _c === void 0 ? void 0 : _c.alias) ? existingWebpackConfig.resolve.alias : {})), (_a = {}, _a[path_1.default.resolve(__dirname, './startSentry')] = mockModulePath, _a[path_1.default.resolve(__dirname, './captureException')] = mockModulePath, _a)) }) });
|
|
28
|
+
return newWebpack;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.extendWebpackConfig = extendWebpackConfig;
|
|
32
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAAuB;AAIhB,IAAM,mBAAmB,GAC9B,UAAC,MAAc;IACf,OAAA,UAAA,aAAa;;;QACX,IAAM,qBAAqB,GACzB,OAAO,CAAA,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAA,KAAK,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;YACrC,CAAC,CAAC,aAAa,CAAA;QAEnB,IAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAA;QAErE,IAAM,UAAU,yBACX,qBAAqB,KACxB,OAAO,wBACF,CAAC,qBAAqB,CAAC,OAAO,IAAI,EAAE,CAAC,KACxC,KAAK,wBACA,CAAC,CAAA,MAAA,qBAAqB,CAAC,OAAO,0CAAE,KAAK,EAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,gBACnF,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,IAAG,cAAc,KACzD,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,IAAG,cAAc,YAGpE,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;AArBD,CAqBC,CAAA;AAvBU,QAAA,mBAAmB,uBAuB7B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@payloadcms/plugin-sentry",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"homepage:": "https://payloadcms.com",
|
|
5
|
+
"repository": "git@github.com:payloadcms/plugin-sentry.git",
|
|
6
|
+
"description": "Sentry plugin for Payload",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"lint": "eslint src",
|
|
13
|
+
"lint:fix": "eslint --fix --ext .ts,.tsx src",
|
|
14
|
+
"clean": "rimraf dist && rimraf dev/yarn.lock",
|
|
15
|
+
"prepublishOnly": "yarn clean && yarn build && yarn test"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"payload",
|
|
19
|
+
"cms",
|
|
20
|
+
"plugin",
|
|
21
|
+
"typescript",
|
|
22
|
+
"sentry",
|
|
23
|
+
"error handling"
|
|
24
|
+
],
|
|
25
|
+
"author": "dev@payloadcms.com",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"payload": "^1.10.1",
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@sentry/node": "^7.55.2",
|
|
36
|
+
"@sentry/types": "^7.54.0",
|
|
37
|
+
"express": "^4.18.2",
|
|
38
|
+
"node": "^18.2.0",
|
|
39
|
+
"src": "^1.1.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@payloadcms/eslint-config": "^0.0.1",
|
|
43
|
+
"@types/express": "^4.17.9",
|
|
44
|
+
"@types/jest": "^29.5.2",
|
|
45
|
+
"@types/node": "18.11.3",
|
|
46
|
+
"@types/react": "18.0.21",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
49
|
+
"copyfiles": "^2.4.1",
|
|
50
|
+
"cross-env": "^7.0.3",
|
|
51
|
+
"dotenv": "^8.2.0",
|
|
52
|
+
"eslint": "^8.19.0",
|
|
53
|
+
"eslint-config-prettier": "^8.5.0",
|
|
54
|
+
"eslint-plugin-filenames": "^1.3.2",
|
|
55
|
+
"eslint-plugin-import": "2.25.4",
|
|
56
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
57
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
58
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
59
|
+
"jest": "^29.5.0",
|
|
60
|
+
"nodemon": "^2.0.6",
|
|
61
|
+
"payload": "^1.10.1",
|
|
62
|
+
"prettier": "^2.7.1",
|
|
63
|
+
"ts-jest": "^29.1.0",
|
|
64
|
+
"ts-node": "^10.9.1",
|
|
65
|
+
"typescript": "^4.1.3"
|
|
66
|
+
}
|
|
67
|
+
}
|