securenow 5.18.0 → 6.0.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.
Files changed (85) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +40 -239
  3. package/cli.js +455 -415
  4. package/console-instrumentation.js +136 -147
  5. package/docs/ALL-FRAMEWORKS-QUICKSTART.md +455 -1339
  6. package/docs/ARCHITECTURE.md +3 -3
  7. package/docs/AUTO-BODY-CAPTURE.md +1 -1
  8. package/docs/AUTO-SETUP.md +4 -4
  9. package/docs/AUTOMATIC-IP-CAPTURE.md +5 -5
  10. package/docs/BODY-CAPTURE-QUICKSTART.md +2 -2
  11. package/docs/CHANGELOG-NEXTJS.md +1 -1
  12. package/docs/CUSTOMER-GUIDE.md +16 -16
  13. package/docs/EASIEST-SETUP.md +5 -5
  14. package/docs/ENVIRONMENT-VARIABLES.md +652 -880
  15. package/docs/EXPRESS-BODY-CAPTURE.md +12 -13
  16. package/docs/EXPRESS-SETUP-GUIDE.md +720 -719
  17. package/docs/INDEX.md +4 -22
  18. package/docs/LOGGING-GUIDE.md +708 -701
  19. package/docs/LOGGING-QUICKSTART.md +239 -234
  20. package/docs/NEXTJS-BODY-CAPTURE.md +2 -2
  21. package/docs/NEXTJS-GUIDE.md +14 -14
  22. package/docs/NEXTJS-QUICKSTART.md +1 -1
  23. package/docs/NEXTJS-WRAPPER-APPROACH.md +1 -1
  24. package/docs/QUICKSTART-BODY-CAPTURE.md +2 -2
  25. package/docs/REDACTION-EXAMPLES.md +1 -1
  26. package/docs/REQUEST-BODY-CAPTURE.md +10 -19
  27. package/docs/VERCEL-OTEL-MIGRATION.md +3 -3
  28. package/examples/README.md +6 -6
  29. package/examples/instrumentation-with-auto-capture.ts +1 -1
  30. package/examples/nextjs-env-example.txt +2 -2
  31. package/examples/nextjs-instrumentation.js +1 -1
  32. package/examples/nextjs-instrumentation.ts +1 -1
  33. package/examples/nextjs-with-logging-example.md +6 -6
  34. package/examples/nextjs-with-options.ts +1 -1
  35. package/examples/test-nextjs-setup.js +1 -1
  36. package/nextjs-auto-capture.js +207 -199
  37. package/nextjs-middleware.js +181 -186
  38. package/nextjs-webpack-config.js +53 -88
  39. package/nextjs-wrapper.js +158 -158
  40. package/nextjs.d.ts +1 -1
  41. package/nextjs.js +135 -190
  42. package/package.json +45 -67
  43. package/postinstall.js +6 -6
  44. package/register.d.ts +1 -1
  45. package/register.js +4 -39
  46. package/tracing.d.ts +1 -2
  47. package/tracing.js +22 -287
  48. package/web-vite.mjs +156 -239
  49. package/CONSUMING-APPS-GUIDE.md +0 -455
  50. package/NPM_README.md +0 -1933
  51. package/SKILL-API.md +0 -600
  52. package/SKILL-CLI.md +0 -409
  53. package/cidr.js +0 -83
  54. package/cli/apps.js +0 -585
  55. package/cli/auth.js +0 -280
  56. package/cli/client.js +0 -115
  57. package/cli/config.js +0 -173
  58. package/cli/firewall.js +0 -100
  59. package/cli/fp.js +0 -638
  60. package/cli/init.js +0 -201
  61. package/cli/monitor.js +0 -440
  62. package/cli/run.js +0 -133
  63. package/cli/security.js +0 -1064
  64. package/cli/ui.js +0 -386
  65. package/docs/API-KEYS-GUIDE.md +0 -233
  66. package/docs/AUTO-SETUP-SUMMARY.md +0 -331
  67. package/docs/BODY-CAPTURE-FIX.md +0 -261
  68. package/docs/COMPLETION-REPORT.md +0 -408
  69. package/docs/FINAL-SOLUTION.md +0 -335
  70. package/docs/FIREWALL-GUIDE.md +0 -426
  71. package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
  72. package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
  73. package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
  74. package/docs/NUXT-GUIDE.md +0 -166
  75. package/docs/SOLUTION-SUMMARY.md +0 -312
  76. package/firewall-cloud.js +0 -212
  77. package/firewall-iptables.js +0 -139
  78. package/firewall-only.js +0 -38
  79. package/firewall-tcp.js +0 -74
  80. package/firewall.js +0 -720
  81. package/free-trial-banner.js +0 -174
  82. package/nuxt-server-plugin.mjs +0 -423
  83. package/nuxt.d.ts +0 -60
  84. package/nuxt.mjs +0 -75
  85. package/resolve-ip.js +0 -77
