securenow 5.17.1 → 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.
- package/LICENSE +15 -0
- package/README.md +40 -243
- package/cli.js +455 -425
- package/console-instrumentation.js +136 -147
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +455 -1339
- package/docs/ARCHITECTURE.md +3 -3
- package/docs/AUTO-BODY-CAPTURE.md +1 -1
- package/docs/AUTO-SETUP.md +4 -4
- package/docs/AUTOMATIC-IP-CAPTURE.md +5 -5
- package/docs/BODY-CAPTURE-QUICKSTART.md +2 -2
- package/docs/CHANGELOG-NEXTJS.md +1 -1
- package/docs/CUSTOMER-GUIDE.md +16 -16
- package/docs/EASIEST-SETUP.md +5 -5
- package/docs/ENVIRONMENT-VARIABLES.md +652 -880
- package/docs/EXPRESS-BODY-CAPTURE.md +12 -13
- package/docs/EXPRESS-SETUP-GUIDE.md +720 -719
- package/docs/INDEX.md +4 -22
- package/docs/LOGGING-GUIDE.md +708 -701
- package/docs/LOGGING-QUICKSTART.md +239 -234
- package/docs/NEXTJS-BODY-CAPTURE.md +2 -2
- package/docs/NEXTJS-GUIDE.md +14 -14
- package/docs/NEXTJS-QUICKSTART.md +1 -1
- package/docs/NEXTJS-WRAPPER-APPROACH.md +1 -1
- package/docs/QUICKSTART-BODY-CAPTURE.md +2 -2
- package/docs/REDACTION-EXAMPLES.md +1 -1
- package/docs/REQUEST-BODY-CAPTURE.md +10 -19
- package/docs/VERCEL-OTEL-MIGRATION.md +3 -3
- package/examples/README.md +6 -6
- package/examples/instrumentation-with-auto-capture.ts +1 -1
- package/examples/nextjs-env-example.txt +2 -2
- package/examples/nextjs-instrumentation.js +1 -1
- package/examples/nextjs-instrumentation.ts +1 -1
- package/examples/nextjs-with-logging-example.md +6 -6
- package/examples/nextjs-with-options.ts +1 -1
- package/examples/test-nextjs-setup.js +1 -1
- package/nextjs-auto-capture.js +207 -199
- package/nextjs-middleware.js +181 -186
- package/nextjs-webpack-config.js +53 -88
- package/nextjs-wrapper.js +158 -158
- package/nextjs.d.ts +1 -1
- package/nextjs.js +135 -190
- package/package.json +45 -67
- package/postinstall.js +6 -6
- package/register.d.ts +1 -1
- package/register.js +4 -39
- package/tracing.d.ts +1 -2
- package/tracing.js +22 -287
- package/web-vite.mjs +156 -239
- package/CONSUMING-APPS-GUIDE.md +0 -455
- package/NPM_README.md +0 -1958
- package/SKILL-API.md +0 -600
- package/SKILL-CLI.md +0 -419
- package/cidr.js +0 -83
- package/cli/apps.js +0 -585
- package/cli/auth.js +0 -280
- package/cli/client.js +0 -115
- package/cli/config.js +0 -173
- package/cli/firewall.js +0 -100
- package/cli/fp.js +0 -638
- package/cli/init.js +0 -201
- package/cli/monitor.js +0 -545
- package/cli/run.js +0 -133
- package/cli/security.js +0 -1064
- package/cli/ui.js +0 -386
- package/docs/API-KEYS-GUIDE.md +0 -233
- package/docs/AUTO-SETUP-SUMMARY.md +0 -331
- package/docs/BODY-CAPTURE-FIX.md +0 -261
- package/docs/COMPLETION-REPORT.md +0 -408
- package/docs/FINAL-SOLUTION.md +0 -335
- package/docs/FIREWALL-GUIDE.md +0 -426
- package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
- package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
- package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
- package/docs/NUXT-GUIDE.md +0 -166
- package/docs/SOLUTION-SUMMARY.md +0 -312
- package/firewall-cloud.js +0 -212
- package/firewall-iptables.js +0 -139
- package/firewall-only.js +0 -38
- package/firewall-tcp.js +0 -74
- package/firewall.js +0 -720
- package/free-trial-banner.js +0 -174
- package/nuxt-server-plugin.mjs +0 -423
- package/nuxt.d.ts +0 -60
- package/nuxt.mjs +0 -75
- package/resolve-ip.js +0 -77
package/cli/init.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const ui = require('./ui');
|
|
6
|
-
|
|
7
|
-
const INSTRUMENTATION_JS = `export async function register() {
|
|
8
|
-
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
9
|
-
const { registerSecureNow } = require('securenow/nextjs');
|
|
10
|
-
registerSecureNow();
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
|
-
const INSTRUMENTATION_TS = `export async function register() {
|
|
16
|
-
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
17
|
-
const { registerSecureNow } = require('securenow/nextjs');
|
|
18
|
-
registerSecureNow();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
function detectProject(dir) {
|
|
24
|
-
const pkgPath = path.join(dir, 'package.json');
|
|
25
|
-
if (!fs.existsSync(pkgPath)) return { framework: 'unknown' };
|
|
26
|
-
|
|
27
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
28
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
29
|
-
|
|
30
|
-
if (allDeps.next) return { framework: 'nextjs', pkg, pkgPath, nextVersion: allDeps.next };
|
|
31
|
-
if (allDeps.nuxt) return { framework: 'nuxt', pkg, pkgPath };
|
|
32
|
-
if (allDeps.express) return { framework: 'express', pkg, pkgPath };
|
|
33
|
-
if (allDeps.fastify) return { framework: 'fastify', pkg, pkgPath };
|
|
34
|
-
if (allDeps.koa) return { framework: 'koa', pkg, pkgPath };
|
|
35
|
-
if (allDeps.hapi || allDeps['@hapi/hapi']) return { framework: 'hapi', pkg, pkgPath };
|
|
36
|
-
return { framework: 'node', pkg, pkgPath };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function findInstrumentationFile(dir) {
|
|
40
|
-
for (const name of ['instrumentation.ts', 'instrumentation.js', 'src/instrumentation.ts', 'src/instrumentation.js']) {
|
|
41
|
-
const p = path.join(dir, name);
|
|
42
|
-
if (fs.existsSync(p)) return p;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function findNextConfig(dir) {
|
|
48
|
-
for (const name of ['next.config.js', 'next.config.mjs', 'next.config.ts']) {
|
|
49
|
-
const p = path.join(dir, name);
|
|
50
|
-
if (fs.existsSync(p)) return p;
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function hasTypeScript(dir) {
|
|
56
|
-
return fs.existsSync(path.join(dir, 'tsconfig.json'));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function init(_args, flags) {
|
|
60
|
-
const dir = process.cwd();
|
|
61
|
-
const project = detectProject(dir);
|
|
62
|
-
|
|
63
|
-
ui.header('SecureNow Project Setup');
|
|
64
|
-
|
|
65
|
-
if (project.framework === 'unknown') {
|
|
66
|
-
ui.error('No package.json found. Run this command in your project root.');
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
ui.info(`Detected framework: ${ui.bold(project.framework)}`);
|
|
71
|
-
|
|
72
|
-
if (project.framework === 'nextjs') {
|
|
73
|
-
await initNextJs(dir, project, flags);
|
|
74
|
-
} else if (project.framework === 'nuxt') {
|
|
75
|
-
initNuxt(dir, project);
|
|
76
|
-
} else {
|
|
77
|
-
initNode(dir, project);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
initEnv(dir, flags);
|
|
81
|
-
|
|
82
|
-
console.log('');
|
|
83
|
-
ui.success('Setup complete! Run your app to verify.');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function initNextJs(dir, project, flags) {
|
|
87
|
-
const useTs = hasTypeScript(dir);
|
|
88
|
-
const ext = useTs ? 'ts' : 'js';
|
|
89
|
-
|
|
90
|
-
const existing = findInstrumentationFile(dir);
|
|
91
|
-
if (existing) {
|
|
92
|
-
ui.info(`instrumentation file already exists: ${path.relative(dir, existing)}`);
|
|
93
|
-
} else {
|
|
94
|
-
const filePath = path.join(dir, `instrumentation.${ext}`);
|
|
95
|
-
const content = useTs ? INSTRUMENTATION_TS : INSTRUMENTATION_JS;
|
|
96
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
97
|
-
ui.success(`Created instrumentation.${ext}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const configPath = findNextConfig(dir);
|
|
101
|
-
if (configPath) {
|
|
102
|
-
const content = fs.readFileSync(configPath, 'utf8');
|
|
103
|
-
if (content.includes('withSecureNow')) {
|
|
104
|
-
ui.info('next.config already uses withSecureNow — skipping');
|
|
105
|
-
} else if (content.includes('serverExternalPackages') && content.includes('securenow')) {
|
|
106
|
-
ui.info('next.config already externalizes securenow — skipping');
|
|
107
|
-
} else if (content.includes('serverComponentsExternalPackages') && content.includes('securenow')) {
|
|
108
|
-
ui.info('next.config already externalizes securenow — skipping');
|
|
109
|
-
} else {
|
|
110
|
-
ui.warn(`Update your ${path.basename(configPath)} to use withSecureNow():`);
|
|
111
|
-
console.log('');
|
|
112
|
-
console.log(` const { withSecureNow } = require('securenow/nextjs-webpack-config');`);
|
|
113
|
-
console.log(` module.exports = withSecureNow({ /* your config */ });`);
|
|
114
|
-
console.log('');
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
const newConfigPath = path.join(dir, 'next.config.js');
|
|
118
|
-
fs.writeFileSync(newConfigPath, `const { withSecureNow } = require('securenow/nextjs-webpack-config');\n\nmodule.exports = withSecureNow({\n reactStrictMode: true,\n});\n`, 'utf8');
|
|
119
|
-
ui.success('Created next.config.js with withSecureNow()');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function initNuxt(dir, project) {
|
|
124
|
-
const configPath = path.join(dir, 'nuxt.config.ts');
|
|
125
|
-
if (fs.existsSync(configPath)) {
|
|
126
|
-
const content = fs.readFileSync(configPath, 'utf8');
|
|
127
|
-
if (content.includes('securenow/nuxt')) {
|
|
128
|
-
ui.info('nuxt.config already references securenow/nuxt — skipping');
|
|
129
|
-
} else {
|
|
130
|
-
ui.warn('Add securenow/nuxt to your nuxt.config modules:');
|
|
131
|
-
console.log('');
|
|
132
|
-
console.log(" modules: ['securenow/nuxt'],");
|
|
133
|
-
console.log('');
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
ui.warn('Add securenow/nuxt to your nuxt.config modules array.');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function initNode(dir, project) {
|
|
141
|
-
const pkg = project.pkg;
|
|
142
|
-
const scripts = pkg.scripts || {};
|
|
143
|
-
|
|
144
|
-
const startScript = scripts.start || '';
|
|
145
|
-
if (startScript.includes('securenow/register')) {
|
|
146
|
-
ui.info('start script already uses securenow/register — skipping');
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (startScript) {
|
|
151
|
-
ui.warn('Update your start script to include the securenow preload:');
|
|
152
|
-
console.log('');
|
|
153
|
-
if (startScript.includes('node ')) {
|
|
154
|
-
const updated = startScript.replace('node ', 'node -r securenow/register ');
|
|
155
|
-
console.log(` "start": "${updated}"`);
|
|
156
|
-
} else {
|
|
157
|
-
console.log(` "start": "node -r securenow/register ${startScript.replace(/^node\s+/, '')}"`);
|
|
158
|
-
}
|
|
159
|
-
console.log('');
|
|
160
|
-
} else {
|
|
161
|
-
ui.warn('Add a start script with the securenow preload:');
|
|
162
|
-
console.log('');
|
|
163
|
-
console.log(' "start": "node -r securenow/register src/index.js"');
|
|
164
|
-
console.log('');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function initEnv(dir, flags) {
|
|
169
|
-
const envFiles = ['.env', '.env.local'];
|
|
170
|
-
let envPath = null;
|
|
171
|
-
|
|
172
|
-
for (const f of envFiles) {
|
|
173
|
-
const p = path.join(dir, f);
|
|
174
|
-
if (fs.existsSync(p)) {
|
|
175
|
-
const content = fs.readFileSync(p, 'utf8');
|
|
176
|
-
if (content.includes('SECURENOW_API_KEY')) {
|
|
177
|
-
ui.info(`SECURENOW_API_KEY already set in ${f}`);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
envPath = p;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (!envPath) envPath = path.join(dir, '.env.local');
|
|
186
|
-
|
|
187
|
-
const apiKey = flags.key || flags['api-key'] || '';
|
|
188
|
-
if (apiKey) {
|
|
189
|
-
const existing = fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf8') : '';
|
|
190
|
-
const sep = existing && !existing.endsWith('\n') ? '\n' : '';
|
|
191
|
-
fs.appendFileSync(envPath, `${sep}SECURENOW_API_KEY=${apiKey}\n`, 'utf8');
|
|
192
|
-
ui.success(`Added SECURENOW_API_KEY to ${path.basename(envPath)}`);
|
|
193
|
-
} else {
|
|
194
|
-
ui.warn(`Add your API key to ${path.basename(envPath)}:`);
|
|
195
|
-
console.log('');
|
|
196
|
-
console.log(' SECURENOW_API_KEY=snk_live_...');
|
|
197
|
-
console.log('');
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
module.exports = { init };
|