Skip to content

Commit d2c90b4

Browse files
Merge pull request #2 from cipherunits/dev
Dev
2 parents 494d1b9 + 7d07fad commit d2c90b4

29 files changed

Lines changed: 429 additions & 185 deletions

‎.agents/skills/fusion-architecture/SKILL.md‎

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,32 @@
22

33
Only when the user needs to modify the CipherLogger package itself (not a project
44
that uses it) — for example, bug fixes, adding a new optional field, or writing an
5-
adapter for another framework (like Fastify or Hono).
5+
adapter for another framework.
66

77
## Folder structure
88

99
```
1010
cipher-logger/
1111
├── src/
12-
│ ├── core/ # core — field configuration and log construction
13-
│ │ ├── logger.ts
14-
│ │ ├── types.ts
15-
│ │ ├── build-request-log.ts
16-
│ │ └── create-cipher-logger.ts
17-
│ ├── express/ # Express adapter
18-
│ │ └── middleware.ts
19-
│ ├── next/ # Next.js adapter
20-
│ │ └── middleware.ts
21-
│ └── index.ts # public entry point
12+
│ ├── core/ # field config, Logger, createCipherLogger
13+
│ ├── adapters/
14+
│ │ ├── express/
15+
│ │ ├── next/
16+
│ │ ├── nuxt/
17+
│ │ ├── fastify/
18+
│ │ ├── nest/
19+
│ │ └── hono/
20+
│ ├── index.ts # core public entry
21+
│ ├── express.ts # cipher-logger/express
22+
│ ├── next.ts # cipher-logger/next
23+
│ └── … # other subpath entries
2224
```
2325

2426
## Data flow
2527

26-
```
27-
Core
28-
fields config → buildRequestLog
29-
│
30-
┌─────────┴─────────┐
31-
▼ ▼
32-
Express Next.js
33-
middleware middleware
34-
```
35-
36-
Both adapters (`express/middleware.ts` and `next/middleware.ts`) rely on the
37-
same `buildRequestLog` core — only the extraction of request/response fields from
38-
the framework differs. The difference in `status`/`duration` behavior between the
39-
two adapters stems from how each adapter calls the core, not from `buildRequestLog`
40-
itself.
28+
Core (`buildRequestLog`) is shared. Each adapter only extracts framework-specific
29+
request/response fields. Subpath entries keep peer frameworks out of the main
30+
`cipher-logger` bundle until that adapter is imported or lazy-loaded.
4131

4232
## Local development
4333

