view0x 1.0.1
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 +234 -0
- package/dist/index.d.mts +141 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +191 -0
- package/dist/index.mjs +156 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# view0x JavaScript/TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for [view0x](https://view0x.com) - Smart Contract Security Analysis Platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install view0x
|
|
9
|
+
# or
|
|
10
|
+
yarn add view0x
|
|
11
|
+
# or
|
|
12
|
+
pnpm add view0x
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { View0xSDK } from 'view0x';
|
|
19
|
+
|
|
20
|
+
// Initialize the SDK with your API key
|
|
21
|
+
const client = new View0xSDK({
|
|
22
|
+
apiKey: 'your-api-key-here',
|
|
23
|
+
// baseURL: 'https://api.view0x.com', // Optional: custom API URL
|
|
24
|
+
// timeout: 30000, // Optional: request timeout in ms
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Create an analysis
|
|
28
|
+
const analysis = await client.createAnalysis({
|
|
29
|
+
contractCode: `
|
|
30
|
+
pragma solidity ^0.8.0;
|
|
31
|
+
contract MyContract {
|
|
32
|
+
// Your contract code
|
|
33
|
+
}
|
|
34
|
+
`,
|
|
35
|
+
contractName: 'MyContract',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log('Analysis ID:', analysis.id);
|
|
39
|
+
console.log('Status:', analysis.status);
|
|
40
|
+
|
|
41
|
+
// Get analysis results
|
|
42
|
+
const result = await client.getAnalysis(analysis.id);
|
|
43
|
+
console.log('Vulnerabilities found:', result.vulnerabilities?.length);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- Full TypeScript support with type definitions
|
|
49
|
+
- Promise-based API
|
|
50
|
+
- Automatic authentication handling
|
|
51
|
+
- Comprehensive error handling
|
|
52
|
+
- Support for all view0x API endpoints
|
|
53
|
+
- Repository analysis (GitHub/GitLab)
|
|
54
|
+
- Webhook management
|
|
55
|
+
- Analytics and reporting
|
|
56
|
+
- Zero hardcoded values - fully configurable
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### Authentication
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// Login
|
|
64
|
+
const { token, user } = await client.login({
|
|
65
|
+
email: 'user@example.com',
|
|
66
|
+
password: 'password',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Register
|
|
70
|
+
const { token, user } = await client.register({
|
|
71
|
+
name: 'John Doe',
|
|
72
|
+
email: 'john@example.com',
|
|
73
|
+
password: 'securepassword',
|
|
74
|
+
company: 'My Company', // optional
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Get current user
|
|
78
|
+
const user = await client.getCurrentUser();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Analysis
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Create analysis
|
|
85
|
+
const analysis = await client.createAnalysis({
|
|
86
|
+
contractCode: solidityCode,
|
|
87
|
+
contractName: 'MyContract', // optional
|
|
88
|
+
options: {}, // optional
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Get analysis by ID
|
|
92
|
+
const analysis = await client.getAnalysis('analysis-id');
|
|
93
|
+
|
|
94
|
+
// Get analysis history with pagination
|
|
95
|
+
const history = await client.getAnalysisHistory({
|
|
96
|
+
page: 1,
|
|
97
|
+
limit: 10,
|
|
98
|
+
search: 'MyContract', // optional
|
|
99
|
+
sortBy: 'createdAt', // optional
|
|
100
|
+
sortOrder: 'DESC', // optional
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Generate report
|
|
104
|
+
const pdfBlob = await client.generateReport('analysis-id', 'pdf');
|
|
105
|
+
// Save to file or download
|
|
106
|
+
|
|
107
|
+
// Share analysis
|
|
108
|
+
const { shareToken, shareUrl } = await client.shareAnalysis('analysis-id');
|
|
109
|
+
|
|
110
|
+
// Revoke share
|
|
111
|
+
await client.revokeShare('analysis-id');
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Repository Analysis
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// Analyze GitHub repository
|
|
118
|
+
const analyses = await client.analyzeGitHubRepository({
|
|
119
|
+
repositoryUrl: 'https://github.com/user/repo',
|
|
120
|
+
branch: 'main', // optional
|
|
121
|
+
token: 'github-token', // optional, for private repos
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Analyze GitLab repository
|
|
125
|
+
const analyses = await client.analyzeGitLabRepository({
|
|
126
|
+
repositoryUrl: 'https://gitlab.com/user/repo',
|
|
127
|
+
branch: 'main', // optional
|
|
128
|
+
token: 'gitlab-token', // optional, for private repos
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Auto-detect platform
|
|
132
|
+
const analyses = await client.analyzeRepository({
|
|
133
|
+
repositoryUrl: 'https://github.com/user/repo',
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Webhooks
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Create webhook
|
|
141
|
+
const webhook = await client.createWebhook(
|
|
142
|
+
'https://myapp.com/webhook',
|
|
143
|
+
['analysis.completed', 'analysis.failed'],
|
|
144
|
+
'webhook-secret' // optional
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// Get all webhooks
|
|
148
|
+
const webhooks = await client.getWebhooks();
|
|
149
|
+
|
|
150
|
+
// Update webhook
|
|
151
|
+
const updated = await client.updateWebhook(
|
|
152
|
+
'webhook-id',
|
|
153
|
+
'https://myapp.com/new-webhook',
|
|
154
|
+
['analysis.completed'],
|
|
155
|
+
'new-secret',
|
|
156
|
+
true // isActive
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Delete webhook
|
|
160
|
+
await client.deleteWebhook('webhook-id');
|
|
161
|
+
|
|
162
|
+
// Test webhook
|
|
163
|
+
await client.testWebhook('webhook-id');
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Analytics
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Get analytics dashboard
|
|
170
|
+
const dashboard = await client.getAnalyticsDashboard({
|
|
171
|
+
dateRange: '7d', // optional: 7d, 30d, 90d
|
|
172
|
+
startDate: '2024-01-01', // optional
|
|
173
|
+
endDate: '2024-01-31', // optional
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Get endpoint-specific analytics
|
|
177
|
+
const endpointStats = await client.getEndpointAnalytics('/api/analysis');
|
|
178
|
+
|
|
179
|
+
// Export analytics
|
|
180
|
+
const csvBlob = await client.exportAnalytics('csv');
|
|
181
|
+
const jsonBlob = await client.exportAnalytics('json');
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Error Handling
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
try {
|
|
188
|
+
const analysis = await client.createAnalysis({
|
|
189
|
+
contractCode: code,
|
|
190
|
+
});
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error('Analysis failed:', error.message);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Environment Configuration
|
|
197
|
+
|
|
198
|
+
The SDK respects environment variables:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Use custom API URL
|
|
202
|
+
export VIEW0X_API_URL=https://api.view0x.com
|
|
203
|
+
|
|
204
|
+
# Set default timeout
|
|
205
|
+
export VIEW0X_TIMEOUT=30000
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## TypeScript Support
|
|
209
|
+
|
|
210
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { View0xSDK, Analysis, Vulnerability } from 'view0x';
|
|
214
|
+
|
|
215
|
+
const client = new View0xSDK({ apiKey: 'key' });
|
|
216
|
+
|
|
217
|
+
const analysis: Analysis = await client.getAnalysis('id');
|
|
218
|
+
const vulnerabilities: Vulnerability[] = analysis.vulnerabilities || [];
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Contributing
|
|
222
|
+
|
|
223
|
+
See [CONTRIBUTING.md](https://github.com/1cbyc/view0x/blob/main/CONTRIBUTING.md)
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT © [Nsisong Labs](https://github.com/1cbyc)
|
|
228
|
+
|
|
229
|
+
## Links
|
|
230
|
+
|
|
231
|
+
- [Documentation](https://docs.view0x.com)
|
|
232
|
+
- [API Reference](https://api.view0x.com/docs)
|
|
233
|
+
- [GitHub](https://github.com/1cbyc/view0x)
|
|
234
|
+
- [Website](https://view0x.com)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
interface View0xConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
interface LoginCredentials {
|
|
7
|
+
email: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
interface RegisterData {
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
password: string;
|
|
14
|
+
company?: string;
|
|
15
|
+
}
|
|
16
|
+
interface AnalysisOptions {
|
|
17
|
+
contractCode: string;
|
|
18
|
+
contractName?: string;
|
|
19
|
+
options?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
interface Analysis {
|
|
22
|
+
id: string;
|
|
23
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
24
|
+
contractCode: string;
|
|
25
|
+
contractName?: string;
|
|
26
|
+
vulnerabilities?: Vulnerability[];
|
|
27
|
+
gasReport?: GasReport;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
completedAt?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Vulnerability {
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
severity: 'critical' | 'high' | 'medium' | 'low' | 'informational';
|
|
36
|
+
title: string;
|
|
37
|
+
description: string;
|
|
38
|
+
location?: {
|
|
39
|
+
file?: string;
|
|
40
|
+
line?: number;
|
|
41
|
+
column?: number;
|
|
42
|
+
};
|
|
43
|
+
recommendation?: string;
|
|
44
|
+
}
|
|
45
|
+
interface GasReport {
|
|
46
|
+
totalGas?: number;
|
|
47
|
+
functions?: Array<{
|
|
48
|
+
name: string;
|
|
49
|
+
gas: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
interface PaginationParams {
|
|
53
|
+
page?: number;
|
|
54
|
+
limit?: number;
|
|
55
|
+
search?: string;
|
|
56
|
+
sortBy?: string;
|
|
57
|
+
sortOrder?: 'ASC' | 'DESC';
|
|
58
|
+
}
|
|
59
|
+
interface AnalysisHistory {
|
|
60
|
+
analyses: Analysis[];
|
|
61
|
+
total: number;
|
|
62
|
+
page: number;
|
|
63
|
+
limit: number;
|
|
64
|
+
totalPages: number;
|
|
65
|
+
}
|
|
66
|
+
interface Webhook {
|
|
67
|
+
id: string;
|
|
68
|
+
url: string;
|
|
69
|
+
events: string[];
|
|
70
|
+
secret?: string;
|
|
71
|
+
isActive: boolean;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
}
|
|
74
|
+
interface ApiResponse<T = any> {
|
|
75
|
+
success: boolean;
|
|
76
|
+
data?: T;
|
|
77
|
+
error?: string;
|
|
78
|
+
message?: string;
|
|
79
|
+
}
|
|
80
|
+
interface RepositoryAnalysisOptions {
|
|
81
|
+
repositoryUrl: string;
|
|
82
|
+
branch?: string;
|
|
83
|
+
token?: string;
|
|
84
|
+
platform?: 'github' | 'gitlab';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class View0xSDK {
|
|
88
|
+
private client;
|
|
89
|
+
private apiKey;
|
|
90
|
+
constructor(config: View0xConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Authentication Methods
|
|
93
|
+
*/
|
|
94
|
+
login(credentials: LoginCredentials): Promise<{
|
|
95
|
+
token: string;
|
|
96
|
+
user: any;
|
|
97
|
+
}>;
|
|
98
|
+
register(userData: RegisterData): Promise<{
|
|
99
|
+
token: string;
|
|
100
|
+
user: any;
|
|
101
|
+
}>;
|
|
102
|
+
getCurrentUser(): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* Analysis Methods
|
|
105
|
+
*/
|
|
106
|
+
createAnalysis(options: AnalysisOptions): Promise<Analysis>;
|
|
107
|
+
getAnalysis(analysisId: string): Promise<Analysis>;
|
|
108
|
+
getAnalysisHistory(params?: PaginationParams): Promise<AnalysisHistory>;
|
|
109
|
+
generateReport(analysisId: string, format?: 'pdf' | 'json'): Promise<Blob>;
|
|
110
|
+
shareAnalysis(analysisId: string): Promise<{
|
|
111
|
+
shareToken: string;
|
|
112
|
+
shareUrl: string;
|
|
113
|
+
}>;
|
|
114
|
+
revokeShare(analysisId: string): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Repository Analysis Methods
|
|
117
|
+
*/
|
|
118
|
+
analyzeGitHubRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
119
|
+
analyzeGitLabRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
120
|
+
analyzeRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Webhook Methods
|
|
123
|
+
*/
|
|
124
|
+
createWebhook(url: string, events: string[], secret?: string): Promise<Webhook>;
|
|
125
|
+
getWebhooks(): Promise<Webhook[]>;
|
|
126
|
+
updateWebhook(id: string, url: string, events: string[], secret?: string, isActive?: boolean): Promise<Webhook>;
|
|
127
|
+
deleteWebhook(id: string): Promise<void>;
|
|
128
|
+
testWebhook(id: string): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Analytics Methods
|
|
131
|
+
*/
|
|
132
|
+
getAnalyticsDashboard(params?: {
|
|
133
|
+
startDate?: string;
|
|
134
|
+
endDate?: string;
|
|
135
|
+
dateRange?: string;
|
|
136
|
+
}): Promise<any>;
|
|
137
|
+
getEndpointAnalytics(endpoint: string): Promise<any>;
|
|
138
|
+
exportAnalytics(format?: 'csv' | 'json'): Promise<Blob>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { type Analysis, type AnalysisHistory, type AnalysisOptions, type ApiResponse, type GasReport, type LoginCredentials, type PaginationParams, type RegisterData, type RepositoryAnalysisOptions, type View0xConfig, View0xSDK, type Vulnerability, type Webhook, View0xSDK as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
interface View0xConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
interface LoginCredentials {
|
|
7
|
+
email: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
interface RegisterData {
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
password: string;
|
|
14
|
+
company?: string;
|
|
15
|
+
}
|
|
16
|
+
interface AnalysisOptions {
|
|
17
|
+
contractCode: string;
|
|
18
|
+
contractName?: string;
|
|
19
|
+
options?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
interface Analysis {
|
|
22
|
+
id: string;
|
|
23
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
24
|
+
contractCode: string;
|
|
25
|
+
contractName?: string;
|
|
26
|
+
vulnerabilities?: Vulnerability[];
|
|
27
|
+
gasReport?: GasReport;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
completedAt?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Vulnerability {
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
severity: 'critical' | 'high' | 'medium' | 'low' | 'informational';
|
|
36
|
+
title: string;
|
|
37
|
+
description: string;
|
|
38
|
+
location?: {
|
|
39
|
+
file?: string;
|
|
40
|
+
line?: number;
|
|
41
|
+
column?: number;
|
|
42
|
+
};
|
|
43
|
+
recommendation?: string;
|
|
44
|
+
}
|
|
45
|
+
interface GasReport {
|
|
46
|
+
totalGas?: number;
|
|
47
|
+
functions?: Array<{
|
|
48
|
+
name: string;
|
|
49
|
+
gas: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
interface PaginationParams {
|
|
53
|
+
page?: number;
|
|
54
|
+
limit?: number;
|
|
55
|
+
search?: string;
|
|
56
|
+
sortBy?: string;
|
|
57
|
+
sortOrder?: 'ASC' | 'DESC';
|
|
58
|
+
}
|
|
59
|
+
interface AnalysisHistory {
|
|
60
|
+
analyses: Analysis[];
|
|
61
|
+
total: number;
|
|
62
|
+
page: number;
|
|
63
|
+
limit: number;
|
|
64
|
+
totalPages: number;
|
|
65
|
+
}
|
|
66
|
+
interface Webhook {
|
|
67
|
+
id: string;
|
|
68
|
+
url: string;
|
|
69
|
+
events: string[];
|
|
70
|
+
secret?: string;
|
|
71
|
+
isActive: boolean;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
}
|
|
74
|
+
interface ApiResponse<T = any> {
|
|
75
|
+
success: boolean;
|
|
76
|
+
data?: T;
|
|
77
|
+
error?: string;
|
|
78
|
+
message?: string;
|
|
79
|
+
}
|
|
80
|
+
interface RepositoryAnalysisOptions {
|
|
81
|
+
repositoryUrl: string;
|
|
82
|
+
branch?: string;
|
|
83
|
+
token?: string;
|
|
84
|
+
platform?: 'github' | 'gitlab';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class View0xSDK {
|
|
88
|
+
private client;
|
|
89
|
+
private apiKey;
|
|
90
|
+
constructor(config: View0xConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Authentication Methods
|
|
93
|
+
*/
|
|
94
|
+
login(credentials: LoginCredentials): Promise<{
|
|
95
|
+
token: string;
|
|
96
|
+
user: any;
|
|
97
|
+
}>;
|
|
98
|
+
register(userData: RegisterData): Promise<{
|
|
99
|
+
token: string;
|
|
100
|
+
user: any;
|
|
101
|
+
}>;
|
|
102
|
+
getCurrentUser(): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* Analysis Methods
|
|
105
|
+
*/
|
|
106
|
+
createAnalysis(options: AnalysisOptions): Promise<Analysis>;
|
|
107
|
+
getAnalysis(analysisId: string): Promise<Analysis>;
|
|
108
|
+
getAnalysisHistory(params?: PaginationParams): Promise<AnalysisHistory>;
|
|
109
|
+
generateReport(analysisId: string, format?: 'pdf' | 'json'): Promise<Blob>;
|
|
110
|
+
shareAnalysis(analysisId: string): Promise<{
|
|
111
|
+
shareToken: string;
|
|
112
|
+
shareUrl: string;
|
|
113
|
+
}>;
|
|
114
|
+
revokeShare(analysisId: string): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Repository Analysis Methods
|
|
117
|
+
*/
|
|
118
|
+
analyzeGitHubRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
119
|
+
analyzeGitLabRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
120
|
+
analyzeRepository(options: RepositoryAnalysisOptions): Promise<Analysis[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Webhook Methods
|
|
123
|
+
*/
|
|
124
|
+
createWebhook(url: string, events: string[], secret?: string): Promise<Webhook>;
|
|
125
|
+
getWebhooks(): Promise<Webhook[]>;
|
|
126
|
+
updateWebhook(id: string, url: string, events: string[], secret?: string, isActive?: boolean): Promise<Webhook>;
|
|
127
|
+
deleteWebhook(id: string): Promise<void>;
|
|
128
|
+
testWebhook(id: string): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Analytics Methods
|
|
131
|
+
*/
|
|
132
|
+
getAnalyticsDashboard(params?: {
|
|
133
|
+
startDate?: string;
|
|
134
|
+
endDate?: string;
|
|
135
|
+
dateRange?: string;
|
|
136
|
+
}): Promise<any>;
|
|
137
|
+
getEndpointAnalytics(endpoint: string): Promise<any>;
|
|
138
|
+
exportAnalytics(format?: 'csv' | 'json'): Promise<Blob>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { type Analysis, type AnalysisHistory, type AnalysisOptions, type ApiResponse, type GasReport, type LoginCredentials, type PaginationParams, type RegisterData, type RepositoryAnalysisOptions, type View0xConfig, View0xSDK, type Vulnerability, type Webhook, View0xSDK as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
View0xSDK: () => View0xSDK,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_axios = __toESM(require("axios"));
|
|
38
|
+
var View0xSDK = class {
|
|
39
|
+
constructor(config) {
|
|
40
|
+
this.apiKey = config.apiKey;
|
|
41
|
+
this.client = import_axios.default.create({
|
|
42
|
+
baseURL: config.baseURL || "https://api.view0x.com",
|
|
43
|
+
timeout: config.timeout || 3e4,
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.client.interceptors.response.use(
|
|
50
|
+
(response) => response,
|
|
51
|
+
(error) => {
|
|
52
|
+
if (error.response?.data) {
|
|
53
|
+
throw new Error(error.response.data.error || error.response.data.message || "API Error");
|
|
54
|
+
}
|
|
55
|
+
throw new Error(error.message || "Network Error");
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Authentication Methods
|
|
61
|
+
*/
|
|
62
|
+
async login(credentials) {
|
|
63
|
+
const response = await this.client.post(
|
|
64
|
+
"/auth/login",
|
|
65
|
+
credentials
|
|
66
|
+
);
|
|
67
|
+
return response.data.data;
|
|
68
|
+
}
|
|
69
|
+
async register(userData) {
|
|
70
|
+
const response = await this.client.post(
|
|
71
|
+
"/auth/register",
|
|
72
|
+
userData
|
|
73
|
+
);
|
|
74
|
+
return response.data.data;
|
|
75
|
+
}
|
|
76
|
+
async getCurrentUser() {
|
|
77
|
+
const response = await this.client.get("/auth/me");
|
|
78
|
+
return response.data.data;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Analysis Methods
|
|
82
|
+
*/
|
|
83
|
+
async createAnalysis(options) {
|
|
84
|
+
const response = await this.client.post("/analysis", options);
|
|
85
|
+
return response.data.data;
|
|
86
|
+
}
|
|
87
|
+
async getAnalysis(analysisId) {
|
|
88
|
+
const response = await this.client.get(`/analysis/${analysisId}`);
|
|
89
|
+
return response.data.data;
|
|
90
|
+
}
|
|
91
|
+
async getAnalysisHistory(params) {
|
|
92
|
+
const response = await this.client.get("/analysis", { params });
|
|
93
|
+
return response.data.data;
|
|
94
|
+
}
|
|
95
|
+
async generateReport(analysisId, format = "pdf") {
|
|
96
|
+
const response = await this.client.post(
|
|
97
|
+
`/analysis/${analysisId}/report`,
|
|
98
|
+
{ format },
|
|
99
|
+
{ responseType: "blob" }
|
|
100
|
+
);
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
async shareAnalysis(analysisId) {
|
|
104
|
+
const response = await this.client.post(
|
|
105
|
+
`/analysis/${analysisId}/share`
|
|
106
|
+
);
|
|
107
|
+
return response.data.data;
|
|
108
|
+
}
|
|
109
|
+
async revokeShare(analysisId) {
|
|
110
|
+
await this.client.delete(`/analysis/${analysisId}/share`);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Repository Analysis Methods
|
|
114
|
+
*/
|
|
115
|
+
async analyzeGitHubRepository(options) {
|
|
116
|
+
const response = await this.client.post(
|
|
117
|
+
"/repository/github",
|
|
118
|
+
options
|
|
119
|
+
);
|
|
120
|
+
return response.data.data.analyses;
|
|
121
|
+
}
|
|
122
|
+
async analyzeGitLabRepository(options) {
|
|
123
|
+
const response = await this.client.post(
|
|
124
|
+
"/repository/gitlab",
|
|
125
|
+
options
|
|
126
|
+
);
|
|
127
|
+
return response.data.data.analyses;
|
|
128
|
+
}
|
|
129
|
+
async analyzeRepository(options) {
|
|
130
|
+
const response = await this.client.post(
|
|
131
|
+
"/repository/analyze",
|
|
132
|
+
options
|
|
133
|
+
);
|
|
134
|
+
return response.data.data.analyses;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Webhook Methods
|
|
138
|
+
*/
|
|
139
|
+
async createWebhook(url, events, secret) {
|
|
140
|
+
const response = await this.client.post("/webhooks", {
|
|
141
|
+
url,
|
|
142
|
+
events,
|
|
143
|
+
secret
|
|
144
|
+
});
|
|
145
|
+
return response.data.data;
|
|
146
|
+
}
|
|
147
|
+
async getWebhooks() {
|
|
148
|
+
const response = await this.client.get("/webhooks");
|
|
149
|
+
return response.data.data;
|
|
150
|
+
}
|
|
151
|
+
async updateWebhook(id, url, events, secret, isActive) {
|
|
152
|
+
const response = await this.client.put(`/webhooks/${id}`, {
|
|
153
|
+
url,
|
|
154
|
+
events,
|
|
155
|
+
secret,
|
|
156
|
+
isActive
|
|
157
|
+
});
|
|
158
|
+
return response.data.data;
|
|
159
|
+
}
|
|
160
|
+
async deleteWebhook(id) {
|
|
161
|
+
await this.client.delete(`/webhooks/${id}`);
|
|
162
|
+
}
|
|
163
|
+
async testWebhook(id) {
|
|
164
|
+
await this.client.post(`/webhooks/${id}/test`);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Analytics Methods
|
|
168
|
+
*/
|
|
169
|
+
async getAnalyticsDashboard(params) {
|
|
170
|
+
const response = await this.client.get("/analytics/dashboard", { params });
|
|
171
|
+
return response.data.data;
|
|
172
|
+
}
|
|
173
|
+
async getEndpointAnalytics(endpoint) {
|
|
174
|
+
const response = await this.client.get("/analytics/endpoint", {
|
|
175
|
+
params: { endpoint }
|
|
176
|
+
});
|
|
177
|
+
return response.data.data;
|
|
178
|
+
}
|
|
179
|
+
async exportAnalytics(format = "json") {
|
|
180
|
+
const response = await this.client.get("/analytics/export", {
|
|
181
|
+
params: { format },
|
|
182
|
+
responseType: "blob"
|
|
183
|
+
});
|
|
184
|
+
return response.data;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var index_default = View0xSDK;
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
View0xSDK
|
|
191
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
var View0xSDK = class {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.apiKey = config.apiKey;
|
|
6
|
+
this.client = axios.create({
|
|
7
|
+
baseURL: config.baseURL || "https://api.view0x.com",
|
|
8
|
+
timeout: config.timeout || 3e4,
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
this.client.interceptors.response.use(
|
|
15
|
+
(response) => response,
|
|
16
|
+
(error) => {
|
|
17
|
+
if (error.response?.data) {
|
|
18
|
+
throw new Error(error.response.data.error || error.response.data.message || "API Error");
|
|
19
|
+
}
|
|
20
|
+
throw new Error(error.message || "Network Error");
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Authentication Methods
|
|
26
|
+
*/
|
|
27
|
+
async login(credentials) {
|
|
28
|
+
const response = await this.client.post(
|
|
29
|
+
"/auth/login",
|
|
30
|
+
credentials
|
|
31
|
+
);
|
|
32
|
+
return response.data.data;
|
|
33
|
+
}
|
|
34
|
+
async register(userData) {
|
|
35
|
+
const response = await this.client.post(
|
|
36
|
+
"/auth/register",
|
|
37
|
+
userData
|
|
38
|
+
);
|
|
39
|
+
return response.data.data;
|
|
40
|
+
}
|
|
41
|
+
async getCurrentUser() {
|
|
42
|
+
const response = await this.client.get("/auth/me");
|
|
43
|
+
return response.data.data;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Analysis Methods
|
|
47
|
+
*/
|
|
48
|
+
async createAnalysis(options) {
|
|
49
|
+
const response = await this.client.post("/analysis", options);
|
|
50
|
+
return response.data.data;
|
|
51
|
+
}
|
|
52
|
+
async getAnalysis(analysisId) {
|
|
53
|
+
const response = await this.client.get(`/analysis/${analysisId}`);
|
|
54
|
+
return response.data.data;
|
|
55
|
+
}
|
|
56
|
+
async getAnalysisHistory(params) {
|
|
57
|
+
const response = await this.client.get("/analysis", { params });
|
|
58
|
+
return response.data.data;
|
|
59
|
+
}
|
|
60
|
+
async generateReport(analysisId, format = "pdf") {
|
|
61
|
+
const response = await this.client.post(
|
|
62
|
+
`/analysis/${analysisId}/report`,
|
|
63
|
+
{ format },
|
|
64
|
+
{ responseType: "blob" }
|
|
65
|
+
);
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
async shareAnalysis(analysisId) {
|
|
69
|
+
const response = await this.client.post(
|
|
70
|
+
`/analysis/${analysisId}/share`
|
|
71
|
+
);
|
|
72
|
+
return response.data.data;
|
|
73
|
+
}
|
|
74
|
+
async revokeShare(analysisId) {
|
|
75
|
+
await this.client.delete(`/analysis/${analysisId}/share`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Repository Analysis Methods
|
|
79
|
+
*/
|
|
80
|
+
async analyzeGitHubRepository(options) {
|
|
81
|
+
const response = await this.client.post(
|
|
82
|
+
"/repository/github",
|
|
83
|
+
options
|
|
84
|
+
);
|
|
85
|
+
return response.data.data.analyses;
|
|
86
|
+
}
|
|
87
|
+
async analyzeGitLabRepository(options) {
|
|
88
|
+
const response = await this.client.post(
|
|
89
|
+
"/repository/gitlab",
|
|
90
|
+
options
|
|
91
|
+
);
|
|
92
|
+
return response.data.data.analyses;
|
|
93
|
+
}
|
|
94
|
+
async analyzeRepository(options) {
|
|
95
|
+
const response = await this.client.post(
|
|
96
|
+
"/repository/analyze",
|
|
97
|
+
options
|
|
98
|
+
);
|
|
99
|
+
return response.data.data.analyses;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Webhook Methods
|
|
103
|
+
*/
|
|
104
|
+
async createWebhook(url, events, secret) {
|
|
105
|
+
const response = await this.client.post("/webhooks", {
|
|
106
|
+
url,
|
|
107
|
+
events,
|
|
108
|
+
secret
|
|
109
|
+
});
|
|
110
|
+
return response.data.data;
|
|
111
|
+
}
|
|
112
|
+
async getWebhooks() {
|
|
113
|
+
const response = await this.client.get("/webhooks");
|
|
114
|
+
return response.data.data;
|
|
115
|
+
}
|
|
116
|
+
async updateWebhook(id, url, events, secret, isActive) {
|
|
117
|
+
const response = await this.client.put(`/webhooks/${id}`, {
|
|
118
|
+
url,
|
|
119
|
+
events,
|
|
120
|
+
secret,
|
|
121
|
+
isActive
|
|
122
|
+
});
|
|
123
|
+
return response.data.data;
|
|
124
|
+
}
|
|
125
|
+
async deleteWebhook(id) {
|
|
126
|
+
await this.client.delete(`/webhooks/${id}`);
|
|
127
|
+
}
|
|
128
|
+
async testWebhook(id) {
|
|
129
|
+
await this.client.post(`/webhooks/${id}/test`);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Analytics Methods
|
|
133
|
+
*/
|
|
134
|
+
async getAnalyticsDashboard(params) {
|
|
135
|
+
const response = await this.client.get("/analytics/dashboard", { params });
|
|
136
|
+
return response.data.data;
|
|
137
|
+
}
|
|
138
|
+
async getEndpointAnalytics(endpoint) {
|
|
139
|
+
const response = await this.client.get("/analytics/endpoint", {
|
|
140
|
+
params: { endpoint }
|
|
141
|
+
});
|
|
142
|
+
return response.data.data;
|
|
143
|
+
}
|
|
144
|
+
async exportAnalytics(format = "json") {
|
|
145
|
+
const response = await this.client.get("/analytics/export", {
|
|
146
|
+
params: { format },
|
|
147
|
+
responseType: "blob"
|
|
148
|
+
});
|
|
149
|
+
return response.data;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var index_default = View0xSDK;
|
|
153
|
+
export {
|
|
154
|
+
View0xSDK,
|
|
155
|
+
index_default as default
|
|
156
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "view0x",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Official JavaScript/TypeScript SDK for view0x - Smart Contract Security Analysis Platform",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"lint": "eslint src --ext .ts",
|
|
25
|
+
"format": "prettier --write \"src/**/*.ts\""
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"view0x",
|
|
29
|
+
"smart-contract",
|
|
30
|
+
"security",
|
|
31
|
+
"analysis",
|
|
32
|
+
"audit",
|
|
33
|
+
"ethereum",
|
|
34
|
+
"solidity",
|
|
35
|
+
"blockchain",
|
|
36
|
+
"vulnerability",
|
|
37
|
+
"sdk"
|
|
38
|
+
],
|
|
39
|
+
"author": "Nsisong Labs <hello@view0x.com>",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/1cbyc/view0x.git",
|
|
44
|
+
"directory": "sdk-js"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/1cbyc/view0x/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://view0x.com",
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"axios": "^1.6.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/jest": "^29.5.0",
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
57
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
58
|
+
"eslint": "^8.0.0",
|
|
59
|
+
"jest": "^29.5.0",
|
|
60
|
+
"prettier": "^3.0.0",
|
|
61
|
+
"ts-jest": "^29.1.0",
|
|
62
|
+
"tsup": "^8.0.0",
|
|
63
|
+
"typescript": "^5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=16.0.0"
|
|
67
|
+
}
|
|
68
|
+
}
|