securenow 7.6.7 → 7.6.9

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 (67) hide show
  1. package/NPM_README.md +13 -13
  2. package/README.md +21 -37
  3. package/app-config.js +5 -3
  4. package/cli/config.js +4 -3
  5. package/cli/diagnostics.js +54 -15
  6. package/cli/run.js +40 -11
  7. package/firewall-only.js +1 -1
  8. package/mcp/catalog.js +1 -1
  9. package/nextjs-webpack-config.js +3 -15
  10. package/nextjs.js +21 -23
  11. package/nuxt-server-plugin.mjs +20 -10
  12. package/package.json +23 -33
  13. package/register.js +1 -1
  14. package/tracing.js +17 -7
  15. package/web-vite.mjs +23 -13
  16. package/CONSUMING-APPS-GUIDE.md +0 -463
  17. package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
  18. package/docs/API-KEYS-GUIDE.md +0 -278
  19. package/docs/ARCHITECTURE.md +0 -408
  20. package/docs/AUTO-BODY-CAPTURE.md +0 -412
  21. package/docs/AUTO-SETUP-SUMMARY.md +0 -331
  22. package/docs/AUTO-SETUP.md +0 -419
  23. package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
  24. package/docs/BODY-CAPTURE-FIX.md +0 -261
  25. package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
  26. package/docs/CHANGELOG-NEXTJS.md +0 -235
  27. package/docs/COMPLETION-REPORT.md +0 -408
  28. package/docs/CUSTOMER-GUIDE.md +0 -364
  29. package/docs/EASIEST-SETUP.md +0 -342
  30. package/docs/ENVIRONMENT-VARIABLES.md +0 -166
  31. package/docs/ENVIRONMENTS.md +0 -60
  32. package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
  33. package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
  34. package/docs/FINAL-SOLUTION.md +0 -335
  35. package/docs/FIREWALL-GUIDE.md +0 -440
  36. package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
  37. package/docs/INDEX.md +0 -222
  38. package/docs/LOGGING-GUIDE.md +0 -704
  39. package/docs/LOGGING-QUICKSTART.md +0 -221
  40. package/docs/MCP-GUIDE.md +0 -58
  41. package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
  42. package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
  43. package/docs/NEXTJS-GUIDE.md +0 -392
  44. package/docs/NEXTJS-QUICKSTART.md +0 -83
  45. package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
  46. package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
  47. package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
  48. package/docs/NUXT-GUIDE.md +0 -173
  49. package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
  50. package/docs/REDACTION-EXAMPLES.md +0 -484
  51. package/docs/REQUEST-BODY-CAPTURE.md +0 -587
  52. package/docs/SOLUTION-SUMMARY.md +0 -312
  53. package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
  54. package/examples/README.md +0 -265
  55. package/examples/express-with-logging.js +0 -137
  56. package/examples/instrumentation-with-auto-capture.ts +0 -41
  57. package/examples/next.config.js +0 -37
  58. package/examples/nextjs-api-route-with-body-capture.ts +0 -54
  59. package/examples/nextjs-env-example.txt +0 -32
  60. package/examples/nextjs-instrumentation.js +0 -36
  61. package/examples/nextjs-instrumentation.ts +0 -36
  62. package/examples/nextjs-middleware.js +0 -37
  63. package/examples/nextjs-middleware.ts +0 -37
  64. package/examples/nextjs-with-logging-example.md +0 -301
  65. package/examples/nextjs-with-options.ts +0 -36
  66. package/examples/test-nextjs-setup.js +0 -70
  67. package/postinstall.js +0 -296
