@withvlibe/storage-sdk 1.0.0 → 1.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,246 @@
1
+ /**
2
+ * Vlibe Storage SDK Types
3
+ */
4
+ interface VlibeStorageConfig {
5
+ /** Your Vlibe App ID */
6
+ appId: string;
7
+ /** Your Vlibe App Secret */
8
+ appSecret: string;
9
+ /** Base URL for the Vlibe API (defaults to production) */
10
+ baseUrl?: string;
11
+ }
12
+ interface StorageFile {
13
+ id: string;
14
+ key: string;
15
+ filename: string;
16
+ size: number;
17
+ mimeType: string;
18
+ isPublic: boolean;
19
+ folder: string | null;
20
+ url?: string;
21
+ createdAt: string;
22
+ }
23
+ interface UploadOptions {
24
+ /** Folder/category for the file */
25
+ folder?: string;
26
+ /** Custom filename (auto-generated if not provided) */
27
+ filename?: string;
28
+ /** Make file publicly accessible */
29
+ isPublic?: boolean;
30
+ /** Progress callback (0-100) */
31
+ onProgress?: (progress: number) => void;
32
+ }
33
+ interface UploadResult {
34
+ id: string;
35
+ key: string;
36
+ filename: string;
37
+ size: number;
38
+ mimeType: string;
39
+ url: string;
40
+ isPublic: boolean;
41
+ }
42
+ interface ListOptions {
43
+ /** Filter by folder */
44
+ folder?: string;
45
+ /** Maximum files to return */
46
+ limit?: number;
47
+ /** Offset for pagination */
48
+ offset?: number;
49
+ }
50
+ interface ListResult {
51
+ files: StorageFile[];
52
+ total: number;
53
+ hasMore: boolean;
54
+ }
55
+ interface StorageStats {
56
+ bytesUsed: number;
57
+ bytesUsedFormatted: string;
58
+ fileCount: number;
59
+ storageLimit: number;
60
+ storageLimitFormatted: string;
61
+ usagePercent: number;
62
+ month: string;
63
+ monthlyStats: {
64
+ bytesUploaded: number;
65
+ bytesUploadedFormatted: string;
66
+ bytesDeleted: number;
67
+ bytesDeletedFormatted: string;
68
+ };
69
+ ownerType: 'platform_user' | 'creator';
70
+ }
71
+ interface CanUploadResult {
72
+ allowed: boolean;
73
+ reason?: string;
74
+ }
75
+ interface PresignedUpload {
76
+ uploadUrl: string;
77
+ key: string;
78
+ expiresIn: number;
79
+ }
80
+ interface Folder {
81
+ id: string;
82
+ name: string;
83
+ parentId: string | null;
84
+ projectId: string | null;
85
+ isProjectRoot: boolean;
86
+ fileCount: number;
87
+ createdAt: string;
88
+ }
89
+ interface CreateFolderOptions {
90
+ /** Parent folder ID (null for root level) */
91
+ parentId?: string;
92
+ /** Associate folder with a project */
93
+ projectId?: string;
94
+ /** Mark as project root folder */
95
+ isProjectRoot?: boolean;
96
+ }
97
+ interface ListFoldersOptions {
98
+ /** Filter by parent folder ID (null for root level) */
99
+ parentId?: string | null;
100
+ /** Filter by project ID */
101
+ projectId?: string;
102
+ }
103
+ interface FileReference {
104
+ id: string;
105
+ sourceFileId: string;
106
+ targetProjectId: string;
107
+ createdAt: string;
108
+ }
109
+ interface FileCopyResult {
110
+ id: string;
111
+ key: string;
112
+ filename: string;
113
+ size: number;
114
+ mimeType: string;
115
+ url: string;
116
+ isPublic: boolean;
117
+ }
118
+ type StorageProviderType = 'r2' | 'wasabi';
119
+ interface StorageConfig {
120
+ provider: StorageProviderType;
121
+ publicUrlBase: string;
122
+ }
123
+
124
+ /**
125
+ * VlibeStorage - Main SDK class
126
+ */
127
+
128
+ declare class VlibeStorage {
129
+ private appId;
130
+ private appSecret;
131
+ private baseUrl;
132
+ private authToken;
133
+ private storageConfig;
134
+ constructor(config: VlibeStorageConfig);
135
+ /**
136
+ * Set the user's auth token (required for authenticated requests)
137
+ */
138
+ setAuthToken(token: string): void;
139
+ /**
140
+ * Clear the auth token
141
+ */
142
+ clearAuthToken(): void;
143
+ /**
144
+ * Get storage configuration from the server
145
+ * This fetches the current storage provider and public URL base
146
+ */
147
+ getStorageConfig(): Promise<StorageConfig>;
148
+ /**
149
+ * Clear cached storage config (call if config might have changed)
150
+ */
151
+ clearStorageConfigCache(): void;
152
+ /**
153
+ * Make an authenticated API request
154
+ */
155
+ private request;
156
+ /**
157
+ * Upload a file directly
158
+ */
159
+ upload(file: File | Blob, options?: UploadOptions): Promise<UploadResult>;
160
+ /**
161
+ * Get a presigned URL for direct upload to storage
162
+ * Useful for large files or when you want upload progress
163
+ */
164
+ getUploadUrl(filename: string, mimeType: string, size: number, options?: Omit<UploadOptions, 'onProgress'>): Promise<PresignedUpload>;
165
+ /**
166
+ * Upload a file using presigned URL (for progress tracking)
167
+ */
168
+ uploadWithProgress(file: File, options?: UploadOptions): Promise<UploadResult>;
169
+ /**
170
+ * Get a signed download URL for a file
171
+ */
172
+ getDownloadUrl(fileId: string, expiresIn?: number): Promise<string>;
173
+ /**
174
+ * Get a public URL for a file (only works for public files in the public path)
175
+ * Returns the direct URL based on the configured storage provider
176
+ *
177
+ * Note: This is a sync method that uses cached config. Call getStorageConfig()
178
+ * first to ensure the config is loaded, or use getPublicUrlAsync() for a
179
+ * guaranteed fresh URL.
180
+ */
181
+ getPublicUrl(key: string): string;
182
+ /**
183
+ * Get a public URL for a file (async version that ensures fresh config)
184
+ * Returns the direct URL based on the configured storage provider
185
+ */
186
+ getPublicUrlAsync(key: string): Promise<string>;
187
+ /**
188
+ * Check if a storage key is in the public path
189
+ */
190
+ isPublicKey(key: string): boolean;
191
+ /**
192
+ * List files
193
+ */
194
+ list(options?: ListOptions): Promise<ListResult>;
195
+ /**
196
+ * Get a single file's metadata
197
+ */
198
+ get(fileId: string): Promise<StorageFile | null>;
199
+ /**
200
+ * Delete a file
201
+ */
202
+ delete(fileId: string): Promise<boolean>;
203
+ /**
204
+ * Delete multiple files
205
+ */
206
+ deleteMany(fileIds: string[]): Promise<{
207
+ deleted: string[];
208
+ failed: string[];
209
+ }>;
210
+ /**
211
+ * Get storage usage statistics
212
+ */
213
+ getUsage(): Promise<StorageStats>;
214
+ /**
215
+ * Check if a file of given size can be uploaded
216
+ */
217
+ canUpload(size: number): Promise<CanUploadResult>;
218
+ /**
219
+ * List folders
220
+ */
221
+ listFolders(options?: ListFoldersOptions): Promise<Folder[]>;
222
+ /**
223
+ * Create a folder
224
+ */
225
+ createFolder(name: string, options?: CreateFolderOptions): Promise<Folder>;
226
+ /**
227
+ * Rename a folder
228
+ */
229
+ renameFolder(folderId: string, name: string): Promise<Folder>;
230
+ /**
231
+ * Delete a folder (must be empty)
232
+ */
233
+ deleteFolder(folderId: string): Promise<boolean>;
234
+ /**
235
+ * Copy a file to another project
236
+ * Creates a new database record pointing to the same S3 object
237
+ */
238
+ copyFileToProject(fileId: string, targetProjectId: string): Promise<FileCopyResult>;
239
+ /**
240
+ * Create a file reference (link file to another project without copying)
241
+ * Does not count against storage quota
242
+ */
243
+ createFileReference(fileId: string, targetProjectId: string): Promise<FileReference>;
244
+ }
245
+
246
+ export { type CanUploadResult, type CreateFolderOptions, type FileCopyResult, type FileReference, type Folder, type ListFoldersOptions, type ListOptions, type ListResult, type PresignedUpload, type StorageConfig, type StorageFile, type StorageProviderType, type StorageStats, type UploadOptions, type UploadResult, VlibeStorage, type VlibeStorageConfig };
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Vlibe Storage SDK Types
3
+ */
4
+ interface VlibeStorageConfig {
5
+ /** Your Vlibe App ID */
6
+ appId: string;
7
+ /** Your Vlibe App Secret */
8
+ appSecret: string;
9
+ /** Base URL for the Vlibe API (defaults to production) */
10
+ baseUrl?: string;
11
+ }
12
+ interface StorageFile {
13
+ id: string;
14
+ key: string;
15
+ filename: string;
16
+ size: number;
17
+ mimeType: string;
18
+ isPublic: boolean;
19
+ folder: string | null;
20
+ url?: string;
21
+ createdAt: string;
22
+ }
23
+ interface UploadOptions {
24
+ /** Folder/category for the file */
25
+ folder?: string;
26
+ /** Custom filename (auto-generated if not provided) */
27
+ filename?: string;
28
+ /** Make file publicly accessible */
29
+ isPublic?: boolean;
30
+ /** Progress callback (0-100) */
31
+ onProgress?: (progress: number) => void;
32
+ }
33
+ interface UploadResult {
34
+ id: string;
35
+ key: string;
36
+ filename: string;
37
+ size: number;
38
+ mimeType: string;
39
+ url: string;
40
+ isPublic: boolean;
41
+ }
42
+ interface ListOptions {
43
+ /** Filter by folder */
44
+ folder?: string;
45
+ /** Maximum files to return */
46
+ limit?: number;
47
+ /** Offset for pagination */
48
+ offset?: number;
49
+ }
50
+ interface ListResult {
51
+ files: StorageFile[];
52
+ total: number;
53
+ hasMore: boolean;
54
+ }
55
+ interface StorageStats {
56
+ bytesUsed: number;
57
+ bytesUsedFormatted: string;
58
+ fileCount: number;
59
+ storageLimit: number;
60
+ storageLimitFormatted: string;
61
+ usagePercent: number;
62
+ month: string;
63
+ monthlyStats: {
64
+ bytesUploaded: number;
65
+ bytesUploadedFormatted: string;
66
+ bytesDeleted: number;
67
+ bytesDeletedFormatted: string;
68
+ };
69
+ ownerType: 'platform_user' | 'creator';
70
+ }
71
+ interface CanUploadResult {
72
+ allowed: boolean;
73
+ reason?: string;
74
+ }
75
+ interface PresignedUpload {
76
+ uploadUrl: string;
77
+ key: string;
78
+ expiresIn: number;
79
+ }
80
+ interface Folder {
81
+ id: string;
82
+ name: string;
83
+ parentId: string | null;
84
+ projectId: string | null;
85
+ isProjectRoot: boolean;
86
+ fileCount: number;
87
+ createdAt: string;
88
+ }
89
+ interface CreateFolderOptions {
90
+ /** Parent folder ID (null for root level) */
91
+ parentId?: string;
92
+ /** Associate folder with a project */
93
+ projectId?: string;
94
+ /** Mark as project root folder */
95
+ isProjectRoot?: boolean;
96
+ }
97
+ interface ListFoldersOptions {
98
+ /** Filter by parent folder ID (null for root level) */
99
+ parentId?: string | null;
100
+ /** Filter by project ID */
101
+ projectId?: string;
102
+ }
103
+ interface FileReference {
104
+ id: string;
105
+ sourceFileId: string;
106
+ targetProjectId: string;
107
+ createdAt: string;
108
+ }
109
+ interface FileCopyResult {
110
+ id: string;
111
+ key: string;
112
+ filename: string;
113
+ size: number;
114
+ mimeType: string;
115
+ url: string;
116
+ isPublic: boolean;
117
+ }
118
+ type StorageProviderType = 'r2' | 'wasabi';
119
+ interface StorageConfig {
120
+ provider: StorageProviderType;
121
+ publicUrlBase: string;
122
+ }
123
+
124
+ /**
125
+ * VlibeStorage - Main SDK class
126
+ */
127
+
128
+ declare class VlibeStorage {
129
+ private appId;
130
+ private appSecret;
131
+ private baseUrl;
132
+ private authToken;
133
+ private storageConfig;
134
+ constructor(config: VlibeStorageConfig);
135
+ /**
136
+ * Set the user's auth token (required for authenticated requests)
137
+ */
138
+ setAuthToken(token: string): void;
139
+ /**
140
+ * Clear the auth token
141
+ */
142
+ clearAuthToken(): void;
143
+ /**
144
+ * Get storage configuration from the server
145
+ * This fetches the current storage provider and public URL base
146
+ */
147
+ getStorageConfig(): Promise<StorageConfig>;
148
+ /**
149
+ * Clear cached storage config (call if config might have changed)
150
+ */
151
+ clearStorageConfigCache(): void;
152
+ /**
153
+ * Make an authenticated API request
154
+ */
155
+ private request;
156
+ /**
157
+ * Upload a file directly
158
+ */
159
+ upload(file: File | Blob, options?: UploadOptions): Promise<UploadResult>;
160
+ /**
161
+ * Get a presigned URL for direct upload to storage
162
+ * Useful for large files or when you want upload progress
163
+ */
164
+ getUploadUrl(filename: string, mimeType: string, size: number, options?: Omit<UploadOptions, 'onProgress'>): Promise<PresignedUpload>;
165
+ /**
166
+ * Upload a file using presigned URL (for progress tracking)
167
+ */
168
+ uploadWithProgress(file: File, options?: UploadOptions): Promise<UploadResult>;
169
+ /**
170
+ * Get a signed download URL for a file
171
+ */
172
+ getDownloadUrl(fileId: string, expiresIn?: number): Promise<string>;
173
+ /**
174
+ * Get a public URL for a file (only works for public files in the public path)
175
+ * Returns the direct URL based on the configured storage provider
176
+ *
177
+ * Note: This is a sync method that uses cached config. Call getStorageConfig()
178
+ * first to ensure the config is loaded, or use getPublicUrlAsync() for a
179
+ * guaranteed fresh URL.
180
+ */
181
+ getPublicUrl(key: string): string;
182
+ /**
183
+ * Get a public URL for a file (async version that ensures fresh config)
184
+ * Returns the direct URL based on the configured storage provider
185
+ */
186
+ getPublicUrlAsync(key: string): Promise<string>;
187
+ /**
188
+ * Check if a storage key is in the public path
189
+ */
190
+ isPublicKey(key: string): boolean;
191
+ /**
192
+ * List files
193
+ */
194
+ list(options?: ListOptions): Promise<ListResult>;
195
+ /**
196
+ * Get a single file's metadata
197
+ */
198
+ get(fileId: string): Promise<StorageFile | null>;
199
+ /**
200
+ * Delete a file
201
+ */
202
+ delete(fileId: string): Promise<boolean>;
203
+ /**
204
+ * Delete multiple files
205
+ */
206
+ deleteMany(fileIds: string[]): Promise<{
207
+ deleted: string[];
208
+ failed: string[];
209
+ }>;
210
+ /**
211
+ * Get storage usage statistics
212
+ */
213
+ getUsage(): Promise<StorageStats>;
214
+ /**
215
+ * Check if a file of given size can be uploaded
216
+ */
217
+ canUpload(size: number): Promise<CanUploadResult>;
218
+ /**
219
+ * List folders
220
+ */
221
+ listFolders(options?: ListFoldersOptions): Promise<Folder[]>;
222
+ /**
223
+ * Create a folder
224
+ */
225
+ createFolder(name: string, options?: CreateFolderOptions): Promise<Folder>;
226
+ /**
227
+ * Rename a folder
228
+ */
229
+ renameFolder(folderId: string, name: string): Promise<Folder>;
230
+ /**
231
+ * Delete a folder (must be empty)
232
+ */
233
+ deleteFolder(folderId: string): Promise<boolean>;
234
+ /**
235
+ * Copy a file to another project
236
+ * Creates a new database record pointing to the same S3 object
237
+ */
238
+ copyFileToProject(fileId: string, targetProjectId: string): Promise<FileCopyResult>;
239
+ /**
240
+ * Create a file reference (link file to another project without copying)
241
+ * Does not count against storage quota
242
+ */
243
+ createFileReference(fileId: string, targetProjectId: string): Promise<FileReference>;
244
+ }
245
+
246
+ export { type CanUploadResult, type CreateFolderOptions, type FileCopyResult, type FileReference, type Folder, type ListFoldersOptions, type ListOptions, type ListResult, type PresignedUpload, type StorageConfig, type StorageFile, type StorageProviderType, type StorageStats, type UploadOptions, type UploadResult, VlibeStorage, type VlibeStorageConfig };