@hoajs/sentry 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
- ## v0.1.0 / 2025-10-27
2
-
3
- - init
1
+ ## v0.1.1 / 2026-02-11
2
+
3
+ - refactor: use tsdown instead of tsup
4
+ - chore(deps): update deps
5
+
6
+ ## v0.1.0 / 2025-10-27
7
+
8
+ - init
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 - present, Hoa contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 - present, Hoa contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,39 +1,39 @@
1
- ## @hoajs/sentry
2
-
3
- Sentry middleware for Hoa.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- $ npm i @hoajs/sentry --save
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```js
14
- import { Hoa } from 'hoa'
15
- import { sentry } from '@hoajs/sentry'
16
-
17
- const app = new Hoa()
18
- app.use(sentry({ dsn: 'xxx' }))
19
-
20
- app.use(async (ctx) => {
21
- ctx.throw(400, 'Some error')
22
- })
23
-
24
- export default app
25
- ```
26
-
27
- ## Documentation
28
-
29
- The documentation is available on [hoa-js.com](https://hoa-js.com/middleware/debug/sentry.html)
30
-
31
- ## Test (100% coverage)
32
-
33
- ```sh
34
- $ npm test
35
- ```
36
-
37
- ## License
38
-
39
- MIT
1
+ ## @hoajs/sentry
2
+
3
+ Sentry middleware for Hoa.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ npm i @hoajs/sentry --save
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```js
14
+ import { Hoa } from 'hoa'
15
+ import { sentry } from '@hoajs/sentry'
16
+
17
+ const app = new Hoa()
18
+ app.use(sentry({ dsn: 'xxx' }))
19
+
20
+ app.use(async (ctx) => {
21
+ ctx.throw(400, 'Some error')
22
+ })
23
+
24
+ export default app
25
+ ```
26
+
27
+ ## Documentation
28
+
29
+ The documentation is available on [hoa-js.com](https://hoa-js.com/middleware/debug/sentry.html)
30
+
31
+ ## Test (100% coverage)
32
+
33
+ ```sh
34
+ $ npm test
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,56 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ let toucan_js = require("toucan-js");
3
+
4
+ //#region src/sentry.js
5
+ /**
6
+ * Minimal mock for Cloudflare's ExecutionContext when not provided.
7
+ */
8
+ var MockExecutionContext = class {
9
+ passThroughOnException() {}
10
+ async waitUntil(promise) {
11
+ await promise;
12
+ }
13
+ };
14
+ const mockExecutionContext = new MockExecutionContext();
15
+ /**
16
+ * Sentry middleware for Hoa.
17
+ *
18
+ * - Reads DSN from `ctx.env.SENTRY_DSN` (or `ctx.env.NEXT_PUBLIC_SENTRY_DSN`).
19
+ * - Attaches the Toucan instance to `ctx.state.sentry`.
20
+ * - Captures exceptions thrown by downstream middleware and rethrows them.
21
+ *
22
+ * @param {Object} [options] - Sentry options
23
+ * @param {string} [options.dsn] - Sentry DSN; falls back to `ctx.env.SENTRY_DSN` or `ctx.env.NEXT_PUBLIC_SENTRY_DSN` when omitted.
24
+ * @returns {HoaMiddleware}
25
+ */
26
+ const sentry = (options = {}) => {
27
+ return async function sentryMiddleware(ctx, next) {
28
+ const toucan = new toucan_js.Toucan({
29
+ dsn: ctx.env?.SENTRY_DSN ?? ctx.env?.NEXT_PUBLIC_SENTRY_DSN,
30
+ request: ctx.request,
31
+ context: ctx.executionCtx ?? mockExecutionContext,
32
+ ...options
33
+ });
34
+ ctx.state.sentry = toucan;
35
+ try {
36
+ await next();
37
+ } catch (err) {
38
+ const status = err.status ?? err.statusCode ?? 500;
39
+ toucan.setTag("http.status_code", String(status));
40
+ toucan.setTag("http.method", ctx.req.method);
41
+ toucan.setTag("http.url", `${ctx.req.pathname}${ctx.req.search}`);
42
+ if (ctx.req.routePath) toucan.setTag("http.route", ctx.req.routePath);
43
+ toucan.setTag("http.host", ctx.req.host);
44
+ const referer = ctx.req.get("referer") || ctx.req.get("referrer");
45
+ if (referer) toucan.setTag("http.referer", referer);
46
+ const requestId = ctx.state.requestId || ctx.req.get("x-request-id");
47
+ if (requestId) toucan.setTag("request_id", requestId);
48
+ toucan.captureException(err);
49
+ throw err;
50
+ }
51
+ };
52
+ };
53
+
54
+ //#endregion
55
+ exports.default = sentry;
56
+ exports.sentry = sentry;
@@ -0,0 +1,54 @@
1
+ import { Toucan } from "toucan-js";
2
+
3
+ //#region src/sentry.js
4
+ /**
5
+ * Minimal mock for Cloudflare's ExecutionContext when not provided.
6
+ */
7
+ var MockExecutionContext = class {
8
+ passThroughOnException() {}
9
+ async waitUntil(promise) {
10
+ await promise;
11
+ }
12
+ };
13
+ const mockExecutionContext = new MockExecutionContext();
14
+ /**
15
+ * Sentry middleware for Hoa.
16
+ *
17
+ * - Reads DSN from `ctx.env.SENTRY_DSN` (or `ctx.env.NEXT_PUBLIC_SENTRY_DSN`).
18
+ * - Attaches the Toucan instance to `ctx.state.sentry`.
19
+ * - Captures exceptions thrown by downstream middleware and rethrows them.
20
+ *
21
+ * @param {Object} [options] - Sentry options
22
+ * @param {string} [options.dsn] - Sentry DSN; falls back to `ctx.env.SENTRY_DSN` or `ctx.env.NEXT_PUBLIC_SENTRY_DSN` when omitted.
23
+ * @returns {HoaMiddleware}
24
+ */
25
+ const sentry = (options = {}) => {
26
+ return async function sentryMiddleware(ctx, next) {
27
+ const toucan = new Toucan({
28
+ dsn: ctx.env?.SENTRY_DSN ?? ctx.env?.NEXT_PUBLIC_SENTRY_DSN,
29
+ request: ctx.request,
30
+ context: ctx.executionCtx ?? mockExecutionContext,
31
+ ...options
32
+ });
33
+ ctx.state.sentry = toucan;
34
+ try {
35
+ await next();
36
+ } catch (err) {
37
+ const status = err.status ?? err.statusCode ?? 500;
38
+ toucan.setTag("http.status_code", String(status));
39
+ toucan.setTag("http.method", ctx.req.method);
40
+ toucan.setTag("http.url", `${ctx.req.pathname}${ctx.req.search}`);
41
+ if (ctx.req.routePath) toucan.setTag("http.route", ctx.req.routePath);
42
+ toucan.setTag("http.host", ctx.req.host);
43
+ const referer = ctx.req.get("referer") || ctx.req.get("referrer");
44
+ if (referer) toucan.setTag("http.referer", referer);
45
+ const requestId = ctx.state.requestId || ctx.req.get("x-request-id");
46
+ if (requestId) toucan.setTag("request_id", requestId);
47
+ toucan.captureException(err);
48
+ throw err;
49
+ }
50
+ };
51
+ };
52
+
53
+ //#endregion
54
+ export { sentry as default, sentry };
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
- {
2
- "name": "@hoajs/sentry",
3
- "version": "0.1.0",
4
- "description": "Sentry middleware for Hoa.",
5
- "main": "./dist/cjs/sentry.js",
6
- "type": "module",
7
- "module": "./dist/esm/sentry.js",
8
- "types": "./types/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./types/index.d.ts",
12
- "import": "./dist/esm/sentry.js",
13
- "require": "./dist/cjs/sentry.js",
14
- "default": "./dist/esm/sentry.js"
15
- }
16
- },
17
- "files": [
18
- "dist",
19
- "types",
20
- "CHANGELOG.md"
21
- ],
22
- "scripts": {
23
- "lint": "eslint .",
24
- "build": "tsup",
25
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
26
- "prepublishOnly": "npm run lint && npm run test && npm run build",
27
- "prepare": "husky"
28
- },
29
- "author": "nswbmw",
30
- "license": "MIT",
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/hoa-js/sentry.git"
34
- },
35
- "keywords": [
36
- "hoa",
37
- "middleware",
38
- "sentry",
39
- "debug",
40
- "debugging",
41
- "errors",
42
- "exceptions",
43
- "logging",
44
- "toucan",
45
- "toucan-js"
46
- ],
47
- "devDependencies": {
48
- "@commitlint/cli": "20.1.0",
49
- "@commitlint/config-conventional": "20.0.0",
50
- "eslint": "9.38.0",
51
- "globals": "16.4.0",
52
- "hoa": "^0.3.0",
53
- "husky": "9.1.7",
54
- "jest": "30.2.0",
55
- "neostandard": "0.12.2",
56
- "tsup": "8.5.0"
57
- },
58
- "peerDependencies": {
59
- "hoa": "*",
60
- "toucan-js": "~4.1.1"
61
- },
62
- "engines": {
63
- "node": ">=20"
64
- }
65
- }
1
+ {
2
+ "name": "@hoajs/sentry",
3
+ "version": "0.1.1",
4
+ "description": "Sentry middleware for Hoa.",
5
+ "main": "./dist/cjs/sentry.cjs",
6
+ "type": "module",
7
+ "module": "./dist/esm/sentry.mjs",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "import": "./dist/esm/sentry.mjs",
13
+ "require": "./dist/cjs/sentry.cjs",
14
+ "default": "./dist/esm/sentry.mjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "types",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "scripts": {
23
+ "lint": "eslint .",
24
+ "build": "tsdown",
25
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
26
+ "prepublishOnly": "npm run lint && npm run test && npm run build",
27
+ "prepare": "husky"
28
+ },
29
+ "author": "nswbmw",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/hoa-js/sentry.git"
34
+ },
35
+ "keywords": [
36
+ "hoa",
37
+ "middleware",
38
+ "sentry",
39
+ "debug",
40
+ "debugging",
41
+ "errors",
42
+ "exceptions",
43
+ "logging",
44
+ "toucan",
45
+ "toucan-js"
46
+ ],
47
+ "devDependencies": {
48
+ "@commitlint/cli": "20.4.1",
49
+ "@commitlint/config-conventional": "20.4.1",
50
+ "eslint": "9.39.2",
51
+ "globals": "17.3.0",
52
+ "hoa": "*",
53
+ "husky": "9.1.7",
54
+ "jest": "30.2.0",
55
+ "neostandard": "0.12.2",
56
+ "tsdown": "^0.20.3"
57
+ },
58
+ "peerDependencies": {
59
+ "hoa": "*",
60
+ "toucan-js": "~4.1.1"
61
+ },
62
+ "engines": {
63
+ "node": ">=20"
64
+ }
65
+ }
package/types/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { HoaMiddleware } from 'hoa'
2
- import type { Options as ToucanOptions } from 'toucan-js'
3
-
4
- export type SentryOptions = Partial<Omit<ToucanOptions, 'request' | 'context'>>
5
-
6
- export function sentry (options?: SentryOptions): HoaMiddleware
7
-
1
+ import type { HoaMiddleware } from 'hoa'
2
+ import type { Options as ToucanOptions } from 'toucan-js'
3
+
4
+ export type SentryOptions = Partial<Omit<ToucanOptions, 'request' | 'context'>>
5
+
6
+ export function sentry (options?: SentryOptions): HoaMiddleware
7
+
8
8
  export default sentry
@@ -1,64 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var sentry_exports = {};
19
- __export(sentry_exports, {
20
- default: () => sentry_default,
21
- sentry: () => sentry
22
- });
23
- module.exports = __toCommonJS(sentry_exports);
24
- var import_toucan_js = require("toucan-js");
25
- class MockExecutionContext {
26
- passThroughOnException() {
27
- }
28
- async waitUntil(promise) {
29
- await promise;
30
- }
31
- }
32
- const mockExecutionContext = new MockExecutionContext();
33
- const sentry = (options = {}) => {
34
- return async function sentryMiddleware(ctx, next) {
35
- const toucan = new import_toucan_js.Toucan({
36
- dsn: ctx.env?.SENTRY_DSN ?? ctx.env?.NEXT_PUBLIC_SENTRY_DSN,
37
- request: ctx.request,
38
- context: ctx.executionCtx ?? mockExecutionContext,
39
- ...options
40
- });
41
- ctx.state.sentry = toucan;
42
- try {
43
- await next();
44
- } catch (err) {
45
- const status = err.status ?? err.statusCode ?? 500;
46
- toucan.setTag("http.status_code", String(status));
47
- toucan.setTag("http.method", ctx.req.method);
48
- toucan.setTag("http.url", `${ctx.req.pathname}${ctx.req.search}`);
49
- if (ctx.req.routePath) toucan.setTag("http.route", ctx.req.routePath);
50
- toucan.setTag("http.host", ctx.req.host);
51
- const referer = ctx.req.get("referer") || ctx.req.get("referrer");
52
- if (referer) toucan.setTag("http.referer", referer);
53
- const requestId = ctx.state.requestId || ctx.req.get("x-request-id");
54
- if (requestId) toucan.setTag("request_id", requestId);
55
- toucan.captureException(err);
56
- throw err;
57
- }
58
- };
59
- };
60
- var sentry_default = sentry;
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
63
- sentry
64
- });
@@ -1,41 +0,0 @@
1
- import { Toucan } from "toucan-js";
2
- class MockExecutionContext {
3
- passThroughOnException() {
4
- }
5
- async waitUntil(promise) {
6
- await promise;
7
- }
8
- }
9
- const mockExecutionContext = new MockExecutionContext();
10
- const sentry = (options = {}) => {
11
- return async function sentryMiddleware(ctx, next) {
12
- const toucan = new Toucan({
13
- dsn: ctx.env?.SENTRY_DSN ?? ctx.env?.NEXT_PUBLIC_SENTRY_DSN,
14
- request: ctx.request,
15
- context: ctx.executionCtx ?? mockExecutionContext,
16
- ...options
17
- });
18
- ctx.state.sentry = toucan;
19
- try {
20
- await next();
21
- } catch (err) {
22
- const status = err.status ?? err.statusCode ?? 500;
23
- toucan.setTag("http.status_code", String(status));
24
- toucan.setTag("http.method", ctx.req.method);
25
- toucan.setTag("http.url", `${ctx.req.pathname}${ctx.req.search}`);
26
- if (ctx.req.routePath) toucan.setTag("http.route", ctx.req.routePath);
27
- toucan.setTag("http.host", ctx.req.host);
28
- const referer = ctx.req.get("referer") || ctx.req.get("referrer");
29
- if (referer) toucan.setTag("http.referer", referer);
30
- const requestId = ctx.state.requestId || ctx.req.get("x-request-id");
31
- if (requestId) toucan.setTag("request_id", requestId);
32
- toucan.captureException(err);
33
- throw err;
34
- }
35
- };
36
- };
37
- var sentry_default = sentry;
38
- export {
39
- sentry_default as default,
40
- sentry
41
- };