@memberjunction/storage 2.106.0 → 2.107.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 (33) hide show
  1. package/dist/drivers/AWSFileStorage.d.ts +27 -1
  2. package/dist/drivers/AWSFileStorage.d.ts.map +1 -1
  3. package/dist/drivers/AWSFileStorage.js +35 -2
  4. package/dist/drivers/AWSFileStorage.js.map +1 -1
  5. package/dist/drivers/AzureFileStorage.d.ts +21 -1
  6. package/dist/drivers/AzureFileStorage.d.ts.map +1 -1
  7. package/dist/drivers/AzureFileStorage.js +24 -0
  8. package/dist/drivers/AzureFileStorage.js.map +1 -1
  9. package/dist/drivers/BoxFileStorage.d.ts +73 -1
  10. package/dist/drivers/BoxFileStorage.d.ts.map +1 -1
  11. package/dist/drivers/BoxFileStorage.js +218 -0
  12. package/dist/drivers/BoxFileStorage.js.map +1 -1
  13. package/dist/drivers/DropboxFileStorage.d.ts +76 -1
  14. package/dist/drivers/DropboxFileStorage.d.ts.map +1 -1
  15. package/dist/drivers/DropboxFileStorage.js +182 -0
  16. package/dist/drivers/DropboxFileStorage.js.map +1 -1
  17. package/dist/drivers/GoogleDriveFileStorage.d.ts +56 -1
  18. package/dist/drivers/GoogleDriveFileStorage.d.ts.map +1 -1
  19. package/dist/drivers/GoogleDriveFileStorage.js +180 -6
  20. package/dist/drivers/GoogleDriveFileStorage.js.map +1 -1
  21. package/dist/drivers/GoogleFileStorage.d.ts +21 -1
  22. package/dist/drivers/GoogleFileStorage.d.ts.map +1 -1
  23. package/dist/drivers/GoogleFileStorage.js +24 -0
  24. package/dist/drivers/GoogleFileStorage.js.map +1 -1
  25. package/dist/drivers/SharePointFileStorage.d.ts +117 -1
  26. package/dist/drivers/SharePointFileStorage.d.ts.map +1 -1
  27. package/dist/drivers/SharePointFileStorage.js +287 -0
  28. package/dist/drivers/SharePointFileStorage.js.map +1 -1
  29. package/dist/generic/FileStorageBase.d.ts +225 -0
  30. package/dist/generic/FileStorageBase.d.ts.map +1 -1
  31. package/dist/generic/FileStorageBase.js.map +1 -1
  32. package/package.json +2 -2
  33. package/readme.md +109 -0
package/readme.md CHANGED
@@ -34,6 +34,7 @@ This library is a key component of the MemberJunction platform, providing seamle
34
34
  - Get detailed file metadata
35
35
  - Check file/directory existence
36
36
  - Direct upload/download via Buffer
37
+ - **Search files** using native provider search APIs
37
38
  - **Extensible**: Easy to add new storage providers by extending `FileStorageBase`
38
39
 
39
40
  ## Installation
@@ -197,6 +198,74 @@ async function directProviderExample() {
197
198
  }
