@hoajs/request-id 0.1.1 → 0.1.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
@@ -1,7 +1,16 @@
1
- ## v0.1.1 / 2025-10-26
2
-
3
- - fix(types): use HoaMiddleware
4
-
5
- ## v0.1.0 / 2025-10-09
6
-
7
- - init
1
+ ## v0.1.3 / 2026-02-12
2
+
3
+ - chore: remove tsup config
4
+
5
+ ## v0.1.2 / 2026-02-12
6
+
7
+ - refactor: use tsdown instead of tsup
8
+ - chore(deps): update deps
9
+
10
+ ## v0.1.1 / 2025-10-26
11
+
12
+ - fix(types): use HoaMiddleware
13
+
14
+ ## v0.1.0 / 2025-10-09
15
+
16
+ - 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/request-id
2
-
3
- Request ID middleware for Hoa.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- $ npm i @hoajs/request-id --save
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```js
14
- import { Hoa } from 'hoa'
15
- import { requestId } from '@hoajs/request-id'
16
-
17
- const app = new Hoa()
18
- app.use(requestId())
19
-
20
- app.use(async (ctx) => {
21
- ctx.res.body = `Hello, ${ctx.state.requestId}!`
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/request-id.html)
30
-
31
- ## Test (100% coverage)
32
-
33
- ```sh
34
- $ npm test
35
- ```
36
-
37
- ## License
38
-
39
- MIT
1
+ ## @hoajs/request-id
2
+
3
+ Request ID middleware for Hoa.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ npm i @hoajs/request-id --save
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```js
14
+ import { Hoa } from 'hoa'
15
+ import { requestId } from '@hoajs/request-id'
16
+
17
+ const app = new Hoa()
18
+ app.use(requestId())
19
+
20
+ app.use(async (ctx) => {
21
+ ctx.res.body = `Hello, ${ctx.state.requestId}!`
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/request-id.html)
30
+
31
+ ## Test (100% coverage)
32
+
33
+ ```sh
34
+ $ npm test
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,38 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region src/request-id.js
4
+ /**
5
+ * Request ID middleware for Hoa.
6
+ *
7
+ * @param {Object} [options]
8
+ * @param {number} [options.limitLength=255] - The maximum length of the request id.
9
+ * @param {string} [options.headerName='X-Request-Id'] - The response header name to expose the id.
10
+ * @param {(ctx: import('hoa').HoaContext) => string} [options.generator] - Custom id generator.
11
+ * @returns {(ctx: import('hoa').HoaContext, next: () => Promise<void>) => Promise<void>} Hoa middleware.
12
+ */
13
+ function requestId(options = {}) {
14
+ const limitLength = options.limitLength ?? 255;
15
+ const headerName = options.headerName ?? "X-Request-Id";
16
+ const generator = options.generator ?? (() => crypto.randomUUID());
17
+ return async function hoaRequestId(ctx, next) {
18
+ let reqId = headerName ? ctx.req.get(headerName) : void 0;
19
+ if (!reqId || reqId.length > limitLength || /[^\w-]/.test(reqId)) reqId = generator(ctx);
20
+ ctx.state.requestId = reqId;
21
+ try {
22
+ await next();
23
+ } catch (err) {
24
+ const errHeaders = err.headers ? Object.fromEntries(new Headers(err.headers).entries()) : {};
25
+ if (headerName) {
26
+ errHeaders[headerName] = reqId;
27
+ err.headers = errHeaders;
28
+ } else if (err.headers) err.headers = errHeaders;
29
+ throw err;
30
+ } finally {
31
+ if (headerName) ctx.res.set(headerName, reqId);
32
+ }
33
+ };
34
+ }
35
+
36
+ //#endregion
37
+ exports.default = requestId;
38
+ exports.requestId = requestId;
@@ -0,0 +1,35 @@
1
+ //#region src/request-id.js
2
+ /**
3
+ * Request ID middleware for Hoa.
4
+ *
5
+ * @param {Object} [options]
6
+ * @param {number} [options.limitLength=255] - The maximum length of the request id.
7
+ * @param {string} [options.headerName='X-Request-Id'] - The response header name to expose the id.
8
+ * @param {(ctx: import('hoa').HoaContext) => string} [options.generator] - Custom id generator.
9
+ * @returns {(ctx: import('hoa').HoaContext, next: () => Promise<void>) => Promise<void>} Hoa middleware.
10
+ */
11
+ function requestId(options = {}) {
12
+ const limitLength = options.limitLength ?? 255;
13
+ const headerName = options.headerName ?? "X-Request-Id";
14
+ const generator = options.generator ?? (() => crypto.randomUUID());
15
+ return async function hoaRequestId(ctx, next) {
16
+ let reqId = headerName ? ctx.req.get(headerName) : void 0;
17
+ if (!reqId || reqId.length > limitLength || /[^\w-]/.test(reqId)) reqId = generator(ctx);
18
+ ctx.state.requestId = reqId;
19
+ try {
20
+ await next();
21
+ } catch (err) {
22
+ const errHeaders = err.headers ? Object.fromEntries(new Headers(err.headers).entries()) : {};
23
+ if (headerName) {
24
+ errHeaders[headerName] = reqId;
25
+ err.headers = errHeaders;
26
+ } else if (err.headers) err.headers = errHeaders;
27
+ throw err;
28
+ } finally {
29
+ if (headerName) ctx.res.set(headerName, reqId);
30
+ }
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ export { requestId as default, requestId };
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "@hoajs/request-id",
3
- "version": "0.1.1",
4
- "description": "Request ID middleware for Hoa.",
5
- "main": "./dist/cjs/request-id.js",
6
- "type": "module",
7
- "module": "./dist/esm/request-id.js",
8
- "types": "./types/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./types/index.d.ts",
12
- "import": "./dist/esm/request-id.js",
13
- "require": "./dist/cjs/request-id.js",
14
- "default": "./dist/esm/request-id.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/request-id.git"
34
- },
35
- "keywords": [
36
- "hoa",
37
- "middleware",
38
- "requestId",
39
- "request-id",
40
- "x-request-id"
41
- ],
42
- "devDependencies": {
43
- "@commitlint/cli": "20.1.0",
44
- "@commitlint/config-conventional": "20.0.0",
45
- "eslint": "9.37.0",
46
- "globals": "16.4.0",
47
- "hoa": "*",
48
- "husky": "9.1.7",
49
- "jest": "30.2.0",
50
- "neostandard": "0.12.2",
51
- "tsup": "8.5.0"
52
- },
53
- "peerDependencies": {
54
- "hoa": "*"
55
- },
56
- "engines": {
57
- "node": ">=20"
58
- }
59
- }
1
+ {
2
+ "name": "@hoajs/request-id",
3
+ "version": "0.1.3",
4
+ "description": "Request ID middleware for Hoa.",
5
+ "main": "./dist/cjs/request-id.cjs",
6
+ "type": "module",
7
+ "module": "./dist/esm/request-id.mjs",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "import": "./dist/esm/request-id.mjs",
13
+ "require": "./dist/cjs/request-id.cjs",
14
+ "default": "./dist/esm/request-id.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/request-id.git"
34
+ },
35
+ "keywords": [
36
+ "hoa",
37
+ "middleware",
38
+ "requestId",
39
+ "request-id",
40
+ "x-request-id"
41
+ ],
42
+ "devDependencies": {
43
+ "@commitlint/cli": "20.4.1",
44
+ "@commitlint/config-conventional": "20.4.1",
45
+ "eslint": "9.39.2",
46
+ "globals": "17.3.0",
47
+ "hoa": "*",
48
+ "husky": "9.1.7",
49
+ "jest": "30.2.0",
50
+ "neostandard": "0.12.2",
51
+ "tsdown": "^0.20.3"
52
+ },
53
+ "peerDependencies": {
54
+ "hoa": "*"
55
+ },
56
+ "engines": {
57
+ "node": ">=20"
58
+ }
59
+ }
package/types/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import type { HoaContext, HoaMiddleware } from 'hoa'
2
-
3
- export type RequestIdGenerator = (ctx: HoaContext) => string
4
-
5
- export interface RequestIdOptions {
6
- limitLength?: number
7
- headerName?: string
8
- generator?: RequestIdGenerator
9
- }
10
-
11
- export function requestId(options?: RequestIdOptions): HoaMiddleware
12
-
13
- export default requestId
1
+ import type { HoaContext, HoaMiddleware } from 'hoa'
2
+
3
+ export type RequestIdGenerator = (ctx: HoaContext) => string
4
+
5
+ export interface RequestIdOptions {
6
+ limitLength?: number
7
+ headerName?: string
8
+ generator?: RequestIdGenerator
9
+ }
10
+
11
+ export function requestId(options?: RequestIdOptions): HoaMiddleware
12
+
13
+ export default requestId
@@ -1,56 +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 request_id_exports = {};
19
- __export(request_id_exports, {
20
- default: () => request_id_default,
21
- requestId: () => requestId
22
- });
23
- module.exports = __toCommonJS(request_id_exports);
24
- function requestId(options = {}) {
25
- const limitLength = options.limitLength ?? 255;
26
- const headerName = options.headerName ?? "X-Request-Id";
27
- const generator = options.generator ?? (() => crypto.randomUUID());
28
- return async function hoaRequestId(ctx, next) {
29
- let reqId = headerName ? ctx.req.get(headerName) : void 0;
30
- if (!reqId || reqId.length > limitLength || /[^\w-]/.test(reqId)) {
31
- reqId = generator(ctx);
32
- }
33
- ctx.state.requestId = reqId;
34
- try {
35
- await next();
36
- } catch (err) {
37
- const errHeaders = err.headers ? Object.fromEntries(new Headers(err.headers).entries()) : {};
38
- if (headerName) {
39
- errHeaders[headerName] = reqId;
40
- err.headers = errHeaders;
41
- } else if (err.headers) {
42
- err.headers = errHeaders;
43
- }
44
- throw err;
45
- } finally {
46
- if (headerName) {
47
- ctx.res.set(headerName, reqId);
48
- }
49
- }
50
- };
51
- }
52
- var request_id_default = requestId;
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- requestId
56
- });
@@ -1,33 +0,0 @@
1
- function requestId(options = {}) {
2
- const limitLength = options.limitLength ?? 255;
3
- const headerName = options.headerName ?? "X-Request-Id";
4
- const generator = options.generator ?? (() => crypto.randomUUID());
5
- return async function hoaRequestId(ctx, next) {
6
- let reqId = headerName ? ctx.req.get(headerName) : void 0;
7
- if (!reqId || reqId.length > limitLength || /[^\w-]/.test(reqId)) {
8
- reqId = generator(ctx);
9
- }
10
- ctx.state.requestId = reqId;
11
- try {
12
- await next();
13
- } catch (err) {
14
- const errHeaders = err.headers ? Object.fromEntries(new Headers(err.headers).entries()) : {};
15
- if (headerName) {
16
- errHeaders[headerName] = reqId;
17
- err.headers = errHeaders;
18
- } else if (err.headers) {
19
- err.headers = errHeaders;
20
- }
21
- throw err;
22
- } finally {
23
- if (headerName) {
24
- ctx.res.set(headerName, reqId);
25
- }
26
- }
27
- };
28
- }
29
- var request_id_default = requestId;
30
- export {
31
- request_id_default as default,
32
- requestId
33
- };