@@ -1,323 +0,0 @@
1
- # Next.js Body Capture - Choosing the Right Approach
2
-
3
- ## 🎯 Two Approaches Available
4
-
5
- SecureNow offers two ways to capture request bodies in Next.js:
6
-
7
- 1. **Wrapper Approach** (Recommended ✅)
8
- 2. **Middleware Approach** (Use with caution ⚠️)
9
-
10
- ---
11
-
12
- ## ✅ Wrapper Approach (RECOMMENDED)
13
-
14
- ### How It Works
15
-
16
- Wrap individual API route handlers to capture bodies **inside the handler**:
17
-
18
- ```typescript
19
- import { withSecureNow } from 'securenow/nextjs-wrapper';
20
-
21
- export const POST = withSecureNow(async (request: Request) => {
22
- const body = await request.json();
23
- return Response.json({ success: true });
24
- });
25
- ```
26
-
27
- ### ✅ Pros
28
-
29
- - **Zero middleware conflicts** - Doesn't interfere with NextAuth or other middleware
30
- - **Never blocks requests** - Runs after routing is complete
31
- - **Per-route control** - Wrap only the routes you need
32
- - **Non-invasive** - Your middleware stays unchanged
33
- - **Safe** - Runs inside your handler, can't prevent handler execution
34
- - **Background capture** - Doesn't delay responses
35
-
36
- ### ❌ Cons
37
-
38
- - Requires wrapping each route individually (but only the ones you want!)
39
- - Slightly more verbose (one extra line per route)
40
-
41
- ### When to Use
42
-
43
- - ✅ You have NextAuth or other middleware
44
- - ✅ You want zero conflicts
45
- - ✅ You want fine-grained control
46
- - ✅ You prioritize reliability
47
- - ✅ **This is the recommended approach for most users**
48
-
49
- ### Setup
50
-
51
- **Step 1:** Enable in .env.local
52
- ```bash
53
- SECURENOW_CAPTURE_BODY=1
54
- ```
55
-
56
- **Step 2:** Wrap your API routes
57
- ```typescript
58
- // app/api/login/route.ts
59
- import { withSecureNow } from 'securenow/nextjs-wrapper';
60
-
61
- export const POST = withSecureNow(async (request: Request) => {
62
- const body = await request.json();
63
- // Your logic...
64
- return Response.json({ success: true });
65
- });
66
- ```
67
-
68
- **That's it!** No middleware.ts needed.
69
-
70
- 📚 **Full guide:** See `NEXTJS-WRAPPER-APPROACH.md`
71
-
72
- ---
73
-
74
- ## ⚠️ Middleware Approach (Use with Caution)
75
-
76
- ### How It Works
77
-
78
- Export SecureNow's middleware to capture bodies **before your handlers**:
79
-
80
- ```typescript
81
- // middleware.ts
82
- export { middleware } from 'securenow/nextjs-middleware';
83
-
84
- export const config = {
85
- matcher: '/api/:path*',
86
- };
87
- ```
88
-
89
- ### ✅ Pros
90
-
91
- - One-time setup (no per-route wrapping)
92
- - Applies to all routes automatically
93
-
94
- ### ❌ Cons
95
-
96
- - **Can conflict with NextAuth** and other middleware
97
- - **May block requests** from reaching handlers
98
- - **All-or-nothing** - applies to all matched routes
99
- - **Runs before routing** - can interfere with request flow
100
- - **May cause "Response body disturbed or locked" errors**
101
-
102
- ### When to Use
103
-
104
- - You have no other middleware
105
- - You want to capture ALL routes
106
- - You're okay with potential conflicts
107
- - **Not recommended if you use NextAuth or have complex middleware**
108
-
109
- ### Known Issues
110
-
111
- **Conflicts with NextAuth:**
112
- ```typescript
113
- // ❌ This can cause conflicts
114
- export { middleware } from 'securenow/nextjs-middleware';
115
-
116
- // If you also use NextAuth, you'll need complex middleware composition
117
- ```
118
-
119
- **Solution:** Use the wrapper approach instead!
120
-
121
- 📚 **Full guide:** See `NEXTJS-BODY-CAPTURE.md` (but consider wrapper approach first)
122
-
123
- ---
124
-
125
- ## 🔄 Comparison Table
126
-
127
- | Feature | Wrapper Approach | Middleware Approach |
128
- |---------|-----------------|---------------------|
129
- | **Setup complexity** | Per-route wrapping | One-time setup |
130
- | **Middleware conflicts** | ✅ None | ⚠️ Possible |
131
- | **NextAuth compatibility** | ✅ Perfect | ❌ Can conflict |
132
- | **Request blocking** | ✅ Never | ⚠️ Possible |
133
- | **Control granularity** | ✅ Per-route | ❌ All-or-nothing |
134
- | **Error impact** | ✅ Isolated | ⚠️ Can block all routes |
135
- | **Recommended for** | ✅ Most users | ⚠️ Simple apps only |
136
-
137
- ---
138
-
139
- ## 🎯 Our Recommendation
140
-
141
- ### For Most Users (Especially with NextAuth)
142
-
143
- **Use the Wrapper Approach:**
144
-
145
- ```typescript
146
- // middleware.ts - Your auth logic (no securenow!)
147
- export async function middleware(request) {
148
- // Just your middleware - no securenow imports
149
- const token = await getToken({ req: request });
150
- if (!token) return NextResponse.redirect('/login');
151
- return NextResponse.next();
152
- }
153
-
154
- // app/api/protected/route.ts - Wrap individual routes
155
- import { withSecureNow } from 'securenow/nextjs-wrapper';
156
-
157
- export const POST = withSecureNow(async (request: Request) => {
158
- // Your handler - no conflicts!
159
- const body = await request.json();
160
- return Response.json({ success: true });
161
- });
162
- ```
163
-
164
- **Why?**
165
- - ✅ Zero conflicts
166
- - ✅ Your middleware stays clean
167
- - ✅ Per-route control
168
- - ✅ Never blocks requests
169
-
170
- ### For Simple Apps (No Other Middleware)
171
-
172
- **You can use Middleware Approach:**
173
-
174
- ```typescript
175
- // middleware.ts
176
- export { middleware } from 'securenow/nextjs-middleware';
177
-
178
- export const config = {
179
- matcher: '/api/:path*',
180
- };
181
- ```
182
-
183
- **Why?**
184
- - ✅ One-time setup
185
- - ✅ Auto-applies to all routes
186
- - ⚠️ But be aware of potential conflicts if you add other middleware later
187
-
188
- ---
189
-
190
- ## 📊 Real-World Scenarios
191
-
192
- ### Scenario 1: NextAuth + SecureNow
193
-
194
- **❌ Middleware Approach - Can Cause Issues:**
195
- ```typescript
196
- // middleware.ts
197
- import { getToken } from 'next-auth/jwt';
198
- import { middleware as securenowMiddleware } from 'securenow/nextjs-middleware';
199
-
200
- export async function middleware(request) {
201
- // Complex composition needed - prone to conflicts
202
- await securenowMiddleware(request);
203
- const token = await getToken({ req: request });
204
- // ...
205
- }
206
- ```
207
-
208
- **✅ Wrapper Approach - Clean & Safe:**
209
- ```typescript
210
- // middleware.ts - Just NextAuth
211
- export async function middleware(request) {
212
- const token = await getToken({ req: request });
213
- if (!token) return NextResponse.redirect('/login');
214
- return NextResponse.next();
215
- }
216
-
217
- // app/api/*/route.ts - Add SecureNow per route
218
- import { withSecureNow } from 'securenow/nextjs-wrapper';
219
- export const POST = withSecureNow(handler);
220
- ```
221
-
222
- ### Scenario 2: Rate Limiting + SecureNow
223
-
224
- **❌ Middleware Approach:**
225
- ```typescript
226
- // Multiple middleware = conflicts
227
- ```
228
-
229
- **✅ Wrapper Approach:**
230
- ```typescript
231
- // middleware.ts - Just rate limiting
232
- export async function middleware(request) {
233
- await checkRateLimit(request);
234
- return NextResponse.next();
235
- }
236
-
237
- // routes - Add SecureNow
238
- export const POST = withSecureNow(handler);
239
- ```
240
-
241
- ### Scenario 3: Simple API (No Other Middleware)
242
-
243
- **✅ Either Approach Works:**
244
-
245
- **Option A - Wrapper:**
246
- ```typescript
247
- export const POST = withSecureNow(handler);
248
- ```
249
-
250
- **Option B - Middleware:**
251
- ```typescript
252
- export { middleware } from 'securenow/nextjs-middleware';
253
- ```
254
-
255
- Both work fine when you have no other middleware!
256
-
257
- ---
258
-
259
- ## 🚀 Migration Guide
260
-
261
- ### From Middleware to Wrapper
262
-
263
- **Before:**
264
- ```typescript
265
- // middleware.ts
266
- export { middleware } from 'securenow/nextjs-middleware';
267
- export const config = { matcher: '/api/:path*' };
268
- ```
269
-
270
- **After:**
271
- ```typescript
272
- // middleware.ts - Delete securenow import!
273
- // (Keep your other middleware like NextAuth)
274
-
275
- // app/api/login/route.ts
276
- import { withSecureNow } from 'securenow/nextjs-wrapper';
277
- export const POST = withSecureNow(async (request) => {
278
- // Your handler
279
- });
280
-
281
- // app/api/register/route.ts
282
- import { withSecureNow } from 'securenow/nextjs-wrapper';
283
- export const POST = withSecureNow(async (request) => {
284
- // Your handler
285
- });
286
- ```
287
-
288
- **Result:** No more conflicts! 🎉
289
-
290
- ---
291
-
292
- ## ✅ Summary
293
-
294
- ### Quick Decision Guide
295
-
296
- **Do you have NextAuth or other middleware?**
297
- - Yes → Use **Wrapper Approach** ✅
298
- - No → Either works, but wrapper is safer
299
-
300
- **Do you want per-route control?**
301
- - Yes → Use **Wrapper Approach** ✅
302
- - No → Middleware works
303
-
304
- **Do you prioritize zero conflicts?**
305
- - Yes → Use **Wrapper Approach** ✅
306
- - Not critical → Middleware works
307
-
308
- **Do you experience "Response body disturbed" errors?**
309
- - Yes → Switch to **Wrapper Approach** ✅
310
-
311
- ### Bottom Line
312
-
313
- **For 90% of users:** Use the **Wrapper Approach**
314
-
315
- It's safer, more flexible, and conflict-free!
316
-
317
- 📚 **Full documentation:**
318
- - Wrapper: `NEXTJS-WRAPPER-APPROACH.md`
319
- - Middleware: `NEXTJS-BODY-CAPTURE.md`
320
-
321
-
322
-
323
-