cipher-logger 1.1.0 → 1.2.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.
package/.editorconfig ADDED
@@ -0,0 +1,19 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ indent_style = space
9
+ indent_size = 2
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
14
+
15
+ [Makefile]
16
+ indent_style = tab
17
+
18
+ [*.{yml,yaml}]
19
+ indent_size = 2
package/.gitattributes ADDED
File without changes
@@ -0,0 +1,36 @@
1
+ name: Pre-publish validation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ validate:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Setup pnpm
19
+ uses: pnpm/action-setup@v4
20
+ with:
21
+ version: 10
22
+
23
+ - name: Setup Node.js
24
+ uses: actions/setup-node@v4
25
+ with:
26
+ node-version: 24
27
+ cache: pnpm
28
+
29
+ - name: Install dependencies
30
+ run: pnpm install --frozen-lockfile
31
+
32
+ - name: Run validation suite
33
+ run: pnpm run test
34
+
35
+ - name: Dry run package publish
36
+ run: npm pack --dry-run
@@ -1,9 +1,9 @@
1
1
  name: Publish to npm
2
2
 
3
3
  on:
4
- push:
5
- branches:
6
- - main
4
+ workflow_run:
5
+ workflows: ["Pre-publish validation"]
6
+ types: [completed]
7
7
 
8
8
  permissions:
9
9
  contents: read
@@ -11,11 +11,14 @@ permissions:
11
11
 
12
12
  jobs:
13
13
  publish:
14
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
14
15
  runs-on: ubuntu-latest
15
16
 
16
17
  steps:
17
18
  - name: Checkout
18
19
  uses: actions/checkout@v4
20
+ with:
21
+ ref: ${{ github.event.workflow_run.head_sha }}
19
22
 
20
23
  - name: Setup pnpm
21
24
  uses: pnpm/action-setup@v4
@@ -41,9 +44,6 @@ jobs:
41
44
  - name: Install dependencies
42
45
  run: pnpm install --frozen-lockfile
43
46
 
44
- - name: Build
45
- run: pnpm run build
46
-
47
47
  - name: Publish
48
48
  run: |
49
49
  NAME=$(node -p "require('./package.json').name")
