@ayurak/sdk 1.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/README.md +370 -0
- package/dist/index.d.mts +547 -0
- package/dist/index.d.ts +547 -0
- package/dist/index.js +787 -0
- package/dist/index.mjs +750 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
# Aribot JavaScript/TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official JavaScript SDK for the Aribot Security Platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install aribot-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add aribot-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add aribot-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Aribot } from 'aribot-sdk';
|
|
19
|
+
|
|
20
|
+
const client = new Aribot('your_api_key');
|
|
21
|
+
|
|
22
|
+
// Analyze architecture diagram for threats
|
|
23
|
+
const file = new File([buffer], 'architecture.png', { type: 'image/png' });
|
|
24
|
+
const result = await client.threatModeling.analyzeDiagram(file);
|
|
25
|
+
console.log(`Found ${result.threat_count} threats`);
|
|
26
|
+
|
|
27
|
+
// Get detailed threats
|
|
28
|
+
const threats = await client.threatModeling.getThreats(result.diagram_id);
|
|
29
|
+
for (const threat of threats) {
|
|
30
|
+
console.log(`[${threat.severity}] ${threat.title}`);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **Full TypeScript support** with comprehensive type definitions
|
|
37
|
+
- **Threat Modeling** - Upload diagrams, detect components, identify threats
|
|
38
|
+
- **Compliance Scanning** - ISO 27001, SOC2, GDPR, HIPAA, PCI-DSS, NIST
|
|
39
|
+
- **Cloud Security** - Scan AWS, Azure, GCP for misconfigurations
|
|
40
|
+
- **Pipeline Security** - SAST, SCA, secrets detection in CI/CD
|
|
41
|
+
|
|
42
|
+
## API Reference
|
|
43
|
+
|
|
44
|
+
### Threat Modeling
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Upload and analyze a diagram
|
|
48
|
+
const result = await client.threatModeling.analyzeDiagram(file, {
|
|
49
|
+
analysisDepth: 'comprehensive', // basic, comprehensive, detailed
|
|
50
|
+
wait: true, // wait for analysis to complete
|
|
51
|
+
timeout: 300000 // max wait time in ms
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// List diagrams
|
|
55
|
+
const diagrams = await client.threatModeling.list({ page: 1, limit: 25 });
|
|
56
|
+
|
|
57
|
+
// Get diagram details
|
|
58
|
+
const diagram = await client.threatModeling.get(diagramId);
|
|
59
|
+
|
|
60
|
+
// Get threats for a diagram
|
|
61
|
+
const threats = await client.threatModeling.getThreats(diagramId);
|
|
62
|
+
|
|
63
|
+
// Get detected components
|
|
64
|
+
const components = await client.threatModeling.getComponents(diagramId);
|
|
65
|
+
|
|
66
|
+
// Run AI-powered analysis
|
|
67
|
+
const aiResult = await client.threatModeling.analyzeWithAI(diagramId, [
|
|
68
|
+
'attack_paths',
|
|
69
|
+
'data_flow'
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
// Delete a diagram
|
|
73
|
+
await client.threatModeling.delete(diagramId);
|
|
74
|
+
|
|
75
|
+
// Get dashboard metrics
|
|
76
|
+
const dashboard = await client.threatModeling.dashboard('month');
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Compliance Scanning
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Run compliance scan
|
|
83
|
+
const result = await client.compliance.scan(diagramId, {
|
|
84
|
+
standards: ['ISO27001', 'SOC2', 'GDPR'],
|
|
85
|
+
includeRecommendations: true
|
|
86
|
+
});
|
|
87
|
+
console.log(`Compliance score: ${result.overall_score}%`);
|
|
88
|
+
|
|
89
|
+
// Get compliance report
|
|
90
|
+
const report = await client.compliance.getReport(diagramId, 'json');
|
|
91
|
+
|
|
92
|
+
// List available standards
|
|
93
|
+
const standards = await client.compliance.listStandards();
|
|
94
|
+
|
|
95
|
+
// Get standard details
|
|
96
|
+
const iso = await client.compliance.getStandard('ISO27001');
|
|
97
|
+
|
|
98
|
+
// List controls for a standard
|
|
99
|
+
const controls = await client.compliance.listControls('SOC2', 'access_control');
|
|
100
|
+
|
|
101
|
+
// Get compliance gaps
|
|
102
|
+
const gaps = await client.compliance.getGaps(diagramId, 'ISO27001');
|
|
103
|
+
|
|
104
|
+
// Create custom standard
|
|
105
|
+
const custom = await client.compliance.addCustomStandard(
|
|
106
|
+
'Internal Security Policy',
|
|
107
|
+
'Company security requirements',
|
|
108
|
+
[
|
|
109
|
+
{
|
|
110
|
+
id: 'ISP-001',
|
|
111
|
+
name: 'Data Encryption',
|
|
112
|
+
description: 'All data must be encrypted at rest',
|
|
113
|
+
severity: 'high'
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// Get compliance dashboard
|
|
119
|
+
const dashboard = await client.compliance.dashboard('quarter');
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Cloud Security
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// Run cloud security scan
|
|
126
|
+
const scan = await client.cloud.scan('123456789012', {
|
|
127
|
+
provider: 'aws',
|
|
128
|
+
services: ['iam', 's3', 'ec2'],
|
|
129
|
+
complianceStandards: ['CIS-AWS']
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Get scan results
|
|
133
|
+
const scanResult = await client.cloud.getScan(scanId);
|
|
134
|
+
|
|
135
|
+
// List scans
|
|
136
|
+
const scans = await client.cloud.listScans({
|
|
137
|
+
provider: 'aws',
|
|
138
|
+
status: 'completed'
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Get findings
|
|
142
|
+
const findings = await client.cloud.getFindings(scanId, {
|
|
143
|
+
severity: 'critical',
|
|
144
|
+
service: 's3'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Connect AWS account
|
|
148
|
+
const account = await client.cloud.connectAccount(
|
|
149
|
+
'aws',
|
|
150
|
+
{
|
|
151
|
+
role_arn: 'arn:aws:iam::123456789012:role/AribotSecurityRole',
|
|
152
|
+
external_id: 'your-external-id'
|
|
153
|
+
},
|
|
154
|
+
{ name: 'Production AWS' }
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
// Connect GCP project
|
|
158
|
+
const gcpAccount = await client.cloud.connectAccount(
|
|
159
|
+
'gcp',
|
|
160
|
+
{
|
|
161
|
+
service_account_key: '{ ... }',
|
|
162
|
+
project_id: 'my-project-123'
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// List connected accounts
|
|
167
|
+
const accounts = await client.cloud.listAccounts('aws');
|
|
168
|
+
|
|
169
|
+
// Get remediation steps
|
|
170
|
+
const remediation = await client.cloud.getRemediation(findingId);
|
|
171
|
+
|
|
172
|
+
// Resolve a finding
|
|
173
|
+
await client.cloud.resolveFinding(findingId, 'fixed', 'Patched in v1.2.3');
|
|
174
|
+
|
|
175
|
+
// Suppress a finding
|
|
176
|
+
await client.cloud.suppressFinding(findingId, 'Accepted risk', 90);
|
|
177
|
+
|
|
178
|
+
// Get cloud security dashboard
|
|
179
|
+
const dashboard = await client.cloud.dashboard('123456789012');
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Pipeline Security
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
// Create a project
|
|
186
|
+
const project = await client.pipeline.createProject('my-api', {
|
|
187
|
+
repositoryUrl: 'https://github.com/org/my-api',
|
|
188
|
+
scanTypes: ['sast', 'sca', 'secrets']
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Run security scan
|
|
192
|
+
const result = await client.pipeline.scan(projectId, {
|
|
193
|
+
commitSha: 'abc123def456',
|
|
194
|
+
branch: 'main',
|
|
195
|
+
scanTypes: ['sast', 'sca', 'secrets'],
|
|
196
|
+
failOnSeverity: 'high',
|
|
197
|
+
wait: true
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (result.status === 'failed') {
|
|
201
|
+
console.log('Security gate failed!');
|
|
202
|
+
for (const finding of result.blocking_findings || []) {
|
|
203
|
+
console.log(` [${finding.severity}] ${finding.title}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Get scan details
|
|
208
|
+
const scan = await client.pipeline.getScan(scanId);
|
|
209
|
+
|
|
210
|
+
// Get specific finding types
|
|
211
|
+
const sastFindings = await client.pipeline.getSastFindings(scanId);
|
|
212
|
+
const scaFindings = await client.pipeline.getScaFindings(scanId);
|
|
213
|
+
const secrets = await client.pipeline.getSecretsFindings(scanId);
|
|
214
|
+
|
|
215
|
+
// Configure security gates
|
|
216
|
+
await client.pipeline.configureGates(projectId, {
|
|
217
|
+
fail_on_critical: true,
|
|
218
|
+
fail_on_high: true,
|
|
219
|
+
max_high_findings: 5,
|
|
220
|
+
block_secrets: true,
|
|
221
|
+
required_scan_types: ['sast', 'secrets']
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Set baseline (suppress existing findings)
|
|
225
|
+
await client.pipeline.addBaseline(projectId, scanId);
|
|
226
|
+
|
|
227
|
+
// Suppress a finding
|
|
228
|
+
await client.pipeline.suppressFinding(findingId, 'False positive');
|
|
229
|
+
|
|
230
|
+
// Get pipeline dashboard
|
|
231
|
+
const dashboard = await client.pipeline.dashboard(projectId);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Error Handling
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import {
|
|
238
|
+
Aribot,
|
|
239
|
+
AribotError,
|
|
240
|
+
AuthenticationError,
|
|
241
|
+
RateLimitError,
|
|
242
|
+
ValidationError,
|
|
243
|
+
NotFoundError,
|
|
244
|
+
ServerError
|
|
245
|
+
} from 'aribot-sdk';
|
|
246
|
+
|
|
247
|
+
const client = new Aribot('your_api_key');
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
const result = await client.threatModeling.analyzeDiagram(file);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (error instanceof AuthenticationError) {
|
|
253
|
+
console.error('Invalid API key');
|
|
254
|
+
} else if (error instanceof RateLimitError) {
|
|
255
|
+
console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
256
|
+
} else if (error instanceof ValidationError) {
|
|
257
|
+
console.error(`Invalid request: ${error.errors}`);
|
|
258
|
+
} else if (error instanceof NotFoundError) {
|
|
259
|
+
console.error('Resource not found');
|
|
260
|
+
} else if (error instanceof ServerError) {
|
|
261
|
+
console.error('Server error - try again later');
|
|
262
|
+
} else if (error instanceof AribotError) {
|
|
263
|
+
console.error(`API error: ${error.message}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Configuration
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// Custom base URL (for on-premise deployments)
|
|
272
|
+
const client = new Aribot('your_api_key', {
|
|
273
|
+
baseUrl: 'https://aribot.internal.company.com/api',
|
|
274
|
+
timeout: 60000
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Check API health
|
|
278
|
+
const health = await client.health();
|
|
279
|
+
|
|
280
|
+
// Get current user info
|
|
281
|
+
const user = await client.me();
|
|
282
|
+
|
|
283
|
+
// Get usage stats
|
|
284
|
+
const usage = await client.usage('month');
|
|
285
|
+
console.log(`API calls used: ${usage.calls_used}/${usage.calls_limit}`);
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Node.js Usage
|
|
289
|
+
|
|
290
|
+
For Node.js environments, you can use the `fs` module to read files:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { Aribot } from 'aribot-sdk';
|
|
294
|
+
import { readFileSync } from 'fs';
|
|
295
|
+
|
|
296
|
+
const client = new Aribot(process.env.ARIBOT_API_KEY!);
|
|
297
|
+
|
|
298
|
+
// Read file and create Blob
|
|
299
|
+
const buffer = readFileSync('architecture.png');
|
|
300
|
+
const blob = new Blob([buffer], { type: 'image/png' });
|
|
301
|
+
|
|
302
|
+
const result = await client.threatModeling.analyzeDiagram(blob, {
|
|
303
|
+
filename: 'architecture.png'
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Browser Usage
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import { Aribot } from 'aribot-sdk';
|
|
311
|
+
|
|
312
|
+
const client = new Aribot('your_api_key');
|
|
313
|
+
|
|
314
|
+
// Handle file input
|
|
315
|
+
const input = document.querySelector<HTMLInputElement>('#file-input');
|
|
316
|
+
input?.addEventListener('change', async (e) => {
|
|
317
|
+
const file = (e.target as HTMLInputElement).files?.[0];
|
|
318
|
+
if (file) {
|
|
319
|
+
const result = await client.threatModeling.analyzeDiagram(file);
|
|
320
|
+
console.log(result);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## CI/CD Integration
|
|
326
|
+
|
|
327
|
+
### GitHub Actions
|
|
328
|
+
|
|
329
|
+
```yaml
|
|
330
|
+
- name: Security Scan
|
|
331
|
+
uses: actions/setup-node@v4
|
|
332
|
+
with:
|
|
333
|
+
node-version: '20'
|
|
334
|
+
|
|
335
|
+
- run: |
|
|
336
|
+
npm install aribot-sdk
|
|
337
|
+
node << 'EOF'
|
|
338
|
+
const { Aribot } = require('aribot-sdk');
|
|
339
|
+
|
|
340
|
+
const client = new Aribot(process.env.ARIBOT_API_KEY);
|
|
341
|
+
|
|
342
|
+
(async () => {
|
|
343
|
+
const result = await client.pipeline.scan(
|
|
344
|
+
process.env.PROJECT_ID,
|
|
345
|
+
{
|
|
346
|
+
commitSha: process.env.GITHUB_SHA,
|
|
347
|
+
failOnSeverity: 'high',
|
|
348
|
+
wait: true
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
if (result.status === 'failed') {
|
|
353
|
+
process.exit(1);
|
|
354
|
+
}
|
|
355
|
+
})();
|
|
356
|
+
EOF
|
|
357
|
+
env:
|
|
358
|
+
ARIBOT_API_KEY: ${{ secrets.ARIBOT_API_KEY }}
|
|
359
|
+
PROJECT_ID: ${{ vars.PROJECT_ID }}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## Support
|
|
363
|
+
|
|
364
|
+
- Documentation: https://developer.ayurak.com/docs/js-sdk
|
|
365
|
+
- API Reference: https://developer.ayurak.com/api
|
|
366
|
+
- Issues: https://github.com/Aristiun/aribot-js/issues
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
MIT
|