|
1 | | -import { protect } from '../src/index'; |
| 1 | +/** |
| 2 | + * Node9 SDK — protect() example |
| 3 | + * |
| 4 | + * There are two ways Node9 protects you: |
| 5 | + * |
| 6 | + * 1. CLI Proxy (automatic) — Node9 wraps Claude Code / Gemini CLI at the |
| 7 | + * process level and intercepts every tool call automatically. No code needed. |
| 8 | + * |
| 9 | + * 2. SDK / protect() (manual) — for developers building their own Node.js apps |
| 10 | + * with an AI SDK (Anthropic, LangChain, etc.). Wrap any dangerous function |
| 11 | + * with `protect()` and Node9 will intercept it before execution, showing a |
| 12 | + * native approval popup and applying your security policy. |
| 13 | + * |
| 14 | + * Usage: |
| 15 | + * npm install @node9/proxy |
| 16 | + * npx ts-node examples/demo.ts |
| 17 | + */ |
| 18 | +import { protect } from '@node9/proxy'; |
2 | 19 | import chalk from 'chalk'; |
3 | 20 |
|
4 | 21 | async function main() { |
5 | 22 | const deleteDatabase = async (name: string) => { |
6 | 23 | console.log(chalk.green(`✅ Success: Database ${name} has been deleted.`)); |
7 | 24 | }; |
8 | 25 |
|
9 | | - // Wrap the dangerous function |
| 26 | + // Wrap the dangerous function — Node9 will intercept it before it runs |
10 | 27 | const secureDelete = protect('aws.rds.delete_database', deleteDatabase); |
11 | 28 |
|
12 | 29 | console.log(chalk.cyan("🤖 AI Agent: 'I am going to clean up the production DB...'")); |
13 | 30 |
|
14 | 31 | try { |
| 32 | + // Node9 will show a native popup asking you to Allow / Block this action. |
| 33 | + // If you click Block (or the policy denies it), an error is thrown. |
15 | 34 | await secureDelete('production-db-v1'); |
16 | 35 | } catch (err: unknown) { |
17 | 36 | const msg = err instanceof Error ? err.message : String(err); |
18 | | - console.log(chalk.yellow(`\n🛡️ Node9 caught it: ${msg}`)); |
| 37 | + console.log(chalk.yellow(`\n🛡️ Node9 blocked it: ${msg}`)); |
19 | 38 | } |
20 | 39 | } |
21 | 40 |
|
|
0 commit comments