@memberjunction/storage 2.39.0 → 2.41.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.
Files changed (38) hide show
  1. package/dist/drivers/AWSFileStorage.d.ts +360 -4
  2. package/dist/drivers/AWSFileStorage.d.ts.map +1 -1
  3. package/dist/drivers/AWSFileStorage.js +357 -4
  4. package/dist/drivers/AWSFileStorage.js.map +1 -1
  5. package/dist/drivers/AzureFileStorage.d.ts +362 -2
  6. package/dist/drivers/AzureFileStorage.d.ts.map +1 -1
  7. package/dist/drivers/AzureFileStorage.js +357 -2
  8. package/dist/drivers/AzureFileStorage.js.map +1 -1
  9. package/dist/drivers/BoxFileStorage.d.ts +648 -20
  10. package/dist/drivers/BoxFileStorage.d.ts.map +1 -1
  11. package/dist/drivers/BoxFileStorage.js +951 -126
  12. package/dist/drivers/BoxFileStorage.js.map +1 -1
  13. package/dist/drivers/DropboxFileStorage.d.ts +437 -15
  14. package/dist/drivers/DropboxFileStorage.d.ts.map +1 -1
  15. package/dist/drivers/DropboxFileStorage.js +431 -15
  16. package/dist/drivers/DropboxFileStorage.js.map +1 -1
  17. package/dist/drivers/GoogleDriveFileStorage.d.ts +342 -16
  18. package/dist/drivers/GoogleDriveFileStorage.d.ts.map +1 -1
  19. package/dist/drivers/GoogleDriveFileStorage.js +340 -16
  20. package/dist/drivers/GoogleDriveFileStorage.js.map +1 -1
  21. package/dist/drivers/GoogleFileStorage.d.ts +358 -2
  22. package/dist/drivers/GoogleFileStorage.d.ts.map +1 -1
  23. package/dist/drivers/GoogleFileStorage.js +356 -2
  24. package/dist/drivers/GoogleFileStorage.js.map +1 -1
  25. package/dist/drivers/SharePointFileStorage.d.ts +434 -20
  26. package/dist/drivers/SharePointFileStorage.d.ts.map +1 -1
  27. package/dist/drivers/SharePointFileStorage.js +453 -22
  28. package/dist/drivers/SharePointFileStorage.js.map +1 -1
  29. package/dist/generic/FileStorageBase.d.ts +326 -108
  30. package/dist/generic/FileStorageBase.d.ts.map +1 -1
  31. package/dist/generic/FileStorageBase.js +54 -6
  32. package/dist/generic/FileStorageBase.js.map +1 -1
  33. package/dist/util.d.ts +125 -18
  34. package/dist/util.d.ts.map +1 -1
  35. package/dist/util.js +125 -18
  36. package/dist/util.js.map +1 -1
  37. package/package.json +8 -7
  38. package/readme.md +211 -1
@@ -1,94 +1,722 @@
1
1
  /// <reference types="node" />
2
2
  import { CreatePreAuthUploadUrlPayload, FileStorageBase, StorageListResult, StorageObjectMetadata } from '../generic/FileStorageBase';
