@cdot65/prisma-airs-sdk 0.1.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/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # prisma-airs-sdk
2
+
3
+ TypeScript SDK for Palo Alto Networks **AI Runtime Security (AIRS)**. API-compatible with the official [Python `pan-aisecurity` SDK](https://pypi.org/project/pan-aisecurity/).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cdot65/prisma-airs-sdk
9
+ ```
10
+
11
+ Requires Node.js 18+.
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { init, Scanner, Content } from '@cdot65/prisma-airs-sdk';
17
+
18
+ // Initialize (mirrors Python's aisecurity.init())
19
+ init({ apiKey: 'YOUR_API_KEY' });
20
+
21
+ const scanner = new Scanner();
22
+ const content = new Content({
23
+ prompt: 'What is the capital of France?',
24
+ response: 'The capital of France is Paris.',
25
+ });
26
+
27
+ const result = await scanner.syncScan({ profile_name: 'my-profile' }, content);
28
+
29
+ console.log(result.category); // "benign" | "malicious"
30
+ console.log(result.action); // "allow" | "block"
31
+ ```
32
+
33
+ ## Initialization
34
+
35
+ ```ts
36
+ import { init } from '@cdot65/prisma-airs-sdk';
37
+
38
+ init({
39
+ apiKey: 'your-api-key', // or set PANW_AI_SEC_API_KEY env var
40
+ apiToken: 'your-bearer-token', // or set PANW_AI_SEC_API_TOKEN env var
41
+ apiEndpoint: 'https://...', // optional, defaults to production
42
+ numRetries: 3, // optional, 0-5, default 5
43
+ });
44
+ ```
45
+
46
+ At least one of `apiKey` or `apiToken` must be provided (directly or via environment variables).
47
+
48
+ ## Scanner Methods
49
+
50
+ | Method | Description |
51
+ | ------------------------------------- | ------------------------------------------ |
52
+ | `syncScan(aiProfile, content, opts?)` | Synchronous inline scan |
53
+ | `asyncScan(scanObjects)` | Batch async scan (up to 5) |
54
+ | `queryByScanIds(scanIds)` | Get results by scan IDs (up to 5) |
55
+ | `queryByReportIds(reportIds)` | Get threat reports by report IDs (up to 5) |
56
+
57
+ ### Sync Scan
58
+
59
+ ```ts
60
+ const result = await scanner.syncScan(
61
+ { profile_name: 'my-profile' },
62
+ new Content({ prompt: 'user input', response: 'model output' }),
63
+ {
64
+ trId: 'transaction-123',
65
+ sessionId: 'session-456',
66
+ metadata: { app_name: 'my-app', ai_model: 'gpt-4' },
67
+ },
68
+ );
69
+ ```
70
+
71
+ ### Async Scan
72
+
73
+ ```ts
74
+ const result = await scanner.asyncScan([
75
+ {
76
+ req_id: 1,
77
+ scan_req: {
78
+ ai_profile: { profile_name: 'my-profile' },
79
+ contents: [{ prompt: 'hello', response: 'world' }],
80
+ },
81
+ },
82
+ ]);
83
+ ```
84
+
85
+ ### Query Results
86
+
87
+ ```ts
88
+ const results = await scanner.queryByScanIds(['scan-uuid-here']);
89
+ const reports = await scanner.queryByReportIds(['report-id-here']);
90
+ ```
91
+
92
+ ## Content Class
93
+
94
+ ```ts
95
+ import { Content } from '@cdot65/prisma-airs-sdk';
96
+
97
+ const content = new Content({
98
+ prompt: 'user prompt',
99
+ response: 'model response',
100
+ context: 'grounding context',
101
+ codePrompt: 'code input',
102
+ codeResponse: 'code output',
103
+ toolEvent: {
104
+ metadata: { ecosystem: 'mcp', method: 'invoke', server_name: 'my-server' },
105
+ input: '{"query": "test"}',
106
+ },
107
+ });
108
+
109
+ // Serialize
110
+ const json = content.toJSON();
111
+
112
+ // Deserialize
113
+ const restored = Content.fromJSON(json);
114
+ const fromFile = Content.fromJSONFile('./content.json');
115
+ ```
116
+
117
+ ## Error Handling
118
+
119
+ ```ts
120
+ import { AISecSDKException, ErrorType } from '@cdot65/prisma-airs-sdk';
121
+
122
+ try {
123
+ await scanner.syncScan(profile, content);
124
+ } catch (err) {
125
+ if (err instanceof AISecSDKException) {
126
+ console.error(err.message); // includes ErrorType prefix
127
+ console.error(err.errorType); // ErrorType enum value
128
+ }
129
+ }
130
+ ```
131
+
132
+ Error types: `SERVER_SIDE_ERROR`, `CLIENT_SIDE_ERROR`, `USER_REQUEST_PAYLOAD_ERROR`, `MISSING_VARIABLE`, `AISEC_SDK_ERROR`.
133
+
134
+ ## Migration from v0.1
135
+
136
+ | v0.1 | v0.2 |
137
+ | --------------------------------------- | --------------------------------------------- |
138
+ | `new PrismaAirsSdkClient({ apiToken })` | `init({ apiKey }); new Scanner()` |
139
+ | `client.scanSyncRequest(body)` | `scanner.syncScan(aiProfile, content, opts?)` |
140
+ | `client.scanAsyncRequest(body)` | `scanner.asyncScan(scanObjects)` |
141
+ | `client.getScanResultsByScanIds(ids)` | `scanner.queryByScanIds(ids)` |
142
+ | `client.getThreatScanReports(ids)` | `scanner.queryByReportIds(ids)` |
143
+ | `PrismaAirsApiError` | `AISecSDKException` |
144
+ | `axios` dependency | Native `fetch` (zero HTTP deps) |
145
+
146
+ ## Development
147
+
148
+ ```bash
149
+ npm install
150
+ npm run build # tsup (CJS + ESM + .d.ts)
151
+ npm run test # vitest
152
+ npm run lint # eslint
153
+ ```
154
+
155
+ ## License
156
+
157
+ MIT