198
199
  ```
199
200
 
201
+ ### Searching Files
202
+
203
+ Providers with native search capabilities support the `SearchFiles` method for finding files by name, content, and metadata:
204
+
205
+ ```typescript
206
+ import { FileStorageBase, FileSearchOptions, UnsupportedOperationError } from '@memberjunction/storage';
207
+ import { MJGlobal } from '@memberjunction/global';
208
+
209
+ async function searchExample() {
210
+ const storage = MJGlobal.Instance.ClassFactory.CreateInstance<FileStorageBase>(
211
+ FileStorageBase,
212
+ 'Google Drive Storage'
213
+ );
214
+
215
+ try {
216
+ // Simple search for files matching a query
217
+ const results = await storage.SearchFiles('quarterly report');
218
+
219
+ console.log(`Found ${results.results.length} files`);
220
+ for (const file of results.results) {
221
+ console.log(` ${file.path} (${file.size} bytes)`);
222
+ if (file.excerpt) {
223
+ console.log(` Excerpt: ${file.excerpt}`);
224
+ }
225
+ }
226
+
227
+ // Advanced search with filters
228
+ const pdfResults = await storage.SearchFiles('budget 2024', {
229
+ fileTypes: ['pdf', 'docx'],
230
+ modifiedAfter: new Date('2024-01-01'),
231
+ pathPrefix: 'documents/finance/',
232
+ maxResults: 50
233
+ });
234
+
235
+ // Content search (searches inside files)
236
+ const contentResults = await storage.SearchFiles('machine learning', {
237
+ searchContent: true,
238
+ fileTypes: ['pdf', 'docx', 'txt']
239
+ });
240
+
241
+ // Check for more results
242
+ if (contentResults.hasMore) {
243
+ console.log(`Total matches: ${contentResults.totalMatches}`);
244
+ console.log(`Next page token: ${contentResults.nextPageToken}`);
245
+ }
246
+
247
+ } catch (error) {
248
+ if (error instanceof UnsupportedOperationError) {
249
+ console.log('This provider does not support file search');
250
+ // Fall back to ListObjects or other approaches
251
+ } else {
252
+ throw error;
253
+ }
254
+ }
255
+ }
256
+ ```
257
+
258
+ **Provider Search Support:**
259
+ - ✅ **Google Drive**: Full support with content search
260
+ - ✅ **SharePoint**: Full support via Microsoft Graph Search
261
+ - ✅ **Dropbox**: Full support with content search
262
+ - ✅ **Box**: Full support with metadata search
263
+ - ❌ **AWS S3**: Not supported (throws UnsupportedOperationError)
264
+ - ❌ **Azure Blob**: Not supported (throws UnsupportedOperationError)
265
+ - ❌ **Google Cloud Storage**: Not supported (throws UnsupportedOperationError)
266
+
267
+ For providers without native search, consider using `ListObjects` with client-side filtering or implementing an external search index.
268
+
200
269
  ## API Reference
201
270
 
202
271
  ### Core Types
@@ -233,6 +302,45 @@ type StorageListResult = {
233
302
  };
234
303
  ```
235
304
 
305
+ #### `FileSearchOptions`
306
+ ```typescript
307
+ type FileSearchOptions = {
308
+ maxResults?: number; // Maximum results (default: 100)
309
+ fileTypes?: string[]; // Filter by MIME types or extensions
310
+ modifiedAfter?: Date; // Only files modified after this date
311
+ modifiedBefore?: Date; // Only files modified before this date
312
+ pathPrefix?: string; // Search within specific directory
313
+ searchContent?: boolean; // Search file contents (default: false)
314
+ providerSpecific?: Record<string, any>; // Provider-specific options
315
+ };
316
+ ```
317
+
318
+ #### `FileSearchResult`
319
+ ```typescript
320
+ type FileSearchResult = {
321
+ path: string; // Full path to file
322
+ name: string; // Filename only
323
+ size: number; // Size in bytes
324
+ contentType: string; // MIME type
325
+ lastModified: Date; // Last modification date
326
+ relevance?: number; // Relevance score (0.0-1.0)
327
+ excerpt?: string; // Text excerpt with match context
328
+ matchInFilename?: boolean; // Whether match is in filename
329
+ customMetadata?: Record<string, string>; // Custom metadata
330
+ providerData?: Record<string, any>; // Provider-specific data
331
+ };
332
+ ```
333
+
334
+ #### `FileSearchResultSet`
335
+ ```typescript
336
+ type FileSearchResultSet = {
337
+ results: FileSearchResult[]; // Array of matching files
338
+ totalMatches?: number; // Total matches (if available)
339
+ hasMore: boolean; // More results available?
340
+ nextPageToken?: string; // Token for next page
341
+ };
342
+ ```
343
+
236
344
  ### FileStorageBase Methods
237
345
 
238
346
  All storage providers implement these methods:
@@ -250,6 +358,7 @@ All storage providers implement these methods:
250
358
  - `CopyObject(sourceObjectName: string, destinationObjectName: string): Promise<boolean>`
251
359
  - `ObjectExists(objectName: string): Promise<boolean>`
252
360
  - `DirectoryExists(directoryPath: string): Promise<boolean>`
361
+ - `SearchFiles(query: string, options?: FileSearchOptions): Promise<FileSearchResultSet>` (throws `UnsupportedOperationError` for providers without native search)
253
362
  - `initialize(): Promise<void>` (optional, for async initialization)
254
363
 
255
364
  ### Utility Functions