@@ -1,463 +0,0 @@
1
- # How to Use SecureNow Logging in Your App
2
-
3
- **Current setup model:** Logging, body capture, multipart capture, and firewall setup are driven by `.securenow/credentials.json` written by `npx securenow login` and completed by `npx securenow init`. For production, generate a tokenless file with `npx securenow credentials runtime --env production` and mount/copy it as `.securenow/credentials.json`. Older env-var snippets in this guide are legacy fallbacks only.
4
-
5
- This guide is for developers who want to add the `securenow` package to their applications to enable logging to SecureNow or any OTLP-compatible backend.
6
-
7
- **Since v7.0.0:** Logging, body capture, and multipart capture are **on by default**. Credentials come from `.securenow/credentials.json` written by `npx securenow login` — no env vars required for local dev. Set `SECURENOW_LOGGING_ENABLED=0` to disable logging if you don't want it.
8
-
9
- ---
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm install securenow
15
- npx securenow login # pick/create your app in the browser
16
- ```
17
-
18
- That's it for local dev. The `login` step writes `.securenow/credentials.json` (gitignored automatically) and the SDK reads it at boot.
19
-
20
- For CI / Docker / production where you can't run the browser flow, set env vars — see "Step 1 (alternative)" below.
21
-
22
- ---
23
-
24
- ## Setup Steps
25
-
26
- ### Step 1 (alternative) — Environment variables for CI / Docker / prod
27
-
28
- If `npx securenow login` isn't an option on the target machine, set:
29
-
30
- ```bash
31
- # App routing key (UUID) — from `npx securenow apps`
32
- SECURENOW_APPID=your-app-key-uuid
33
-
34
- # OTLP collector (defaults to https://freetrial.securenow.ai:4318)
35
- SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
36
-
37
- # Optional — defaults are already on:
38
- # SECURENOW_LOGGING_ENABLED=0 # to disable console-log forwarding
39
- # SECURENOW_CAPTURE_BODY=0 # to disable body capture (required for Fastify/Hapi/Hono)
40
- # OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-key"
41
- ```
42
-
43
- Env vars always take precedence over the credentials file.
44
-
45
- ---
46
-
47
- ### Step 2: Choose Your Integration Method
48
-
49
- You have **three options** to integrate logging:
50
-
51
- #### **Option A: Automatic Console Instrumentation** (Recommended - Easiest)
52
-
53
- Since **v5.6.0**, when `SECURENOW_LOGGING_ENABLED=1`, all `console.log()`, `console.info()`, `console.warn()`, `console.error()`, and `console.debug()` calls are **automatically** captured and sent as OTLP log records. No extra require is needed.
54
-
55
- **Add to your main application file:**
56
-
57
- ```javascript
58
- // At the very top of your app.js, index.js, server.js, or main.ts
59
- require('securenow/register');
60
-
61
- // That's it! With SECURENOW_LOGGING_ENABLED=1, all console calls become OTLP logs.
62
- console.log('Application started');
63
- console.error('An error occurred', { userId: 123, details: 'Something went wrong' });
64
- console.warn('Warning message');
65
- ```
66
-
67
- **Or using NODE_OPTIONS (no code changes needed):**
68
-
69
- ```bash
70
- NODE_OPTIONS="-r securenow/register" node app.js
71
- ```
72
-
73
- ---
74
-
75
- #### **Option B: Direct Logger API**
76
-
77
- For more control over logging, use the OpenTelemetry logger API directly:
78
-
79
- ```javascript
80
- require('securenow/register');
81
- const { getLogger } = require('securenow/tracing');
82
-
83
- // Get a logger instance
84
- const logger = getLogger('my-service', '1.0.0');
85
-
86
- // Emit structured logs
87
- logger.emit({
88
- severityNumber: 9, // INFO level
89
- severityText: 'INFO',
90
- body: 'User logged in',
91
- attributes: {
92
- userId: 123,
93
- username: 'john',
94
- ip: '192.168.1.1',
95
- },
96
- });
97
- ```
98
-
99
- **Severity Levels:**
100
- - `5` = DEBUG
101
- - `9` = INFO
102
- - `13` = WARN
103
- - `17` = ERROR
104
-
105
- ---
106
-
107
- #### **Option C: Custom Logger Wrapper**
108
-
109
- Create your own logger wrapper for cleaner API:
110
-
111
- ```javascript
112
- // logger.js
113
- require('securenow/register');
114
- const { getLogger } = require('securenow/tracing');
115
-
116
- const logger = getLogger('app-logger', '1.0.0');
117
-
118
- const SeverityNumber = {
119
- DEBUG: 5,
120
- INFO: 9,
121
- WARN: 13,
122
- ERROR: 17,
123
- };
124
-
125
- function log(level, message, attributes = {}) {
126
- if (logger) {
127
- logger.emit({
128
- severityNumber: SeverityNumber[level],
129
- severityText: level,
130
- body: message,
131
- attributes,
132
- });
133
- }
134
- console.log(`[${level}] ${message}`, attributes);
135
- }
136
-
137
- module.exports = {
138
- debug: (msg, attrs) => log('DEBUG', msg, attrs),
139
- info: (msg, attrs) => log('INFO', msg, attrs),
140
- warn: (msg, attrs) => log('WARN', msg, attrs),
141
- error: (msg, attrs) => log('ERROR', msg, attrs),
142
- };
143
- ```
144
-
145
- **Usage:**
146
-
147
- ```javascript
148
- const logger = require('./logger');
149
-
150
- logger.info('User signed up', { userId: 456, email: 'user@example.com' });
151
- logger.error('Payment failed', { orderId: 789, amount: 99.99 });
152
- ```
153
-
154
- ---
155
-
156
- ## Framework-Specific Setup
157
-
158
- ### Express.js
159
-
160
- ```javascript
161
- // app.js
162
- require('securenow/register');
163
-
164
- const express = require('express');
165
- const app = express();
166
-
167
- app.get('/', (req, res) => {
168
- console.log('Home page accessed');
169
- res.send('Hello World');
170
- });
171
-
172
- app.listen(3000, () => {
173
- console.log('Server running on port 3000');
174
- });
175
- ```
176
-
177
- **Run:**
178
- ```bash
179
- SECURENOW_LOGGING_ENABLED=1 SECURENOW_APPID=express-app node app.js
180
- ```
181
-
182
- ---
183
-
184
- ### Next.js (App Router)
185
-
186
- **1. Run `npx securenow init`** or create `instrumentation.ts` in your project root:
187
-
188
- ```typescript
189
- // instrumentation.ts
190
- export async function register() {
191
- if (process.env.NEXT_RUNTIME === 'nodejs') {
192
- const { registerSecureNow } = require('securenow/nextjs');
193
- registerSecureNow();
194
- }
195
- }
196
- ```
197
-
198
- **2. Update `next.config.js` with `withSecureNow()`:**
199
-
200
- ```javascript
201
- const { withSecureNow } = require('securenow/nextjs-webpack-config');
202
-
203
- module.exports = withSecureNow({
204
- // your existing config
205
- });
206
- ```
207
-
208
- This auto-detects Next.js 14 vs 15 and sets the correct `serverExternalPackages` / `experimental.serverComponentsExternalPackages` config.
209
-
210
- **3. Add to `.env.local`:**
211
-
212
- ```bash
213
- SECURENOW_LOGGING_ENABLED=1
214
- SECURENOW_APPID=my-nextjs-app
215
- SECURENOW_INSTANCE=http://localhost:4318
216
- SECURENOW_API_KEY=snk_live_abc123...
217
- ```
218
-
219
- **4. Use in API routes:**
220
-
221
- ```typescript
222
- // app/api/users/route.ts
223
- export async function GET() {
224
- console.log('GET /api/users called');
225
- const users = await fetchUsers();
226
- console.info('Users fetched', { count: users.length });
227
- return Response.json(users);
228
- }
229
- ```
230
-
231
- ---
232
-
233
- ### Fastify
234
-
235
- ```javascript
236
- // server.js
237
- require('securenow/register');
238
-
239
- const fastify = require('fastify')();
240
-
241
- fastify.get('/', async () => {
242
- console.log('Root endpoint called');
243
- return { hello: 'world' };
244
- });
245
-
246
- fastify.listen({ port: 3000 });
247
- ```
248
-
249
- ---
250
-
251
- ### NestJS
252
-
253
- ```typescript
254
- // main.ts
255
- require('securenow/register');
256
-
257
- import { NestFactory } from '@nestjs/core';
258
- import { AppModule } from './app.module';
259
-
260
- async function bootstrap() {
261
- const app = await NestFactory.create(AppModule);
262
- console.log('NestJS application starting');
263
- await app.listen(3000);
264
- }
265
-
266
- bootstrap();
267
- ```
268
-
269
- ---
270
-
271
- ## Verification
272
-
273
- After starting your app, you should see:
274
-
275
- ```
276
- [securenow] OTel SDK started → http://your-otlp-collector:4318/v1/traces
277
- [securenow] 📋 Logging: ENABLED → http://your-otlp-collector:4318/v1/logs
278
- [securenow] Console instrumentation installed
279
- ```
280
-
281
- ---
282
-
283
- ## View Logs in SecureNow
284
-
285
- 1. Open your SecureNow dashboard
286
- 2. Go to **Logs** section
287
- 3. Filter by `service.name = my-app-name`
288
- 4. See all your logs with:
289
- - Automatic severity levels
290
- - Structured attributes
291
- - Trace correlation
292
-
293
- ---
294
-
295
- ## Common Issues
296
-
297
- ### Logs Not Appearing
298
-
299
- **Check 1:** Verify `SECURENOW_LOGGING_ENABLED=1` is set
300
-
301
- ```bash
302
- echo $SECURENOW_LOGGING_ENABLED # Should output: 1
303
- ```
304
-
305
- **Check 2:** Verify endpoint is correct
306
-
307
- ```bash
308
- # Self-hosted OTLP collector
309
- export SECURENOW_INSTANCE=http://localhost:4318
310
-
311
- # Managed OTLP (example)
312
- export SECURENOW_INSTANCE=https://ingest.<region>.securenow.ai:443
313
- export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your-key>"
314
- ```
315
-
316
- **Check 3:** Enable debug logging
317
-
318
- ```bash
319
- export OTEL_LOG_LEVEL=debug
320
- node app.js
321
- ```
322
-
323
- ---
324
-
325
- ### Console Instrumentation Not Working
326
-
327
- Make sure the load order is correct:
328
-
329
- ```javascript
330
- // ✅ Correct — register must be first
331
- require('securenow/register');
332
- const express = require('express');
333
-
334
- // ❌ Wrong
335
- const express = require('express');
336
- require('securenow/register');
337
- ```
338
-
339
- ---
340
-
341
- ### Logger Returns Null
342
-
343
- This happens when logging is disabled:
344
-
345
- ```javascript
346
- const { getLogger } = require('securenow/tracing');
347
- const logger = getLogger('test');
348
-
349
- if (!logger) {
350
- console.log('Set SECURENOW_LOGGING_ENABLED=1 to enable logging');
351
- }
352
- ```
353
-
354
- ---
355
-
356
- ## Environment Variables Reference
357
-
358
- ```bash
359
- # Logging
360
- SECURENOW_LOGGING_ENABLED=1 # Enable/disable logging (default: 1)
361
-
362
- # Connection
363
- SECURENOW_INSTANCE=http://localhost:4318 # OTLP endpoint
364
- OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=... # Override logs endpoint
365
-
366
- # Authentication
367
- OTEL_EXPORTER_OTLP_HEADERS="x-api-key=KEY"
368
-
369
- # Service Info
370
- SECURENOW_APPID=my-app # Your app name
371
- OTEL_SERVICE_NAME=my-app # Alternative
372
-
373
- # Request Body Capture
374
- SECURENOW_CAPTURE_BODY=1 # Capture JSON/form/GraphQL request bodies
375
- SECURENOW_MAX_BODY_SIZE=10240 # Max body size in bytes (default: 10KB)
376
- SECURENOW_SENSITIVE_FIELDS="field1,field2" # Additional fields to redact
377
-
378
- # Multipart Body Capture (v5.8.0+)
379
- SECURENOW_CAPTURE_MULTIPART=1 # Capture multipart field values & file metadata (streaming)
380
-
381
- # Debugging
382
- OTEL_LOG_LEVEL=debug # Enable debug output
383
- ```
384
-
385
- ---
386
-
387
- ## Best Practices
388
-
389
- 1. **Use Structured Logging** - Pass objects with meaningful attributes
390
- ```javascript
391
- console.log('User action', { userId: 123, action: 'login' });
392
- ```
393
-
394
- 2. **Choose Appropriate Severity Levels**
395
- - `console.log()` / `console.info()` - Normal operations
396
- - `console.warn()` - Warnings, deprecations
397
- - `console.error()` - Errors, exceptions
398
-
399
- 3. **Include Context** - Add userId, requestId, etc. to log attributes
400
-
401
- 4. **Don't Log Sensitive Data** - SecureNow automatically redacts passwords, tokens, etc.
402
-
403
- 5. **Use Different Loggers for Different Modules**
404
- ```javascript
405
- const authLogger = getLogger('auth-service');
406
- const dbLogger = getLogger('database');
407
- ```
408
-
409
- ---
410
-
411
- ---
412
-
413
- ## Firewall — Automatic IP Blocking
414
-
415
- If you use the SecureNow blocklist to block malicious IPs, the firewall module can enforce that blocklist directly in your app with zero code changes.
416
-
417
- ### Enable It
418
-
419
- Add your API key to `.env`:
420
-
421
- ```bash
422
- SECURENOW_API_KEY=snk_live_abc123...
423
- ```
424
-
425
- The firewall activates automatically on startup and syncs the blocklist using a version-based protocol:
426
-
427
- ```
428
- [securenow] Firewall: ENABLED
429
- [securenow] Firewall: Layer 1 (HTTP 403) active
430
- [securenow] Firewall: synced 142 blocked IPs (138 exact + 4 CIDR ranges)
431
- ```
432
-
433
- Blocked IPs get a 403 Forbidden with a full security alert page. Changes propagate in 10-15 seconds. No code changes needed -- works with Express, Next.js, Nuxt, Fastify, and all Node.js frameworks.
434
-
435
- **Firewall-only mode** (no tracing overhead):
436
-
437
- ```bash
438
- node -r securenow/firewall-only app.js
439
- ```
440
-
441
- See the [Firewall Guide](./docs/FIREWALL-GUIDE.md) for advanced layers (TCP blocking, iptables, Cloud WAF).
442
-
443
- ---
444
-
445
- ## Complete Documentation
446
-
447
- - [Firewall Guide](./docs/FIREWALL-GUIDE.md)
448
- - [API Keys Guide](./docs/API-KEYS-GUIDE.md)
449
- - [Logging Quick Start](./docs/LOGGING-QUICKSTART.md)
450
- - [Logging Complete Guide](./docs/LOGGING-GUIDE.md)
451
- - [All Examples](./examples/)
452
-
453
- ---
454
-
455
- ## Support
456
-
457
- - **Documentation**: [Full Docs](./docs/INDEX.md)
458
- - **Website**: [securenow.ai](http://securenow.ai/)
459
- - **Issues**: GitHub Issues
460
-
461
- ---
462
-
463
- **That's it!** Your app is now sending logs to your OTLP backend (for example SecureNow). 🎉