@marlinjai/storage-brain-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.
@@ -0,0 +1,367 @@
1
+ /**
2
+ * Allowed MIME types for file uploads
3
+ */
4
+ declare const ALLOWED_FILE_TYPES: {
5
+ readonly 'image/jpeg': {
6
+ readonly extension: "jpg";
7
+ readonly category: "image";
8
+ };
9
+ readonly 'image/png': {
10
+ readonly extension: "png";
11
+ readonly category: "image";
12
+ };
13
+ readonly 'image/webp': {
14
+ readonly extension: "webp";
15
+ readonly category: "image";
16
+ };
17
+ readonly 'image/gif': {
18
+ readonly extension: "gif";
19
+ readonly category: "image";
20
+ };
21
+ readonly 'image/avif': {
22
+ readonly extension: "avif";
23
+ readonly category: "image";
24
+ };
25
+ readonly 'application/pdf': {
26
+ readonly extension: "pdf";
27
+ readonly category: "document";
28
+ };
29
+ };
30
+ type AllowedMimeType = keyof typeof ALLOWED_FILE_TYPES;
31
+ declare const ALLOWED_MIME_TYPES: AllowedMimeType[];
32
+ declare const IMAGE_MIME_TYPES: ("image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/avif" | "application/pdf")[];
33
+ declare const DOCUMENT_MIME_TYPES: ("image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/avif" | "application/pdf")[];
34
+ /**
35
+ * Processing contexts
36
+ */
37
+ declare const PROCESSING_CONTEXTS: readonly ["newsletter", "invoice", "framer-site", "default"];
38
+ type ProcessingContext = (typeof PROCESSING_CONTEXTS)[number];
39
+ /**
40
+ * File size limits
41
+ */
42
+ declare const MAX_FILE_SIZE_BYTES: number;
43
+ /**
44
+ * Thumbnail sizes
45
+ */
46
+ declare const THUMBNAIL_SIZES: {
47
+ readonly thumb: {
48
+ readonly width: 200;
49
+ readonly height: 200;
50
+ };
51
+ readonly medium: {
52
+ readonly width: 400;
53
+ readonly height: 400;
54
+ };
55
+ readonly large: {
56
+ readonly width: 800;
57
+ readonly height: 800;
58
+ };
59
+ };
60
+ type ThumbnailSize = keyof typeof THUMBNAIL_SIZES;
61
+ /**
62
+ * Processing statuses
63
+ */
64
+ declare const PROCESSING_STATUSES: readonly ["pending", "processing", "completed", "failed"];
65
+ type ProcessingStatus = (typeof PROCESSING_STATUSES)[number];
66
+
67
+ /**
68
+ * File metadata (stored as JSON)
69
+ */
70
+ interface FileMetadata {
71
+ thumbnailUrls?: ThumbnailUrls;
72
+ ocrData?: OcrResult;
73
+ imageInfo?: ImageInfo;
74
+ processingError?: string;
75
+ [key: string]: unknown;
76
+ }
77
+ /**
78
+ * Thumbnail URLs for different sizes
79
+ */
80
+ type ThumbnailUrls = {
81
+ [K in ThumbnailSize]?: string;
82
+ };
83
+ /**
84
+ * OCR result from Google Cloud Vision
85
+ */
86
+ interface OcrResult {
87
+ fullText: string;
88
+ confidence: number;
89
+ blocks: OcrBlock[];
90
+ }
91
+ interface OcrBlock {
92
+ text: string;
93
+ confidence: number;
94
+ boundingBox: BoundingBox;
95
+ }
96
+ interface BoundingBox {
97
+ x: number;
98
+ y: number;
99
+ width: number;
100
+ height: number;
101
+ }
102
+ /**
103
+ * Image information extracted from EXIF
104
+ */
105
+ interface ImageInfo {
106
+ width: number;
107
+ height: number;
108
+ format: string;
109
+ colorSpace?: string;
110
+ hasAlpha?: boolean;
111
+ }
112
+ /**
113
+ * Configuration for Storage Brain client
114
+ */
115
+ interface StorageBrainConfig {
116
+ /** API key for authentication (sk_live_... or sk_test_...) */
117
+ apiKey: string;
118
+ /** Base URL of the Storage Brain API (defaults to production) */
119
+ baseUrl?: string;
120
+ /** Request timeout in milliseconds (default: 30000) */
121
+ timeout?: number;
122
+ /** Number of retry attempts for failed requests (default: 3) */
123
+ maxRetries?: number;
124
+ }
125
+ /**
126
+ * Options for uploading a file
127
+ */
128
+ interface UploadOptions {
129
+ /** Processing context for the file */
130
+ context: ProcessingContext;
131
+ /** Optional tags for the file */
132
+ tags?: Record<string, string>;
133
+ /** Progress callback (0-100) */
134
+ onProgress?: (progress: number) => void;
135
+ /** Optional webhook URL to call after processing */
136
+ webhookUrl?: string;
137
+ /** Abort signal for cancellation */
138
+ signal?: AbortSignal;
139
+ }
140
+ /**
141
+ * File information returned from the API
142
+ */
143
+ interface FileInfo {
144
+ /** Unique file identifier */
145
+ id: string;
146
+ /** Public URL to access the file */
147
+ url: string;
148
+ /** Original file name */
149
+ originalName: string;
150
+ /** MIME type */
151
+ fileType: AllowedMimeType;
152
+ /** File size in bytes */
153
+ sizeBytes: number;
154
+ /** Processing context */
155
+ context: ProcessingContext;
156
+ /** User-defined tags */
157
+ tags: Record<string, string> | null;
158
+ /** Processing results and metadata */
159
+ metadata: FileMetadata | null;
160
+ /** Current processing status */
161
+ processingStatus: ProcessingStatus;
162
+ /** ISO 8601 timestamp */
163
+ createdAt: string;
164
+ }
165
+ /**
166
+ * Options for listing files
167
+ */
168
+ interface ListFilesOptions {
169
+ /** Maximum number of files to return (1-100, default: 20) */
170
+ limit?: number;
171
+ /** Cursor for pagination */
172
+ cursor?: string;
173
+ /** Filter by processing context */
174
+ context?: ProcessingContext;
175
+ /** Filter by file type */
176
+ fileType?: AllowedMimeType;
177
+ }
178
+ /**
179
+ * Result of listing files
180
+ */
181
+ interface ListFilesResult {
182
+ /** Array of file information */
183
+ files: FileInfo[];
184
+ /** Cursor for next page, null if no more pages */
185
+ nextCursor: string | null;
186
+ /** Total number of files matching the query */
187
+ total: number;
188
+ }
189
+ /**
190
+ * Quota usage information
191
+ */
192
+ interface QuotaInfo {
193
+ /** Total quota in bytes */
194
+ quotaBytes: number;
195
+ /** Used storage in bytes */
196
+ usedBytes: number;
197
+ /** Available storage in bytes */
198
+ availableBytes: number;
199
+ /** Usage percentage (0-100) */
200
+ usagePercent: number;
201
+ }
202
+ /**
203
+ * Tenant information
204
+ */
205
+ interface TenantInfo {
206
+ /** Tenant ID */
207
+ id: string;
208
+ /** Tenant name */
209
+ name: string;
210
+ /** Allowed file types for this tenant */
211
+ allowedFileTypes: AllowedMimeType[] | null;
212
+ /** ISO 8601 timestamp */
213
+ createdAt: string;
214
+ }
215
+ /**
216
+ * Upload handshake response
217
+ */
218
+ interface UploadHandshake {
219
+ /** File ID assigned to this upload */
220
+ fileId: string;
221
+ /** Presigned URL for uploading */
222
+ presignedUrl: string;
223
+ /** Expiration timestamp (ISO 8601) */
224
+ expiresAt: string;
225
+ /** Upload constraints */
226
+ uploadMetadata: {
227
+ maxSizeBytes: number;
228
+ allowedTypes: AllowedMimeType[];
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Storage Brain SDK Client
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const storage = new StorageBrain({
238
+ * apiKey: 'sk_live_...',
239
+ * });
240
+ *
241
+ * // Upload a file
242
+ * const file = await storage.upload(fileBlob, {
243
+ * context: 'newsletter',
244
+ * onProgress: (p) => console.log(`${p}%`),
245
+ * });
246
+ *
247
+ * console.log(file.url);
248
+ * ```
249
+ */
250
+ declare class StorageBrain {
251
+ private readonly apiKey;
252
+ private readonly baseUrl;
253
+ private readonly timeout;
254
+ private readonly maxRetries;
255
+ constructor(config: StorageBrainConfig);
256
+ /**
257
+ * Upload a file
258
+ */
259
+ upload(file: File | Blob, options: UploadOptions): Promise<FileInfo>;
260
+ /**
261
+ * Request an upload handshake
262
+ */
263
+ private requestUpload;
264
+ /**
265
+ * Upload file content to presigned URL
266
+ */
267
+ private uploadToPresignedUrl;
268
+ /**
269
+ * Wait for file processing to complete
270
+ */
271
+ private waitForProcessing;
272
+ /**
273
+ * Get a file by ID
274
+ */
275
+ getFile(fileId: string): Promise<FileInfo>;
276
+ /**
277
+ * List files
278
+ */
279
+ listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
280
+ /**
281
+ * Delete a file
282
+ */
283
+ deleteFile(fileId: string): Promise<void>;
284
+ /**
285
+ * Get quota usage
286
+ */
287
+ getQuota(): Promise<QuotaInfo>;
288
+ /**
289
+ * Get tenant information
290
+ */
291
+ getTenantInfo(): Promise<TenantInfo>;
292
+ /**
293
+ * Make an authenticated API request with retry logic
294
+ */
295
+ private request;
296
+ }
297
+
298
+ /**
299
+ * Base error class for Storage Brain SDK
300
+ */
301
+ declare class StorageBrainError extends Error {
302
+ code: string;
303
+ statusCode?: number | undefined;
304
+ details?: Record<string, unknown> | undefined;
305
+ constructor(message: string, code: string, statusCode?: number | undefined, details?: Record<string, unknown> | undefined);
306
+ }
307
+ /**
308
+ * Authentication error - invalid or missing API key
309
+ */
310
+ declare class AuthenticationError extends StorageBrainError {
311
+ constructor(message?: string);
312
+ }
313
+ /**
314
+ * Quota exceeded error
315
+ */
316
+ declare class QuotaExceededError extends StorageBrainError {
317
+ quotaBytes?: number | undefined;
318
+ usedBytes?: number | undefined;
319
+ constructor(message?: string, quotaBytes?: number | undefined, usedBytes?: number | undefined);
320
+ }
321
+ /**
322
+ * Invalid file type error
323
+ */
324
+ declare class InvalidFileTypeError extends StorageBrainError {
325
+ constructor(fileType: string, allowedTypes?: string[]);
326
+ }
327
+ /**
328
+ * File too large error
329
+ */
330
+ declare class FileTooLargeError extends StorageBrainError {
331
+ constructor(fileSize: number, maxSize: number);
332
+ }
333
+ /**
334
+ * File not found error
335
+ */
336
+ declare class FileNotFoundError extends StorageBrainError {
337
+ constructor(fileId: string);
338
+ }
339
+ /**
340
+ * Network error - connection issues
341
+ */
342
+ declare class NetworkError extends StorageBrainError {
343
+ originalError?: Error | undefined;
344
+ constructor(message?: string, originalError?: Error | undefined);
345
+ }
346
+ /**
347
+ * Upload error - file upload failed
348
+ */
349
+ declare class UploadError extends StorageBrainError {
350
+ originalError?: Error | undefined;
351
+ constructor(message: string, originalError?: Error | undefined);
352
+ }
353
+ /**
354
+ * Validation error - request validation failed
355
+ */
356
+ declare class ValidationError extends StorageBrainError {
357
+ errors?: Array<{
358
+ path: string;
359
+ message: string;
360
+ }> | undefined;
361
+ constructor(message: string, errors?: Array<{
362
+ path: string;
363
+ message: string;
364
+ }> | undefined);
365
+ }
366
+
367
+ export { ALLOWED_FILE_TYPES, ALLOWED_MIME_TYPES, type AllowedMimeType, AuthenticationError, type BoundingBox, DOCUMENT_MIME_TYPES, type FileInfo, type FileMetadata, FileNotFoundError, FileTooLargeError, IMAGE_MIME_TYPES, type ImageInfo, InvalidFileTypeError, type ListFilesOptions, type ListFilesResult, MAX_FILE_SIZE_BYTES, NetworkError, type OcrBlock, type OcrResult, PROCESSING_CONTEXTS, PROCESSING_STATUSES, type ProcessingContext, type ProcessingStatus, QuotaExceededError, type QuotaInfo, StorageBrain, type StorageBrainConfig, StorageBrainError, THUMBNAIL_SIZES, type TenantInfo, type ThumbnailSize, type ThumbnailUrls, UploadError, type UploadHandshake, type UploadOptions, ValidationError, StorageBrain as default };