@@ -48,17 +38,17 @@ pnpm install
4838
pnpm run build
4939
```
5040

51-
## Adding a new adapter (e.g. Fastify)
41+
## Adding a new adapter
5242

53-
Create a new file such as `src/fastify/middleware.ts` that calls the same
54-
`buildRequestLog` from `core/build-request-log.ts` and only differs in how fields
55-
are extracted from the framework — do not reimplement the log-construction logic
56-
inside the new adapter.
43+
1. Add `src/adapters/<name>/middleware.ts` that calls `cipher.logRequest(...)`.
44+
2. Add `src/<name>.ts` re-exporting the factory.
45+
3. Register the entry in `tsup.config.ts` and `package.json` `exports`.
46+
4. Wire a lazy method on `createCipherLogger` via `loadAdapter("<name>")`.
5747

5848
## Contribution rules (from README)
5949

6050
- Commits must follow [Conventional Commits](https://www.conventionalcommits.org/)
6151
- Run `pnpm run build` before opening a PR
6252
- Keep changes focused and small
63-
- Update README for any API changes
64-
- License: MIT © Cipher Unit
53+
- Update README/docs for any API changes
54+
- License: BSD-3-Clause © Cipher Unit

‎.github/workflows/publish.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ permissions:
1111

1212
jobs:
1313
publish:
14-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
# Only publish successful pushes to main — never PRs or other branches.
15+
if: >
16+
github.event.workflow_run.conclusion == 'success' &&
17+
github.event.workflow_run.event == 'push' &&
18+
github.event.workflow_run.head_branch == 'main'
1519
runs-on: ubuntu-latest
1620

1721
steps:
@@ -57,4 +61,4 @@ jobs:
5761
exit 0
5862
fi
5963
60-
npm publish --access public
64+
npm publish --access public --provenance

‎.husky/commit-msg‎

100644100755
File mode changed.

‎.husky/pre-commit‎

100644100755
File mode changed.

‎.npmignore‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
# Source & tooling (published package only ships dist + docs via "files")
1+
# Backup ignore list; package.json "files" is the publish allowlist.
22
src/
33
tsconfig.json
44
tsup.config.ts
55
pnpm-lock.yaml
66
pnpm-workspace.yaml
7-
CipherScope_Roadmap.md
7+
eslint.config.mjs
8+
mkdocs.yml
9+
zensical.toml
10+
docs/
11+
.agents/
12+
.github/
13+
.husky/
14+
assets/
15+
examples/
816
test/
917

1018
# Local artifacts
@@ -21,4 +29,3 @@ Thumbs.db
2129
*.swp
2230
*.swo
2331
Backups
24-
examples

‎README.md‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p align="center">
22
<img
33
src="./assets/cipherlogger_logo_mono.png"
4-
alt="Fusion Snippet"
4+
alt="Cipher Logger"
55
width="120"
66
style="border-radius: 18px;"
77
/>
@@ -16,20 +16,20 @@
1616

1717
<p align="center">
1818
<a href="https://www.npmjs.com/package/cipher-logger"><img src="https://img.shields.io/npm/v/cipher-logger.svg" alt="npm version"></a>
19-
<a href="https://github.com/cipherunits/CipherLogger/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="license"></a>
19+
<a href="https://github.com/cipherunits/CipherLogger/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="license"></a>
2020
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg" alt="node version"></a>
2121
<a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-ready-3178C6.svg" alt="typescript"></a>
2222
</p>
2323

2424
---
2525

26-
**Cipher Logger** is a lightweight, production-ready HTTP request logging library for Node.js. It captures every request in your app — **Express**, **Next.js**, and more frameworks on the way — with full control over which fields get logged.
26+
**Cipher Logger** is a lightweight, production-ready HTTP request logging library for Node.js. It captures every request with adapters for **Express**, **Next.js**, **Fastify**, **Hono**, **NestJS**, and **Nuxt**, with full control over which fields get logged.
2727

2828
## Highlights
2929

3030
- **TypeScript-first**, fully typed API
3131
- **Configurable fields** — required fields always logged, optional fields opt-in
32-
- **Framework adapters** for Express and Next.js, with more in progress
32+
- **Framework adapters** via subpath imports (`cipher-logger/express`, `cipher-logger/next`, …)
3333
- **Zero heavy dependencies** — only your framework as an optional peer dependency
3434
- **Node.js 18+**
3535

@@ -47,20 +47,28 @@ yarn add cipher-logger
4747

4848
```ts
4949
import { createCipherLogger } from "cipher-logger";
50+
import { createExpressMiddleware } from "cipher-logger/express";
5051

5152
const cipher = createCipherLogger({
5253
fields: { ip: true, userAgent: true, query: true },
5354
level: "info",
5455
});
5556