@@ -0,0 +1 @@
1
+ pnpm exec commitlint --edit "$1"
@@ -0,0 +1,4 @@
1
+ # #!/usr/bin/env sh
2
+ # . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ pnpm build
@@ -0,0 +1,11 @@
1
+ node_modules
2
+ .next
3
+ .turbo
4
+ dist
5
+ build
6
+ examples
7
+ pnpm-lock.yaml
8
+ package-lock.json
9
+ yarn.lock
10
+ *.log
11
+ .agents
@@ -0,0 +1,26 @@
1
+ /** @type {import('@commitlint/types').UserConfig} */
2
+ export default {
3
+ extends: ['@commitlint/config-conventional'],
4
+ rules: {
5
+ 'type-enum': [
6
+ 2,
7
+ 'always',
8
+ [
9
+ 'feat',
10
+ 'fix',
11
+ 'docs',
12
+ 'i18n',
13
+ 'style',
14
+ 'refactor',
15
+ 'perf',
16
+ 'test',
17
+ 'build',
18
+ 'ci',
19
+ 'chore',
20
+ 'revert',
21
+ ],
22
+ ],
23
+ 'subject-case': [2, 'never', ['start-case', 'pascal-case', 'upper-case']],
24
+ 'header-max-length': [2, 'always', 100],
25
+ },
26
+ };
package/dist/index.js CHANGED
@@ -312,7 +312,9 @@ function createNestMiddleware(cipher) {
312
312
 
313
313
  // src/adapters/hono/middleware.ts
314
314
  function getHeader5(request, name) {
315
- if (!request) return void 0;
315
+ if (!request) {
316
+ return void 0;
317
+ }
316
318
  if (typeof request.header === "function") {
317
319
  return request.header(name) ?? void 0;
318
320
  }
@@ -321,6 +323,9 @@ function getHeader5(request, name) {
321
323
  }
322
324
  return void 0;
323
325
  }
326
+ function hasHeader(request, name) {
327
+ return Boolean(getHeader5(request, name));
328
+ }
324
329
  function parseQuery5(urlString) {
325
330
  try {
326
331
  const url = new URL(urlString);
@@ -348,7 +353,7 @@ function createHonoMiddleware(cipher) {
348
353
  status = cres.statusCode;
349
354
  }
350
355
  const xfwd = getHeader5(req, "x-forwarded-for");
351
- const ip = xfwd ? String(xfwd).split(",")[0].trim() : getHeader5(req, "x-real-ip") ?? void 0;
356
+ const ip = hasHeader(req, "x-forwarded-for") ? String(xfwd).split(",")[0].trim() : getHeader5(req, "x-real-ip") ?? void 0;
352
357
  cipher.logRequest({
353
358
  method: req?.method,
354
359
  path: parsed.pathname + parsed.search,
package/dist/index.mjs CHANGED
@@ -279,7 +279,9 @@ function createNestMiddleware(cipher) {
279
279
 
280
280
  // src/adapters/hono/middleware.ts
281
281
  function getHeader5(request, name) {
282
- if (!request) return void 0;
282
+ if (!request) {
283
+ return void 0;
284
+ }
283
285
  if (typeof request.header === "function") {
284
286
  return request.header(name) ?? void 0;
285
287
  }
@@ -288,6 +290,9 @@ function getHeader5(request, name) {
288
290
  }
289
291
  return void 0;
290
292
  }
293
+ function hasHeader(request, name) {
294
+ return Boolean(getHeader5(request, name));
295
+ }
291
296
  function parseQuery5(urlString) {
292
297
  try {
293
298
  const url = new URL(urlString);
@@ -315,7 +320,7 @@ function createHonoMiddleware(cipher) {
315
320
  status = cres.statusCode;
316
321
  }
317
322
  const xfwd = getHeader5(req, "x-forwarded-for");
318
- const ip = xfwd ? String(xfwd).split(",")[0].trim() : getHeader5(req, "x-real-ip") ?? void 0;
323
+ const ip = hasHeader(req, "x-forwarded-for") ? String(xfwd).split(",")[0].trim() : getHeader5(req, "x-real-ip") ?? void 0;
319
324
  cipher.logRequest({
320
325
  method: req?.method,
321
326
  path: parsed.pathname + parsed.search,
@@ -0,0 +1,69 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import nextVitals from "eslint-config-next/core-web-vitals";
3
+ import nextTs from "eslint-config-next/typescript";
4
+
5
+ export default defineConfig([
6
+ ...nextVitals,
7
+ ...nextTs,
8
+
9
+ {
10
+ rules: {
11
+ // ===== JavaScript =====
12
+ eqeqeq: ["error", "always"],
13
+ curly: ["error", "all"],
14
+ "no-var": "error",
15
+ "prefer-const": "error",
16
+ "no-console":
17
+ process.env.NODE_ENV === "production"
18
+ ? ["warn", { allow: ["warn", "error"] }]
19
+ : "off",
20
+
21
+ // ===== TypeScript =====
22
+ "@typescript-eslint/no-unused-vars": [
23
+ "warn",
24
+ {
25
+ argsIgnorePattern: "^_",
26
+ varsIgnorePattern: "^_",
27
+ ignoreRestSiblings: true,
28
+ },
29
+ ],
30
+ "@typescript-eslint/consistent-type-imports": [
31
+ "error",
32
+ {
33
+ prefer: "type-imports",
34
+ fixStyle: "inline-type-imports",
35
+ },
36
+ ],
37
+ "@typescript-eslint/no-explicit-any": "warn",
38
+ "@typescript-eslint/no-non-null-assertion": "warn",
39
+
40
+ // ===== Import =====
41
+ "sort-imports": [
42
+ "warn",
43
+ {
44
+ ignoreDeclarationSort: true,
45
+ ignoreCase: true,
46
+ },
47
+ ],
48
+
49
+ // ===== React =====
50
+ "react/jsx-key": "error",
51
+ "react/self-closing-comp": "warn",
52
+
53
+ // ===== Next =====
54
+ "@next/next/no-img-element": "warn",
55
+ },
56
+ },
57
+
58
+ globalIgnores([
59
+ ".next/**",
60
+ "out/**",
61
+ "build/**",
62
+ "next-env.d.ts",
63
+ "coverage/**",
64
+ "dist/**",
65
+ "*.config.js",
66
+ "*.config.cjs",
67
+ "*.config.mjs",
68
+ ]),
69
+ ]);
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "cipher-logger",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "See every request. Capture every error. Understand your application.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
8
  "scripts": {
9
9
  "build": "tsup",
10
- "prepublishOnly": "npm run build"
10
+ "lint": "eslint .",
11
+ "lint:fix": "eslint --fix .",
12
+ "test": "pnpm run lint && pnpm run build",
13
+ "prepublishOnly": "pnpm run test",
14
+ "commitlint": "commitlint --edit",
15
+ "clean": "rm -rf out dist node_modules/.cache",
16
+ "prepare": "husky"
11
17
  },
12
18
  "repository": {
13
19
  "type": "git",
@@ -73,8 +79,7 @@
73
79
  },
74
80
  "next": {
75
81
  "optional": true
76
- }
77
- ,
82
+ },
78
83
  "fastify": {
79
84
  "optional": true
80
85
  },
@@ -89,6 +94,8 @@
89
94
  }
90
95
  },
91
96
  "devDependencies": {
97
+ "@commitlint/cli": "^20.1.0",
98
+ "@commitlint/config-conventional": "^20.0.0",
92
99
  "@types/express": "^5.0.3",
93
100
  "@types/node": "^26.1.2",
94
101
  "express": "^5.1.0",
@@ -96,6 +103,9 @@
96
103
  "fastify": "^4.27.0",
97
104
  "hono": "^3.3.0",
98
105
  "tsup": "^8.5.1",
106
+ "eslint": "^9",
107
+ "eslint-config-next": "16.3.0",
108
+ "husky": "^9.1.7",
99
109
  "typescript": "^6.0.3"
100
110
  }
101
- }
111
+ }
@@ -0,0 +1,18 @@
1
+ /** @type {import("prettier").Config} */
2
+ const config = {
3
+ semi: true,
4
+ singleQuote: false,
5
+ jsxSingleQuote: false,
6
+ trailingComma: "all",
7
+ tabWidth: 2,
8
+ useTabs: false,
9
+ printWidth: 80,
10
+ bracketSpacing: true,
11
+ bracketSameLine: false,
12
+ arrowParens: "always",
13
+ endOfLine: "lf",
14
+
15
+ plugins: ["prettier-plugin-tailwindcss"],
16
+ };
17
+
18
+ export default config;