3
+ /**
4
+ * FileStorageBase implementation for Box.com cloud storage
5
+ *
6
+ * This provider allows working with files stored in Box.com. It supports
7
+ * authentication via access token, refresh token, or client credentials (JWT).
8
+ *
9
+ * @remarks
10
+ * This implementation requires at least one of the following authentication methods:
11
+ *
12
+ * 1. Access Token:
13
+ * - STORAGE_BOX_ACCESS_TOKEN - A valid Box API access token
14
+ *
15
+ * 2. Refresh Token:
16
+ * - STORAGE_BOX_REFRESH_TOKEN - A valid Box API refresh token
17
+ * - STORAGE_BOX_CLIENT_ID - Your Box application client ID
18
+ * - STORAGE_BOX_CLIENT_SECRET - Your Box application client secret
19
+ *
20
+ * 3. Client Credentials (JWT):
21
+ * - STORAGE_BOX_CLIENT_ID - Your Box application client ID
22
+ * - STORAGE_BOX_CLIENT_SECRET - Your Box application client secret
23
+ * - STORAGE_BOX_ENTERPRISE_ID - Your Box enterprise ID
24
+ *
25
+ * Optional configuration:
26
+ * - STORAGE_BOX_ROOT_FOLDER_ID - ID of a Box folder to use as the root (defaults to '0' which is the root)
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // Set required environment variables for JWT auth
31
+ * process.env.STORAGE_BOX_CLIENT_ID = 'your-client-id';
32
+ * process.env.STORAGE_BOX_CLIENT_SECRET = 'your-client-secret';
33
+ * process.env.STORAGE_BOX_ENTERPRISE_ID = 'your-enterprise-id';
34
+ *
35
+ * // Create the provider
36
+ * const storage = new BoxFileStorage();
37
+ * await storage.initialize(); // Required for JWT auth
38
+ *
39
+ * // Upload a file
40
+ * const fileContent = Buffer.from('Hello, Box!');
41
+ * await storage.PutObject('documents/hello.txt', fileContent, 'text/plain');
42
+ *
43
+ * // Download a file
44
+ * const downloadedContent = await storage.GetObject('documents/hello.txt');
45
+ *
46
+ * // Get a temporary download URL
47
+ * const downloadUrl = await storage.CreatePreAuthDownloadUrl('documents/hello.txt');
48
+ * ```
49
+ */
3
50
  export declare class BoxFileStorage extends FileStorageBase {
51
+ /**
52
+ * The name of this storage provider
53
+ */
4
54
  protected readonly providerName = "Box";
55
+ /**
56
+ * Box API access token
57
+ */
5
58
  private _accessToken;
59
+ /**
60
+ * Box API refresh token
61
+ */
6
62
  private _refreshToken;
63
+ /**
64
+ * Box application client ID
65
+ */
7
66
  private _clientId;
67
+ /**
68
+ * Box application client secret
69
+ */
8
70
  private _clientSecret;
71
+ /**
72
+ * Timestamp when current access token expires
73
+ */
9
74
  private _tokenExpiresAt;
75
+ /**
76
+ * Base URL for Box API
77
+ */
10
78
  private _baseApiUrl;
79
+ /**
80
+ * Base URL for Box Upload API
81
+ */
11
82
  private _uploadApiUrl;
83
+ /**
84
+ * ID of the Box folder to use as root
85
+ */
12
86
  private _rootFolderId;
87
+ /**
88
+ * Box enterprise ID for JWT auth
89
+ */
13
90
  private _enterpriseId;
91
+ /**
92
+ * Box Client
93
+ */
94
+ private _client;
95
+ /**
96
+ * Creates a new BoxFileStorage instance
97
+ *
98
+ * This constructor reads the required Box authentication configuration
99
+ * from environment variables.
100
+ *
101
+ * @throws Error if refresh token is provided without client ID and secret
102
+ */
14
103
  constructor();
15
104
  /**
16
- * Initialize the storage driver by setting up the access token
17
- * This should be called after construction
105
+ * Initializes the Box storage driver
106
+ *
107
+ * This method must be called after creating a BoxFileStorage instance
108
+ * when using client credentials (JWT) authentication. It obtains the
109
+ * initial access token required for API calls.
110
+ *
111
+ * @returns A Promise that resolves when initialization is complete
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const storage = new BoxFileStorage();
116
+ * await storage.initialize();
117
+ * // Now the storage provider is ready to use
118
+ * ```
18
119
  */
19
120
  initialize(): Promise<void>;
121
+ /**
122
+ * Initializes the Box client instance
123
+ *
124
+ * This method creates a new Box SDK client using the current credentials
125
+ * and access token, making it ready for API operations.
126
+ *
127
+ * @private
128
+ * @returns A Promise that resolves when the client is initialized
129
+ */
130
+ private _setClient;
131
+ /**
132
+ * Obtains an access token using client credentials flow
133
+ *
134
+ * This method requests a new access token using the Box client credentials
135
+ * flow (JWT) with the enterprise as the subject.
136
+ *
137
+ * @private
138
+ * @returns A Promise that resolves when the access token is obtained
139
+ * @throws Error if token acquisition fails
140
+ */
20
141
  private _setAccessToken;
21
142
  /**
22
- * Ensures we have a valid access token
143
+ * Returns the current Box API access token
144
+ *
145
+ * This method ensures a valid token is available before returning it,
146
+ * refreshing or generating a new token if necessary.
147
+ *
148
+ * @returns A Promise that resolves to a valid access token string
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Get a valid Box access token
153
+ * const token = await storage.AccessToken();
154
+ * console.log(`Using access token: ${token}`);
155
+ * ```
156
+ */
157
+ AccessToken(): Promise<string>;
158
+ /**
159
+ * Returns the current Box client instance
160
+ *
161
+ * This method ensures a valid token is available before returning the client,
162
+ * refreshing or generating a new token if necessary.
163
+ *
164
+ * @returns A Promise that resolves to the authenticated Box client instance
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * // Get the Box client for direct API access
169
+ * const client = await storage.BoxClient();
170
+ *
171
+ * // Use the client for Box SDK operations
172
+ * const user = await client.users.get('me');
173
+ * console.log(`Current user: ${user.name}`);
174
+ * ```
175
+ */
176
+ BoxClient(): Promise<any>;
177
+ /**
178
+ * Ensures a valid access token is available for API requests
179
+ *
180
+ * This method checks if the current token is valid, and if not, attempts
181
+ * to refresh or obtain a new token using the configured authentication method.
182
+ *
183
+ * @private
184
+ * @returns A Promise that resolves to a valid access token
185
+ * @throws Error if no valid token can be obtained
23
186
  */
24
187
  private _ensureValidToken;
25
188
  /**
26
- * Make an authenticated API request to Box
189
+ * Makes an authenticated API request to the Box API
190
+ *
191
+ * This helper method handles authentication, request formatting, and
192
+ * response parsing for all Box API calls.
193
+ *
194
+ * @private
195
+ * @param endpoint - The API endpoint to call (e.g., '/files/123')
196
+ * @param method - The HTTP method to use (default: 'GET')
197
+ * @param body - Optional request body (will be serialized as JSON unless it's FormData)
198
+ * @param headers - Optional additional headers
199
+ * @param baseUrl - Base URL to use (defaults to standard API URL)
200
+ * @returns A Promise that resolves to the API response data
201
+ * @throws Error if the API request fails
27
202
  */
28
203
  private _apiRequest;
29
204
  /**
30
- * Parse a Box API path into folder ID and name components
205
+ * Parses a path string into Box API components
206
+ *
207
+ * This helper method converts a standard path string (e.g., 'documents/reports/file.txt')
208
+ * into components used by the Box API (folder ID, name, parent path).
209
+ *
210
+ * @private
211
+ * @param path - The path to parse
212
+ * @returns An object containing the parsed components: id, name, and parent
31
213
  */
32
214
  private _parsePath;
33
215
  /**
34
- * Get item ID by path
216
+ * Resolves a path string to a Box item ID
217
+ *
218
+ * This helper method navigates the Box folder hierarchy to find
219
+ * the item at the specified path, returning its Box ID.
220
+ *
221
+ * @private
222
+ * @param path - The path to resolve
223
+ * @returns A Promise that resolves to the Box item ID
224
+ * @throws Error if the item does not exist
35
225
  */
36
226
  private _getIdFromPath;
37
227
  /**
38
- * Convert Box item to StorageObjectMetadata
228
+ * Converts a Box API item to StorageObjectMetadata
229
+ *
230
+ * This helper method transforms a Box API item representation into
231
+ * the standard StorageObjectMetadata format used by FileStorageBase.
232
+ *
233
+ * @private
234
+ * @param item - The Box API item object
235
+ * @param parentPath - The parent path string
236
+ * @returns A StorageObjectMetadata object
39
237
  */
40
238
  private _convertToMetadata;
41
239
  /**
42
- * Create a pre-authenticated upload URL
240
+ * Creates a pre-authenticated upload URL for a file
241
+ *
242
+ * This method creates a Box upload session and returns a URL that can be used
243
+ * to upload file content directly to Box without requiring authentication.
244
+ *
245
+ * @param objectName - Path where the file should be uploaded (e.g., 'documents/report.pdf')
246
+ * @returns A Promise that resolves to an object containing the upload URL and provider key
247
+ * @throws Error if the URL creation fails
248
+ *
249
+ * @remarks
250
+ * - The parent folder structure will be created automatically if it doesn't exist
251
+ * - The returned provider key contains the session ID needed to complete the upload
252
+ * - Box upload sessions expire after a certain period (typically 1 hour)
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * try {
257
+ * // Generate a pre-authenticated upload URL
258
+ * const uploadInfo = await storage.CreatePreAuthUploadUrl('presentations/quarterly-results.pptx');
259
+ *
260
+ * // The URL can be used to upload content directly
261
+ * console.log(`Upload URL: ${uploadInfo.UploadUrl}`);
262
+ *
263
+ * // Make sure to save the provider key, as it's needed to reference the upload
264
+ * console.log(`Provider Key: ${uploadInfo.ProviderKey}`);
265
+ *
266
+ * // You can use fetch or another HTTP client to upload to this URL
267
+ * await fetch(uploadInfo.UploadUrl, {
268
+ * method: 'PUT',
269
+ * headers: { 'Content-Type': 'application/octet-stream' },
270
+ * body: fileContent
271
+ * });
272
+ * } catch (error) {
273
+ * console.error('Error creating upload URL:', error.message);
274
+ * }
275
+ * ```
43
276
  */
44
277
  CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
45
278
  /**
46
- * Create a pre-authenticated download URL
279
+ * Creates a pre-authenticated download URL for a file
280
+ *
281
+ * This method generates a time-limited URL that can be used to download
282
+ * a file without authentication. The URL typically expires after 60 minutes.
283
+ *
284
+ * @param objectName - Path to the file to download (e.g., 'documents/report.pdf')
285
+ * @returns A Promise that resolves to the download URL string
286
+ * @throws Error if the file doesn't exist or URL creation fails
287
+ *
288
+ * @remarks
289
+ * - Cannot be used with upload sessions that haven't been completed
290
+ * - Box download URLs typically expire after 60 minutes
291
+ * - Generated URLs can be shared with users who don't have Box access
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * try {
296
+ * // Generate a pre-authenticated download URL
297
+ * const downloadUrl = await storage.CreatePreAuthDownloadUrl('documents/financial-report.pdf');
298
+ *
299
+ * console.log(`Download the file using this URL: ${downloadUrl}`);
300
+ *
301
+ * // The URL can be shared or used in a browser to download the file
302
+ * // without requiring Box authentication
303
+ * } catch (error) {
304
+ * console.error('Error creating download URL:', error.message);
305
+ * }
306
+ * ```
47
307
  */
48
308
  CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
49
309
  /**
50
- * Move an object
310
+ * Moves a file or folder from one location to another
311
+ *
312
+ * This method moves a file or folder to a new location in Box storage.
313
+ * It handles both renaming and changing the parent folder.
314
+ *
315
+ * @param oldObjectName - Current path of the object (e.g., 'old-folder/document.docx')
316
+ * @param newObjectName - New path for the object (e.g., 'new-folder/renamed-document.docx')
317
+ * @returns A Promise that resolves to true if successful, false otherwise
318
+ *
319
+ * @remarks
320
+ * - Parent folders will be created automatically if they don't exist
321
+ * - Works with both files and folders
322
+ * - For folders, all contents will move with the folder
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * // Move a file to a different folder and rename it
327
+ * const moveResult = await storage.MoveObject(
328
+ * 'documents/old-report.pdf',
329
+ * 'archive/2023/annual-report.pdf'
330
+ * );
331
+ *
332
+ * if (moveResult) {
333
+ * console.log('File moved successfully');
334
+ * } else {
335
+ * console.error('Failed to move file');
336
+ * }
337
+ * ```
51
338
  */
52
339
  MoveObject(oldObjectName: string, newObjectName: string): Promise<boolean>;
53
340
  /**
54
- * Delete an object
341
+ * Deletes a file or folder from Box storage
342
+ *
343
+ * This method permanently deletes a file or folder. It can also
344
+ * handle special cases like incomplete upload sessions.
345
+ *
346
+ * @param objectName - Path to the object to delete (e.g., 'documents/old-report.docx')
347
+ * @returns A Promise that resolves to true if successful, false if an error occurs
348
+ *
349
+ * @remarks
350
+ * - Returns true if the object doesn't exist (for idempotency)
351
+ * - Can handle special provider keys like upload sessions
352
+ * - Box puts deleted items in the trash, where they can be recovered for a limited time
353
+ * - To permanently delete folder contents, use DeleteDirectory with recursive=true
354
+ *
355
+ * @example
356
+ * ```typescript
357
+ * // Delete a file
358
+ * const deleteResult = await storage.DeleteObject('temp/draft-document.docx');
359
+ *
360
+ * if (deleteResult) {
361
+ * console.log('File deleted successfully or already didn\'t exist');
362
+ * } else {
363
+ * console.error('Failed to delete file');
364
+ * }
365
+ *
366
+ * // Delete an upload session
367
+ * await storage.DeleteObject('session:1234567890:documents/large-file.zip');
368
+ * ```
55
369
  */
56
370
  DeleteObject(objectName: string): Promise<boolean>;
57
371
  /**
58
- * List objects in a directory
372
+ * Lists files and folders in a given directory
373
+ *
374
+ * This method retrieves all files and subfolders in the specified directory.
375
+ * It returns both a list of object metadata and a list of directory prefixes.
376
+ *
377
+ * @param prefix - Path to the directory to list (e.g., 'documents/reports')
378
+ * @param delimiter - Optional delimiter character (default: '/')
379
+ * @returns A Promise that resolves to a StorageListResult containing objects and prefixes
380
+ *
381
+ * @remarks
382
+ * - The `objects` array includes both files and folders
383
+ * - The `prefixes` array includes only folder paths (with trailing slashes)
384
+ * - Returns empty arrays if the directory doesn't exist
385
+ * - The delimiter parameter is included for interface compatibility but not used internally
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * // List all files and folders in the 'documents' directory
390
+ * const result = await storage.ListObjects('documents');
391
+ *
392
+ * // Process files and folders
393
+ * console.log(`Found ${result.objects.length} items:`);
394
+ * for (const obj of result.objects) {
395
+ * console.log(`- ${obj.name} (${obj.isDirectory ? 'Folder' : 'File'}, ${obj.size} bytes)`);
396
+ * }
397
+ *
398
+ * // List subfolders only
399
+ * console.log(`Found ${result.prefixes.length} subfolders:`);
400
+ * for (const prefix of result.prefixes) {
401
+ * console.log(`- ${prefix}`);
402
+ * }
403
+ * ```
59
404
  */
60
405
  ListObjects(prefix: string, delimiter?: string): Promise<StorageListResult>;
61
406
  /**
62
- * Create a directory
407
+ * Creates a new directory (folder) in Box storage
408
+ *
409
+ * This method creates a folder at the specified path, automatically
410
+ * creating any parent folders that don't exist.
411
+ *
412
+ * @param directoryPath - Path where the directory should be created (e.g., 'documents/reports/2023')
413
+ * @returns A Promise that resolves to true if successful, false if an error occurs
414
+ *
415
+ * @remarks
416
+ * - Creates parent directories recursively if they don't exist
417
+ * - Returns true if the directory already exists (idempotent operation)
418
+ * - Trailing slashes in the path are automatically removed
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * // Create a nested directory structure
423
+ * const createResult = await storage.CreateDirectory('documents/reports/2023/Q1');
424
+ *
425
+ * if (createResult) {
426
+ * console.log('Directory created successfully');
427
+ *
428
+ * // Now we can put files in this directory
429
+ * await storage.PutObject(
430
+ * 'documents/reports/2023/Q1/financial-summary.xlsx',
431
+ * fileContent,
432
+ * 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
433
+ * );
434
+ * } else {
435
+ * console.error('Failed to create directory');
436
+ * }
437
+ * ```
63
438
  */
64
439
  CreateDirectory(directoryPath: string): Promise<boolean>;
65
440
  /**
66
- * Delete a directory
441
+ * Gets file representation information for a Box file
442
+ *
443
+ * This method retrieves information about available representations
444
+ * (such as thumbnails, previews, or other formats) for a specific file.
445
+ *
446
+ * @param fileId - The Box file ID to get representations for
447
+ * @param repHints - The representation hints string (format and options)
448
+ * @returns A Promise that resolves to a JSON object containing representations data
449
+ * @throws Error if the request fails
450
+ *
451
+ * @remarks
452
+ * - Requires a valid file ID (not a path)
453
+ * - The repHints parameter controls what type of representations are returned
454
+ * - Common representation types include thumbnails, preview images, and text extractions
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * try {
459
+ * // Get a high-resolution PNG representation of a file
460
+ * const fileId = '12345';
461
+ * const representations = await storage.GetFileRepresentations(
462
+ * fileId,
463
+ * 'png?dimensions=2048x2048'
464
+ * );
465
+ *
466
+ * // Process the representation information
467
+ * console.log('Available representations:', representations);
468
+ * } catch (error) {
469
+ * console.error('Error getting representations:', error.message);
470
+ * }
471
+ * ```
472
+ */
473
+ GetFileRepresentations(fileId: string, repHints?: string): Promise<JSON>;
474
+ /**
475
+ * Helper function for making HTTP requests
476
+ *
477
+ * This method provides a Promise-based wrapper around Node.js https requests,
478
+ * simplifying the process of making API calls to the Box API.
479
+ *
480
+ * @private
481
+ * @param options - The HTTPS request options (URL, method, headers, etc.)
482
+ * @param data - Optional string data to send with the request
483
+ * @returns A Promise that resolves to the response data as a string
484
+ * @throws Error if the request fails or returns a non-2xx status code
485
+ */
486
+ private _makeRequest;
487
+ /**
488
+ * Deletes a directory from Box storage
489
+ *
490
+ * This method deletes a folder and optionally its contents. By default,
491
+ * it will only delete empty folders unless recursive is set to true.
492
+ *
493
+ * @param directoryPath - Path to the directory to delete (e.g., 'documents/old-reports')
494
+ * @param recursive - If true, delete the directory and all its contents; if false, only delete if empty
495
+ * @returns A Promise that resolves to true if successful, false if an error occurs
496
+ *
497
+ * @remarks
498
+ * - Returns true if the directory doesn't exist (idempotent operation)
499
+ * - If recursive=false and the directory contains files, the operation will fail
500
+ * - Box puts deleted folders in the trash, where they can be recovered for a limited time
501
+ * - Trailing slashes in the path are automatically removed
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * // Try to delete an empty folder
506
+ * const deleteResult = await storage.DeleteDirectory('temp/empty-folder');
507
+ *
508
+ * // Delete a folder and all its contents
509
+ * const recursiveDeleteResult = await storage.DeleteDirectory('archive/old-data', true);
510
+ *
511
+ * if (recursiveDeleteResult) {
512
+ * console.log('Folder and all its contents deleted successfully');
513
+ * } else {
514
+ * console.error('Failed to delete folder');
515
+ * }
516
+ * ```
67
517
  */
68
518
  DeleteDirectory(directoryPath: string, recursive?: boolean): Promise<boolean>;
69
519
  /**
70
- * Get object metadata
520
+ * Gets metadata for a file or folder
521
+ *
522
+ * This method retrieves metadata about a file or folder in Box storage,
523
+ * such as size, type, and modification date.
524
+ *
525
+ * @param objectName - Path to the object to get metadata for (e.g., 'documents/report.pdf')
526
+ * @returns A Promise that resolves to a StorageObjectMetadata object
527
+ * @throws Error if the object doesn't exist or cannot be accessed
528
+ *
529
+ * @example
530
+ * ```typescript
531
+ * try {
532
+ * // Get metadata for a file
533
+ * const metadata = await storage.GetObjectMetadata('presentations/quarterly-update.pptx');
534
+ *
535
+ * console.log(`Name: ${metadata.name}`);
536
+ * console.log(`Path: ${metadata.path}`);
537
+ * console.log(`Size: ${metadata.size} bytes`);
538
+ * console.log(`Content Type: ${metadata.contentType}`);
539
+ * console.log(`Last Modified: ${metadata.lastModified}`);
540
+ * console.log(`Is Directory: ${metadata.isDirectory}`);
541
+ *
542
+ * // Box-specific metadata is available in customMetadata
543
+ * console.log(`Box ID: ${metadata.customMetadata.id}`);
544
+ * } catch (error) {
545
+ * console.error('Error getting metadata:', error.message);
546
+ * }
547
+ * ```
71
548
  */
72
549
  GetObjectMetadata(objectName: string): Promise<StorageObjectMetadata>;
73
550
  /**
74
- * Get an object's contents
551
+ * Downloads a file's contents
552
+ *
553
+ * This method retrieves the raw content of a file as a Buffer.
554
+ *
555
+ * @param objectName - Path to the file to download (e.g., 'documents/report.pdf')
556
+ * @returns A Promise that resolves to a Buffer containing the file's contents
557
+ * @throws Error if the file doesn't exist or cannot be downloaded
558
+ *
559
+ * @remarks
560
+ * - This method will throw an error if the object is a folder
561
+ * - For large files, consider using CreatePreAuthDownloadUrl instead
562
+ * - For upload sessions that haven't been completed, this method will fail
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * try {
567
+ * // Download a text file
568
+ * const fileContent = await storage.GetObject('documents/notes.txt');
569
+ *
570
+ * // Convert Buffer to string for text files
571
+ * const textContent = fileContent.toString('utf8');
572
+ * console.log('File content:', textContent);
573
+ *
574
+ * // For binary files, you can write the buffer to disk
575
+ * // or process it as needed
576
+ * } catch (error) {
577
+ * console.error('Error downloading file:', error.message);
578
+ * }
579
+ * ```
75
580
  */
76
581
  GetObject(objectName: string): Promise<Buffer>;
77
582
  /**
78
- * Upload an object
583
+ * Uploads a file to Box storage
584
+ *
585
+ * This method uploads a file to the specified path in Box storage. It automatically
586
+ * determines whether to use a simple upload or chunked upload based on file size.
587
+ *
588
+ * @param objectName - Path where the file should be uploaded (e.g., 'documents/report.pdf')
589
+ * @param data - Buffer containing the file content
590
+ * @param contentType - Optional MIME type of the file (if not provided, it will be guessed from the filename)
591
+ * @param metadata - Optional metadata to associate with the file (not used in Box implementation)
592
+ * @returns A Promise that resolves to true if successful, false if an error occurs
593
+ *
594
+ * @remarks
595
+ * - Automatically creates parent directories if they don't exist
596
+ * - Files smaller than 50MB use a simple upload
597
+ * - Files 50MB or larger use a chunked upload process
598
+ * - If a file with the same name exists, it will be replaced
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * // Create a simple text file
603
+ * const textContent = Buffer.from('This is a sample document', 'utf8');
604
+ * const uploadResult = await storage.PutObject(
605
+ * 'documents/sample.txt',
606
+ * textContent,
607
+ * 'text/plain'
608
+ * );
609
+ *
610
+ * // Upload a large file using chunked upload
611
+ * const largeFileBuffer = fs.readFileSync('/path/to/large-presentation.pptx');
612
+ * const largeUploadResult = await storage.PutObject(
613
+ * 'presentations/quarterly-results.pptx',
614
+ * largeFileBuffer,
615
+ * 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
616
+ * );
617
+ *
618
+ * if (largeUploadResult) {
619
+ * console.log('Large file uploaded successfully');
620
+ * } else {
621
+ * console.error('Failed to upload large file');
622
+ * }
623
+ * ```
79
624
  */
80
625
  PutObject(objectName: string, data: Buffer, contentType?: string, metadata?: Record<string, string>): Promise<boolean>;
81
626
  /**
82
- * Copy an object
627
+ * Copies a file from one location to another
628
+ *
629
+ * This method creates a copy of a file at a new location. The original file
630
+ * remains unchanged.
631
+ *
632
+ * @param sourceObjectName - Path to the source file (e.g., 'templates/report-template.docx')
633
+ * @param destinationObjectName - Path where the copy should be created (e.g., 'documents/new-report.docx')
634
+ * @returns A Promise that resolves to true if successful, false if an error occurs
635
+ *
636
+ * @remarks
637
+ * - Only files can be copied; folders cannot be copied with this method
638
+ * - Parent directories in the destination path will be created automatically if they don't exist
639
+ * - If a file with the same name exists at the destination, it will be replaced
640
+ *
641
+ * @example
642
+ * ```typescript
643
+ * // Copy a template file to a new location with a different name
644
+ * const copyResult = await storage.CopyObject(
645
+ * 'templates/financial-report.xlsx',
646
+ * 'reports/2023/q1-financial-report.xlsx'
647
+ * );
648
+ *
649
+ * if (copyResult) {
650
+ * console.log('File copied successfully');
651
+ * } else {
652
+ * console.error('Failed to copy file');
653
+ * }
654
+ * ```
83
655
  */
84
656
  CopyObject(sourceObjectName: string, destinationObjectName: string): Promise<boolean>;
85
657
  /**
86
- * Check if an object exists
658
+ * Checks if a file or folder exists
659
+ *
660
+ * This method verifies whether an object (file or folder) exists at the specified path.
661
+ *
662
+ * @param objectName - Path to check (e.g., 'documents/report.pdf')
663
+ * @returns A Promise that resolves to true if the object exists, false otherwise
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * // Check if a file exists before attempting to download it
668
+ * const exists = await storage.ObjectExists('presentations/quarterly-update.pptx');
669
+ *
670
+ * if (exists) {
671
+ * // File exists, proceed with download
672
+ * const fileContent = await storage.GetObject('presentations/quarterly-update.pptx');
673
+ * // Process the file...
674
+ * } else {
675
+ * console.log('File does not exist');
676
+ * }
677
+ * ```
87
678
  */
88
679
  ObjectExists(objectName: string): Promise<boolean>;
89
680
  /**
90
- * Check if a directory exists
681
+ * Checks if a directory exists
682
+ *
683
+ * This method verifies whether a folder exists at the specified path.
684
+ * Unlike ObjectExists, this method also checks that the item is a folder.
685
+ *
686
+ * @param directoryPath - Path to check (e.g., 'documents/reports')
687
+ * @returns A Promise that resolves to true if the directory exists, false otherwise
688
+ *
689
+ * @remarks
690
+ * - Returns false if the path exists but points to a file instead of a folder
691
+ * - Trailing slashes in the path are automatically removed
692
+ *
693
+ * @example
694
+ * ```typescript
695
+ * // Check if a directory exists before creating a file in it
696
+ * const dirExists = await storage.DirectoryExists('documents/reports');
697
+ *
698
+ * if (!dirExists) {
699
+ * // Create the directory first
700
+ * await storage.CreateDirectory('documents/reports');
701
+ * }
702
+ *
703
+ * // Now we can safely put a file in this directory
704
+ * await storage.PutObject('documents/reports/annual-summary.pdf', fileContent, 'application/pdf');
705
+ * ```
91
706
  */
92
707
  DirectoryExists(directoryPath: string): Promise<boolean>;
708
+ /**
709
+ * Finds a Box folder ID by traversing a path string
710
+ *
711
+ * This helper method navigates through the Box folder hierarchy,
712
+ * following each segment of the path to find the ID of the target folder.
713
+ * It uses pagination to handle large folders efficiently.
714
+ *
715
+ * @private
716
+ * @param path - The path string to resolve (e.g., 'documents/reports/2023')
717
+ * @returns A Promise that resolves to the Box folder ID
718
+ * @throws Error if any segment of the path cannot be found
719
+ */
720
+ private _findFolderIdByPath;
93
721
  }
94
722
  //# sourceMappingURL=BoxFileStorage.d.ts.map