56-
app.use(cipher.express());
57+
app.use(createExpressMiddleware(cipher));
58+
// or: app.use(cipher.express());
5759
```
5860

5961
## Documentation
6062

61-
Full documentation — configuration reference, framework guides (Express, Next.js, and upcoming adapters), log schema, API reference, and architecture — lives on the docs site:
63+
Full documentation — configuration reference, framework guides, log schema, API reference, and architecture — lives on the docs site:
6264

63-
**[docs.cipherunit.xyz](https://cipherunits.github.io/CipherLogger/)**
65+
| Resource | URL |
66+
|----------|-----|
67+
| Npm Package | [npmjs.com](https://npmjs.com/package/cipher-logger) |
68+
| Documentation | [cipherunits.github.io/CipherLogger](https://cipherunits.github.io/CipherLogger/) |
69+
| GitHub Org | [github.com/cipherunits](https://github.com/cipherunits/CipherLogger) |
70+
71+
---
6472

6573
## Contributing
6674

@@ -72,12 +80,18 @@ Contributions are welcome.
7280
4. Run `pnpm run build` before submitting
7381
5. Open a Pull Request
7482

75-
See the [full contributing guide](https://docs.cipherunit.xyz/contributing) on the docs site for details.
83+
See the [full contributing guide](https://cipherunits.github.io/CipherLogger/) on the docs site for details.
7684

7785
## License
7886

7987
[BSD-3-Clause](./LICENSE) © [Cipher Unit](https://cipherunit.xyz)
8088

89+
</br>
90+
</br>
91+
</br>
92+
</br>
93+
</br>
94+
8195
<p align="center" style="margin-top: 100px;">
8296
<b><i>Made with ❤️ for developers by CipherUnits</i></b>
83-
</p>
97+
</p>

‎docs/advanced/architecture.md‎

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
# Architecture
22

3-
CipherLogger is split into a framework-agnostic **core** and thin, per-framework **adapters**. This keeps the dependency footprint small — you only pull in the adapter for the framework you actually use — and keeps the logging logic itself easy to test in isolation.
3+
CipherLogger is split into a framework-agnostic **core** and thin, per-framework **adapters**. Adapters ship as separate entry points so importing the core package does not load Express, Next.js, or other peers.
44

55
## Package layout
66

77
```text
88
cipher-logger/
99
├── src/
10-
│ ├── core/ # Core — field config & log building
11-
│ │ ├── logger.ts
12-
│ │ ├── types.ts
13-
│ │ ├── build-request-log.ts
14-
│ │ └── create-cipher-logger.ts
15-
│ ├── express/ # Express adapter
16-
│ │ └── middleware.ts
17-
│ ├── next/ # Next.js adapter
18-
│ │ └── middleware.ts
19-
│ └── index.ts # Public entry point
10+
│ ├── core/ # Field config, Logger, createCipherLogger
11+
│ ├── adapters/
12+
│ │ ├── express/
13+
│ │ ├── next/
14+
│ │ ├── nuxt/
15+
│ │ ├── fastify/
16+
│ │ ├── nest/
17+
│ │ └── hono/
18+
│ ├── index.ts # Public core entry
19+
│ ├── express.ts # Subpath: cipher-logger/express
20+
│ ├── next.ts # Subpath: cipher-logger/next
21+
│ └── … # Other adapter entries
22+
└── dist/ # Built CJS + ESM + types
2023
```
2124

2225
## Data flow
@@ -25,22 +28,33 @@ cipher-logger/
2528
flowchart TB
2629
A[fields config] --> B[buildRequestLog]
2730
B --> C{Adapter}
28-
C --> D[Express middleware]
31+
C --> D[Express / Nest]
2932
C --> E[Next.js middleware]
30-
D --> F[res.finish → accurate status/duration]
31-
E --> G[middleware execution → see timing caveat]
33+
C --> F[withCipherLogger route handler]
34+
C --> G[Fastify / Hono / Nuxt]
35+
D --> H[res.finish → accurate status/duration]
36+
F --> I[real Response status/duration]
37+
E --> J[middleware timing caveat]
3238
```
3339

