wolfronix-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/LICENSE +21 -0
- package/README.md +351 -0
- package/dist/index.d.mts +238 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +505 -0
- package/dist/index.mjs +473 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wolfronix SDK for JavaScript/TypeScript
|
|
3
|
+
* Zero-knowledge encryption made simple
|
|
4
|
+
*
|
|
5
|
+
* @package @wolfronix/sdk
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
interface WolfronixConfig {
|
|
9
|
+
/** Wolfronix server base URL */
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** Your enterprise client ID (optional for self-hosted) */
|
|
12
|
+
clientId?: string;
|
|
13
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Retry failed requests (default: 3) */
|
|
16
|
+
retries?: number;
|
|
17
|
+
/** Skip SSL verification for self-signed certs (default: false) */
|
|
18
|
+
insecure?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface AuthResponse {
|
|
21
|
+
success: boolean;
|
|
22
|
+
user_id: string;
|
|
23
|
+
token: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
interface EncryptResponse {
|
|
27
|
+
success: boolean;
|
|
28
|
+
file_id: string;
|
|
29
|
+
original_name: string;
|
|
30
|
+
encrypted_size: number;
|
|
31
|
+
message: string;
|
|
32
|
+
}
|
|
33
|
+
interface FileInfo {
|
|
34
|
+
file_id: string;
|
|
35
|
+
original_name: string;
|
|
36
|
+
encrypted_size: number;
|
|
37
|
+
created_at: string;
|
|
38
|
+
}
|
|
39
|
+
interface ListFilesResponse {
|
|
40
|
+
success: boolean;
|
|
41
|
+
files: FileInfo[];
|
|
42
|
+
total: number;
|
|
43
|
+
}
|
|
44
|
+
interface DeleteResponse {
|
|
45
|
+
success: boolean;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
interface MetricsResponse {
|
|
49
|
+
success: boolean;
|
|
50
|
+
total_encryptions: number;
|
|
51
|
+
total_decryptions: number;
|
|
52
|
+
total_bytes_encrypted: number;
|
|
53
|
+
total_bytes_decrypted: number;
|
|
54
|
+
}
|
|
55
|
+
interface StreamToken {
|
|
56
|
+
token: string;
|
|
57
|
+
expires_at: string;
|
|
58
|
+
}
|
|
59
|
+
declare class WolfronixError extends Error {
|
|
60
|
+
readonly code: string;
|
|
61
|
+
readonly statusCode?: number;
|
|
62
|
+
readonly details?: Record<string, unknown>;
|
|
63
|
+
constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
|
|
64
|
+
}
|
|
65
|
+
declare class AuthenticationError extends WolfronixError {
|
|
66
|
+
constructor(message?: string);
|
|
67
|
+
}
|
|
68
|
+
declare class FileNotFoundError extends WolfronixError {
|
|
69
|
+
constructor(fileId: string);
|
|
70
|
+
}
|
|
71
|
+
declare class PermissionDeniedError extends WolfronixError {
|
|
72
|
+
constructor(message?: string);
|
|
73
|
+
}
|
|
74
|
+
declare class NetworkError extends WolfronixError {
|
|
75
|
+
constructor(message?: string);
|
|
76
|
+
}
|
|
77
|
+
declare class ValidationError extends WolfronixError {
|
|
78
|
+
constructor(message: string);
|
|
79
|
+
}
|
|
80
|
+
declare class Wolfronix {
|
|
81
|
+
private readonly config;
|
|
82
|
+
private token;
|
|
83
|
+
private userId;
|
|
84
|
+
private tokenExpiry;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new Wolfronix client
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const wfx = new Wolfronix({
|
|
91
|
+
* baseUrl: 'https://wolfronix-server:5002',
|
|
92
|
+
* clientId: 'your-client-id'
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
constructor(config: WolfronixConfig | string);
|
|
97
|
+
private getHeaders;
|
|
98
|
+
private request;
|
|
99
|
+
private sleep;
|
|
100
|
+
private ensureAuthenticated;
|
|
101
|
+
/**
|
|
102
|
+
* Register a new user
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const { user_id, token } = await wfx.register('user@example.com', 'password123');
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
register(email: string, password: string): Promise<AuthResponse>;
|
|
110
|
+
/**
|
|
111
|
+
* Login with existing credentials
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* await wfx.login('user@example.com', 'password123');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
login(email: string, password: string): Promise<AuthResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* Set authentication token directly (useful for server-side apps)
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* wfx.setToken('jwt-token-here', 'user-id-here');
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
setToken(token: string, userId?: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* Clear authentication state (logout)
|
|
130
|
+
*/
|
|
131
|
+
logout(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Check if client is authenticated
|
|
134
|
+
*/
|
|
135
|
+
isAuthenticated(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Get current user ID
|
|
138
|
+
*/
|
|
139
|
+
getUserId(): string | null;
|
|
140
|
+
/**
|
|
141
|
+
* Encrypt and store a file
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Browser
|
|
146
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
147
|
+
* const result = await wfx.encrypt(fileInput.files[0]);
|
|
148
|
+
*
|
|
149
|
+
* // Node.js
|
|
150
|
+
* const buffer = fs.readFileSync('document.pdf');
|
|
151
|
+
* const result = await wfx.encrypt(buffer, 'document.pdf');
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
encrypt(file: File | Blob | ArrayBuffer | Uint8Array, filename?: string): Promise<EncryptResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Encrypt a file using streaming (for large files)
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const result = await wfx.encryptStream(largeFile, (progress) => {
|
|
161
|
+
* console.log(`Progress: ${progress}%`);
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
encryptStream(file: File | Blob, onProgress?: (percent: number) => void): Promise<EncryptResponse>;
|
|
166
|
+
/**
|
|
167
|
+
* Decrypt and retrieve a file
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Get as Blob (browser)
|
|
172
|
+
* const blob = await wfx.decrypt('file-id');
|
|
173
|
+
* const url = URL.createObjectURL(blob);
|
|
174
|
+
*
|
|
175
|
+
* // Get as Buffer (Node.js)
|
|
176
|
+
* const buffer = await wfx.decryptToBuffer('file-id');
|
|
177
|
+
* fs.writeFileSync('decrypted.pdf', buffer);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
decrypt(fileId: string): Promise<Blob>;
|
|
181
|
+
/**
|
|
182
|
+
* Decrypt and return as ArrayBuffer
|
|
183
|
+
*/
|
|
184
|
+
decryptToBuffer(fileId: string): Promise<ArrayBuffer>;
|
|
185
|
+
/**
|
|
186
|
+
* Decrypt using streaming (for large files)
|
|
187
|
+
*/
|
|
188
|
+
decryptStream(fileId: string, onProgress?: (percent: number) => void): Promise<Blob>;
|
|
189
|
+
/**
|
|
190
|
+
* List all encrypted files for current user
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const { files } = await wfx.listFiles();
|
|
195
|
+
* files.forEach(f => console.log(f.original_name, f.file_id));
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
listFiles(): Promise<ListFilesResponse>;
|
|
199
|
+
/**
|
|
200
|
+
* Delete an encrypted file
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* await wfx.deleteFile('file-id');
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
deleteFile(fileId: string): Promise<DeleteResponse>;
|
|
208
|
+
/**
|
|
209
|
+
* Get encryption/decryption metrics
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const metrics = await wfx.getMetrics();
|
|
214
|
+
* console.log(`Total encryptions: ${metrics.total_encryptions}`);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
getMetrics(): Promise<MetricsResponse>;
|
|
218
|
+
/**
|
|
219
|
+
* Check if server is healthy
|
|
220
|
+
*/
|
|
221
|
+
healthCheck(): Promise<boolean>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create a new Wolfronix client
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* import { createClient } from '@wolfronix/sdk';
|
|
229
|
+
*
|
|
230
|
+
* const wfx = createClient({
|
|
231
|
+
* baseUrl: 'https://wolfronix-server:5002',
|
|
232
|
+
* clientId: 'your-client-id'
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function createClient(config: WolfronixConfig | string): Wolfronix;
|
|
237
|
+
|
|
238
|
+
export { type AuthResponse, AuthenticationError, type DeleteResponse, type EncryptResponse, type FileInfo, FileNotFoundError, type ListFilesResponse, type MetricsResponse, NetworkError, PermissionDeniedError, type StreamToken, ValidationError, Wolfronix, type WolfronixConfig, WolfronixError, createClient, Wolfronix as default };
|