34-
1. **Core** owns the `fields` configuration and `buildRequestLog`, which assembles a `RequestLog` object from raw request/response data and whatever optional fields are enabled.
35-
2. **Adapters** are responsible only for extracting framework-specific data (headers, timing hooks, request/response objects) and handing it to core in a normalized shape.
36-
3. Each adapter decides *when* logging happens — Express logs on `res.finish` (after the real response), while the Next.js adapter currently logs during middleware execution (see the [timing caveat](../guide/nextjs.md#timing-caveat)).
40+
1. **Core** owns `fields` configuration and `buildRequestLog`.
41+
2. **Adapters** extract framework-specific data and call `cipher.logRequest(...)`.
42+
3. Convenience methods like `cipher.express()` lazy-load the matching `dist/<adapter>` chunk at call time so unused peers are never required.
3743

3844
## Why this split?
3945

40-
- **Small surface area per adapter.** Adding a new framework (Fastify, Hono, NestJS, Nuxt — see the [Roadmap](roadmap.md)) means writing a thin file that maps that framework's request lifecycle onto core, not reimplementing field logic.
41-
- **Zero unnecessary dependencies.** `express` and `next` are optional peer dependencies — installing CipherLogger doesn't pull in either unless you import that adapter.
42-
- **Testable core.** `buildRequestLog` and `Logger` have no framework dependencies, so they're covered by plain unit tests independent of any HTTP server.
43-
44-
## Public entry point
45-
46-
`src/index.ts` re-exports everything documented in the [API Reference](../reference/api.md): `createCipherLogger`, `Logger`, and every public type. Adapters are not imported eagerly — `cipher.express()` and `cipher.next()` are resolved lazily so that, for example, requiring `next` doesn't happen in a pure-Express project.
46+
- **Small surface area per adapter.** Adding a framework means a thin adapter file plus a subpath entry.
47+
- **Optional peers stay optional.** `require("cipher-logger")` / `import "cipher-logger"` does not load `next` or `express`.
48+
- **Typed imports when you need them.** Prefer `import { createExpressMiddleware } from "cipher-logger/express"` for full framework types.
49+
50+
## Public entry points
51+
52+
| Import | Contents |
53+
| ------ | -------- |
54+
| `cipher-logger` | `createCipherLogger`, `Logger`, core types |
55+
| `cipher-logger/express` | `createExpressMiddleware` |
56+
| `cipher-logger/next` | `createNextMiddleware`, `withCipherLogger` |
57+
| `cipher-logger/fastify` | `createFastifyMiddleware` |
58+
| `cipher-logger/hono` | `createHonoMiddleware` |
59+
| `cipher-logger/nest` | `createNestMiddleware` |
60+
| `cipher-logger/nuxt` | `createNuxtMiddleware` |

‎docs/advanced/roadmap.md‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ CipherLogger is under active development. This page tracks what's planned so you
77
| Framework | Status |
88
| --------- | ------ |
99
| Express | :material-check-circle:{ style="color: #4caf50" } Stable |
10-
| Next.js | :material-check-circle:{ style="color: #4caf50" } Stable (see [timing caveat](../guide/nextjs.md#timing-caveat)) |
11-
| Fastify | :material-clock-outline: Planned |
12-
| Hono | :material-clock-outline: Planned |
13-
| NestJS | :material-clock-outline: Planned |
14-
| Nuxt | :material-clock-outline: Planned |
15-
16-
## Accurate Next.js response logging
17-
18-
Today, the Next.js adapter logs during middleware execution, so `status` and `duration` don't reflect the final route response (full explanation in the [Next.js guide](../guide/nextjs.md#timing-caveat)). Route-handler wrappers that log the *actual* final response are planned, mirroring how the Express adapter already works via `res.finish`.
10+
| Next.js | :material-check-circle:{ style="color: #4caf50" } Stable — middleware + [`withCipherLogger`](../guide/nextjs.md#accurate-route-handler-logging) |
11+
| Fastify | :material-check-circle:{ style="color: #4caf50" } Available (`cipher-logger/fastify`) |
12+
| Hono | :material-check-circle:{ style="color: #4caf50" } Available (`cipher-logger/hono`) |
13+
| NestJS | :material-check-circle:{ style="color: #4caf50" } Available — Express-compatible middleware (`cipher-logger/nest`) |
14+
| Nuxt | :material-check-circle:{ style="color: #4caf50" } Available — Node-style middleware (`cipher-logger/nuxt`) |
1915

2016
## Package structure
2117

22-
A restructure of `src/` into clearer `core/` and `adapters/` directories is planned, so that adding a new framework adapter is a self-contained addition rather than a change scattered across the package. Subpath exports (e.g. `cipher-logger/express`, `cipher-logger/next`) are also being considered, so importing one adapter doesn't pull in code for frameworks you don't use.
18+
Core and adapters live under `src/core/` and `src/adapters/`. Subpath exports (`cipher-logger/express`, `cipher-logger/next`, …) keep peer framework code out of the main entry until you import (or call) that adapter.
2319

2420
## Contributing to the roadmap
2521

26-
Have a framework you'd like supported, or a field you think should be built in? Open an issue on [GitHub](https://github.com/cipherunits/CipherLogger/issues) — see the [Contributing](../index.md) section of the README for the process.
22+
Have a framework you'd like supported, or a field you think should be built in? Open an issue on [GitHub](https://github.com/cipherunits/CipherLogger/issues).

‎docs/faq.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Not really — they solve different problems. Winston and Pino are general-purpo
66

77
## Why is `duration` wrong in my Next.js logs?
88

9-
This is expected with the current Next.js adapter — see the [timing caveat](guide/nextjs.md#timing-caveat). Middleware runs before your route handler, so the adapter can only measure its own execution time, not the full response. A fix (route-handler wrappers) is on the [Roadmap](advanced/roadmap.md).
9+
This is expected with `createNextMiddleware` / `cipher.next()` — see the [timing caveat](guide/nextjs.md#timing-caveat). Middleware runs before your route handler. Use [`withCipherLogger`](guide/nextjs.md#accurate-route-handler-logging) on App Router handlers for accurate status/duration.
1010

1111
## Can I use CipherLogger without Express or Next.js?
1212

@@ -22,7 +22,7 @@ Each enabled field does a small amount of extra work per request (header read, q
2222

2323
## Is CommonJS supported, or only ESM?
2424

25-
Both. CipherLogger ships dual ESM/CJS builds, so `import` and `require` both work out of the box.
25+
Both. CipherLogger ships dual ESM/CJS builds with an `exports` map, so `import` and `require` both resolve correctly — including subpaths like `cipher-logger/express`.
2626

2727
## Where do I report a bug or request a framework adapter?
2828

‎docs/getting-started/installation.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
## Peer dependencies
2424

25-
CipherLogger only requires the framework you actually use — everything else stays out of your `node_modules`.
25+
CipherLogger only requires the framework you actually use — everything else stays out of your `node_modules`. Import the matching subpath (for example `cipher-logger/express`) or call the lazy convenience method (`cipher.express()`).
2626

2727
=== "Express"
2828

@@ -36,14 +36,20 @@ CipherLogger only requires the framework you actually use — everything else st
3636
npm install next
3737
```
3838

39+
=== "Fastify / Hono / Nest / Nuxt"
40+
41+
```bash
42+
npm install fastify # or hono / @nestjs/common / nuxt
43+
```
44+
3945
If you only use the framework-agnostic [`Logger`](../reference/api.md#logger) class, no peer dependency is required at all.
4046

4147
## Requirements
4248

4349
| Requirement | Version |
4450
| ----------- | ------- |
4551
| Node.js | 18 or later |
46-
| TypeScript | 5.x (optional — CipherLogger ships its own `.d.ts` files) |
52+
| TypeScript | 5.x or 6.x (optional — CipherLogger ships its own `.d.ts` files) |
4753
| Module system | ESM and CommonJS both supported |
4854

4955
## Verifying the install

0 commit comments

Comments
 (0)