@memberjunction/storage 3.1.1 → 3.2.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/dist/__tests__/FileStorageBase.test.d.ts +6 -0
- package/dist/__tests__/FileStorageBase.test.d.ts.map +1 -0
- package/dist/__tests__/FileStorageBase.test.js +213 -0
- package/dist/__tests__/FileStorageBase.test.js.map +1 -0
- package/dist/__tests__/util.test.d.ts +7 -0
- package/dist/__tests__/util.test.d.ts.map +1 -0
- package/dist/__tests__/util.test.js +326 -0
- package/dist/__tests__/util.test.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +28 -14
- package/dist/config.js.map +1 -1
- package/dist/drivers/AWSFileStorage.d.ts +20 -0
- package/dist/drivers/AWSFileStorage.d.ts.map +1 -1
- package/dist/drivers/AWSFileStorage.js +43 -18
- package/dist/drivers/AWSFileStorage.js.map +1 -1
- package/dist/drivers/AzureFileStorage.d.ts +1 -1
- package/dist/drivers/AzureFileStorage.d.ts.map +1 -1
- package/dist/drivers/AzureFileStorage.js +17 -17
- package/dist/drivers/AzureFileStorage.js.map +1 -1
- package/dist/drivers/BoxFileStorage.d.ts +47 -1
- package/dist/drivers/BoxFileStorage.d.ts.map +1 -1
- package/dist/drivers/BoxFileStorage.js +219 -95
- package/dist/drivers/BoxFileStorage.js.map +1 -1
- package/dist/drivers/DropboxFileStorage.d.ts +59 -0
- package/dist/drivers/DropboxFileStorage.d.ts.map +1 -1
- package/dist/drivers/DropboxFileStorage.js +314 -62
- package/dist/drivers/DropboxFileStorage.js.map +1 -1
- package/dist/drivers/GoogleDriveFileStorage.d.ts +29 -0
- package/dist/drivers/GoogleDriveFileStorage.d.ts.map +1 -1
- package/dist/drivers/GoogleDriveFileStorage.js +220 -72
- package/dist/drivers/GoogleDriveFileStorage.js.map +1 -1
- package/dist/drivers/GoogleFileStorage.d.ts.map +1 -1
- package/dist/drivers/GoogleFileStorage.js +12 -12
- package/dist/drivers/GoogleFileStorage.js.map +1 -1
- package/dist/drivers/SharePointFileStorage.d.ts +64 -5
- package/dist/drivers/SharePointFileStorage.d.ts.map +1 -1
- package/dist/drivers/SharePointFileStorage.js +265 -94
- package/dist/drivers/SharePointFileStorage.js.map +1 -1
- package/dist/generic/FileStorageBase.d.ts +79 -13
- package/dist/generic/FileStorageBase.d.ts.map +1 -1
- package/dist/generic/FileStorageBase.js +57 -12
- package/dist/generic/FileStorageBase.js.map +1 -1
- package/dist/util.d.ts +429 -11
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +677 -16
- package/dist/util.js.map +1 -1
- package/package.json +11 -5
package/dist/util.d.ts
CHANGED
|
@@ -1,4 +1,109 @@
|
|
|
1
|
-
import { FileStorageProviderEntity } from '@memberjunction/core-entities';
|
|
1
|
+
import { FileStorageProviderEntity, FileStorageAccountEntity } from '@memberjunction/core-entities';
|
|
2
|
+
import { UserInfo } from '@memberjunction/core';
|
|
3
|
+
import { FileStorageBase, FileSearchResult } from './generic/FileStorageBase';
|
|
4
|
+
/**
|
|
5
|
+
* Callback function called when a new refresh token is issued.
|
|
6
|
+
* This is important for providers like Box that issue new refresh tokens with each refresh.
|
|
7
|
+
*/
|
|
8
|
+
export type TokenRefreshCallback = (newRefreshToken: string, newAccessToken?: string) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for OAuth-enabled storage providers.
|
|
11
|
+
* This is the format expected by the Google Drive and similar OAuth-based drivers.
|
|
12
|
+
*/
|
|
13
|
+
export interface OAuthStorageConfig {
|
|
14
|
+
/** OAuth2 Client ID (from app registration) */
|
|
15
|
+
clientID: string;
|
|
16
|
+
/** OAuth2 Client Secret (from app registration) */
|
|
17
|
+
clientSecret: string;
|
|
18
|
+
/** User's OAuth refresh token (long-lived) */
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
/** Optional root folder ID to restrict operations */
|
|
21
|
+
rootFolderID?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Callback called when a new refresh token is issued.
|
|
24
|
+
* Required for providers like Box that issue new refresh tokens with each token refresh.
|
|
25
|
+
*/
|
|
26
|
+
onTokenRefresh?: TokenRefreshCallback;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for initializing a storage driver with user-specific credentials.
|
|
30
|
+
*/
|
|
31
|
+
export interface UserStorageDriverOptions {
|
|
32
|
+
/** The file storage provider entity */
|
|
33
|
+
providerEntity: FileStorageProviderEntity;
|
|
34
|
+
/** The user's ID for loading their OAuth tokens */
|
|
35
|
+
userID: string;
|
|
36
|
+
/** Context user for database operations */
|
|
37
|
+
contextUser: UserInfo;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated This function is being replaced by the enterprise file storage model.
|
|
41
|
+
* Use FileStorageAccount with Credential Engine instead.
|
|
42
|
+
*
|
|
43
|
+
* Initializes a storage driver with user-specific OAuth credentials.
|
|
44
|
+
* NOTE: This function currently only supports non-OAuth providers.
|
|
45
|
+
* OAuth provider support will be added via the Credential Engine integration.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Configuration options including provider, user ID, and context
|
|
48
|
+
* @returns A promise resolving to an initialized FileStorageBase driver
|
|
49
|
+
* @throws Error if the provider requires OAuth (not yet supported in enterprise model)
|
|
50
|
+
*/
|
|
51
|
+
export declare function initializeDriverWithUserCredentials(options: UserStorageDriverOptions): Promise<FileStorageBase>;
|
|
52
|
+
/**
|
|
53
|
+
* Options for user context in storage operations.
|
|
54
|
+
* Required for OAuth providers to access user-specific credentials.
|
|
55
|
+
*/
|
|
56
|
+
export interface UserContextOptions {
|
|
57
|
+
/** The user's ID for loading their OAuth tokens */
|
|
58
|
+
userID: string;
|
|
59
|
+
/** Context user for database operations */
|
|
60
|
+
contextUser: UserInfo;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for initializing a storage driver with account-based credentials.
|
|
64
|
+
* This is the new enterprise model where credentials are stored in FileStorageAccount.
|
|
65
|
+
*/
|
|
66
|
+
export interface AccountStorageDriverOptions {
|
|
67
|
+
/** The file storage account entity (contains CredentialID) */
|
|
68
|
+
accountEntity: FileStorageAccountEntity;
|
|
69
|
+
/** The file storage provider entity (contains driver configuration) */
|
|
70
|
+
providerEntity: FileStorageProviderEntity;
|
|
71
|
+
/** Context user for database operations and credential access */
|
|
72
|
+
contextUser: UserInfo;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Initializes a storage driver using account-based credentials from the Credential Engine.
|
|
76
|
+
* This is the enterprise model where credentials are stored in the Credential entity
|
|
77
|
+
* and decrypted at runtime.
|
|
78
|
+
*
|
|
79
|
+
* For providers that issue new refresh tokens on each token refresh (like Box.com),
|
|
80
|
+
* this function automatically configures a callback to persist the new tokens back
|
|
81
|
+
* to the Credential entity in the database.
|
|
82
|
+
*
|
|
83
|
+
* @param options - Configuration options including account, provider, and context user
|
|
84
|
+
* @returns A promise resolving to an initialized FileStorageBase driver
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const driver = await initializeDriverWithAccountCredentials({
|
|
89
|
+
* accountEntity,
|
|
90
|
+
* providerEntity,
|
|
91
|
+
* contextUser
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Driver is now ready to use
|
|
95
|
+
* const objects = await driver.ListObjects('/');
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function initializeDriverWithAccountCredentials(options: AccountStorageDriverOptions): Promise<FileStorageBase>;
|
|
99
|
+
/**
|
|
100
|
+
* Extended user context options that can also include account information
|
|
101
|
+
* for the enterprise credential model.
|
|
102
|
+
*/
|
|
103
|
+
export interface ExtendedUserContextOptions extends UserContextOptions {
|
|
104
|
+
/** Optional account entity for enterprise credential model */
|
|
105
|
+
accountEntity?: FileStorageAccountEntity;
|
|
106
|
+
}
|
|
2
107
|
/**
|
|
3
108
|
* Creates a pre-authenticated upload URL for a file in the specified file storage provider.
|
|
4
109
|
*
|
|
@@ -19,6 +124,7 @@ import { FileStorageProviderEntity } from '@memberjunction/core-entities';
|
|
|
19
124
|
* - ProviderID: The ID of the storage provider to use
|
|
20
125
|
* - ContentType: (Optional) The MIME type of the file
|
|
21
126
|
* - ProviderKey: (Optional) Provider-specific key for the file
|
|
127
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
22
128
|
* @returns A promise that resolves to an object containing:
|
|
23
129
|
* - updatedInput: The input object with additional metadata (Status, ContentType, and possibly ProviderKey)
|
|
24
130
|
* - UploadUrl: The pre-authenticated URL for uploading the file
|
|
@@ -33,7 +139,8 @@ import { FileStorageProviderEntity } from '@memberjunction/core-entities';
|
|
|
33
139
|
* ID: '123',
|
|
34
140
|
* Name: 'report.pdf',
|
|
35
141
|
* ProviderID: fileStorageProvider.ID
|
|
36
|
-
* }
|
|
142
|
+
* },
|
|
143
|
+
* { userID: currentUser.ID, contextUser } // Required for OAuth providers
|
|
37
144
|
* );
|
|
38
145
|
*
|
|
39
146
|
* // The content type is automatically determined from the file extension
|
|
@@ -52,7 +159,7 @@ export declare const createUploadUrl: <TInput extends {
|
|
|
52
159
|
ProviderID: string;
|
|
53
160
|
ContentType?: string;
|
|
54
161
|
ProviderKey?: string;
|
|
55
|
-
}>(providerEntity: FileStorageProviderEntity, input: TInput) => Promise<{
|
|
162
|
+
}>(providerEntity: FileStorageProviderEntity, input: TInput, userContext?: UserContextOptions) => Promise<{
|
|
56
163
|
updatedInput: TInput & {
|
|
57
164
|
Status: string;
|
|
58
165
|
ContentType: string;
|
|
@@ -70,6 +177,7 @@ export declare const createUploadUrl: <TInput extends {
|
|
|
70
177
|
* @param providerEntity - The file storage provider entity containing connection details
|
|
71
178
|
* @param providerKeyOrName - The provider key or name of the file to download
|
|
72
179
|
* (use the ProviderKey if it was returned during upload, otherwise use the file Name)
|
|
180
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
73
181
|
* @returns A promise that resolves to the pre-authenticated download URL as a string
|
|
74
182
|
*
|
|
75
183
|
* @example
|
|
@@ -78,16 +186,16 @@ export declare const createUploadUrl: <TInput extends {
|
|
|
78
186
|
* const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
|
|
79
187
|
*
|
|
80
188
|
* // Using the file name
|
|
81
|
-
* const downloadUrl = await createDownloadUrl(fileStorageProvider, 'reports/annual-report.pdf');
|
|
189
|
+
* const downloadUrl = await createDownloadUrl(fileStorageProvider, 'reports/annual-report.pdf', userContext);
|
|
82
190
|
*
|
|
83
191
|
* // Or using the provider key if returned during upload
|
|
84
|
-
* const downloadUrl = await createDownloadUrl(fileStorageProvider, file.ProviderKey);
|
|
192
|
+
* const downloadUrl = await createDownloadUrl(fileStorageProvider, file.ProviderKey, userContext);
|
|
85
193
|
*
|
|
86
194
|
* // The download URL can be provided to clients for direct download
|
|
87
195
|
* console.log(downloadUrl);
|
|
88
196
|
* ```
|
|
89
197
|
*/
|
|
90
|
-
export declare const createDownloadUrl: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string) => Promise<string>;
|
|
198
|
+
export declare const createDownloadUrl: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string, userContext?: UserContextOptions) => Promise<string>;
|
|
91
199
|
/**
|
|
92
200
|
* Moves an object from one location to another within the specified file storage provider.
|
|
93
201
|
*
|
|
@@ -99,6 +207,7 @@ export declare const createDownloadUrl: (providerEntity: FileStorageProviderEnti
|
|
|
99
207
|
* @param oldProviderKeyOrName - The key or name of the object's current location
|
|
100
208
|
* (use the ProviderKey if it was returned during upload, otherwise use the file Name)
|
|
101
209
|
* @param newProviderKeyOrName - The key or name for the object's new location
|
|
210
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
102
211
|
* @returns A promise that resolves to a boolean indicating whether the move operation was successful
|
|
103
212
|
*
|
|
104
213
|
* @example
|
|
@@ -110,7 +219,8 @@ export declare const createDownloadUrl: (providerEntity: FileStorageProviderEnti
|
|
|
110
219
|
* const success = await moveObject(
|
|
111
220
|
* fileStorageProvider,
|
|
112
221
|
* 'drafts/report.docx',
|
|
113
|
-
* 'published/final-report.docx'
|
|
222
|
+
* 'published/final-report.docx',
|
|
223
|
+
* userContext
|
|
114
224
|
* );
|
|
115
225
|
*
|
|
116
226
|
* if (success) {
|
|
@@ -120,7 +230,38 @@ export declare const createDownloadUrl: (providerEntity: FileStorageProviderEnti
|
|
|
120
230
|
* }
|
|
121
231
|
* ```
|
|
122
232
|
*/
|
|
123
|
-
export declare const moveObject: (providerEntity: FileStorageProviderEntity, oldProviderKeyOrName: string, newProviderKeyOrName: string) => Promise<boolean>;
|
|
233
|
+
export declare const moveObject: (providerEntity: FileStorageProviderEntity, oldProviderKeyOrName: string, newProviderKeyOrName: string, userContext?: UserContextOptions) => Promise<boolean>;
|
|
234
|
+
/**
|
|
235
|
+
* Copies an object from one location to another within the specified file storage provider.
|
|
236
|
+
*
|
|
237
|
+
* This utility function handles copying files by instantiating the appropriate storage
|
|
238
|
+
* provider driver and delegating to its CopyObject method. It can be used to duplicate files
|
|
239
|
+
* within the same storage provider, either in the same folder with a different name or to
|
|
240
|
+
* a different folder.
|
|
241
|
+
*
|
|
242
|
+
* @param providerEntity - The file storage provider entity containing connection details
|
|
243
|
+
* @param sourceProviderKeyOrName - The key or name of the source file to copy
|
|
244
|
+
* @param destinationProviderKeyOrName - The key or name for the destination copy
|
|
245
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
246
|
+
* @returns A promise that resolves to a boolean indicating whether the copy was successful
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const success = await copyObject(
|
|
251
|
+
* providerEntity,
|
|
252
|
+
* 'documents/report.pdf',
|
|
253
|
+
* 'documents/archive/report-2024.pdf',
|
|
254
|
+
* userContext
|
|
255
|
+
* );
|
|
256
|
+
*
|
|
257
|
+
* if (success) {
|
|
258
|
+
* console.log('File successfully copied');
|
|
259
|
+
* } else {
|
|
260
|
+
* console.log('Failed to copy file');
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare const copyObject: (providerEntity: FileStorageProviderEntity, sourceProviderKeyOrName: string, destinationProviderKeyOrName: string, userContext?: UserContextOptions) => Promise<boolean>;
|
|
124
265
|
/**
|
|
125
266
|
* Deletes a file from the specified file storage provider.
|
|
126
267
|
*
|
|
@@ -131,6 +272,7 @@ export declare const moveObject: (providerEntity: FileStorageProviderEntity, old
|
|
|
131
272
|
* @param providerEntity - The file storage provider entity containing connection details
|
|
132
273
|
* @param providerKeyOrName - The key or name of the file to delete
|
|
133
274
|
* (use the ProviderKey if it was returned during upload, otherwise use the file Name)
|
|
275
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
134
276
|
* @returns A promise that resolves to a boolean indicating whether the deletion was successful
|
|
135
277
|
*
|
|
136
278
|
* @example
|
|
@@ -139,10 +281,10 @@ export declare const moveObject: (providerEntity: FileStorageProviderEntity, old
|
|
|
139
281
|
* const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
|
|
140
282
|
*
|
|
141
283
|
* // Delete using the file name
|
|
142
|
-
* const deleted = await deleteObject(fileStorageProvider, 'temp/obsolete-document.pdf');
|
|
284
|
+
* const deleted = await deleteObject(fileStorageProvider, 'temp/obsolete-document.pdf', userContext);
|
|
143
285
|
*
|
|
144
286
|
* // Or using the provider key if returned during upload
|
|
145
|
-
* const deleted = await deleteObject(fileStorageProvider, file.ProviderKey);
|
|
287
|
+
* const deleted = await deleteObject(fileStorageProvider, file.ProviderKey, userContext);
|
|
146
288
|
*
|
|
147
289
|
* if (deleted) {
|
|
148
290
|
* console.log('File successfully deleted');
|
|
@@ -151,5 +293,281 @@ export declare const moveObject: (providerEntity: FileStorageProviderEntity, old
|
|
|
151
293
|
* }
|
|
152
294
|
* ```
|
|
153
295
|
*/
|
|
154
|
-
export declare const deleteObject: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string) => Promise<boolean>;
|
|
296
|
+
export declare const deleteObject: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string, userContext?: UserContextOptions) => Promise<boolean>;
|
|
297
|
+
/**
|
|
298
|
+
* Lists objects (files) and prefixes (directories) in a storage provider at the specified path.
|
|
299
|
+
*
|
|
300
|
+
* This utility function provides access to the storage provider's file and folder listing
|
|
301
|
+
* functionality. It returns both files and directories found at the specified path prefix,
|
|
302
|
+
* allowing for hierarchical navigation through the storage provider's contents.
|
|
303
|
+
*
|
|
304
|
+
* @param providerEntity - The file storage provider entity containing connection details
|
|
305
|
+
* @param prefix - The path prefix to list objects from (e.g., "/" for root, "documents/" for a specific folder)
|
|
306
|
+
* @param delimiter - The character used to group keys into a hierarchy (defaults to "/")
|
|
307
|
+
* @param userContext - Optional user context for OAuth providers (required if provider.RequiresOAuth is true)
|
|
308
|
+
* @returns A promise that resolves to a StorageListResult containing:
|
|
309
|
+
* - objects: Array of file metadata (name, size, contentType, lastModified, etc.)
|
|
310
|
+
* - prefixes: Array of directory/folder path strings
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* // List contents of the root directory
|
|
315
|
+
* const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'aws-s3-main');
|
|
316
|
+
* const result = await listObjects(fileStorageProvider, '/', '/', userContext);
|
|
317
|
+
*
|
|
318
|
+
* // Display files
|
|
319
|
+
* for (const file of result.objects) {
|
|
320
|
+
* console.log(`File: ${file.name} (${file.size} bytes)`);
|
|
321
|
+
* }
|
|
322
|
+
*
|
|
323
|
+
* // Display folders
|
|
324
|
+
* for (const folder of result.prefixes) {
|
|
325
|
+
* console.log(`Folder: ${folder}`);
|
|
326
|
+
* }
|
|
327
|
+
*
|
|
328
|
+
* // List contents of a specific folder
|
|
329
|
+
* const docsResult = await listObjects(fileStorageProvider, 'documents/', '/', userContext);
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export declare const listObjects: (providerEntity: FileStorageProviderEntity, prefix: string, delimiter?: string, userContext?: UserContextOptions) => Promise<import('./generic/FileStorageBase').StorageListResult>;
|
|
333
|
+
/**
|
|
334
|
+
* Result of a cross-provider copy operation
|
|
335
|
+
*/
|
|
336
|
+
export interface CopyBetweenProvidersResult {
|
|
337
|
+
success: boolean;
|
|
338
|
+
message: string;
|
|
339
|
+
bytesTransferred?: number;
|
|
340
|
+
sourceProvider: string;
|
|
341
|
+
destinationProvider: string;
|
|
342
|
+
sourcePath: string;
|
|
343
|
+
destinationPath: string;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Options for cross-provider copy operations.
|
|
347
|
+
*/
|
|
348
|
+
export interface CopyBetweenProvidersOptions {
|
|
349
|
+
/** User context for the source provider (required if source provider.RequiresOAuth is true). Can include accountEntity for enterprise credential model. */
|
|
350
|
+
sourceUserContext?: ExtendedUserContextOptions;
|
|
351
|
+
/** User context for the destination provider (required if destination provider.RequiresOAuth is true). Can include accountEntity for enterprise credential model. */
|
|
352
|
+
destinationUserContext?: ExtendedUserContextOptions;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Copies a file from one storage provider to another.
|
|
356
|
+
*
|
|
357
|
+
* This utility function enables transferring files between different storage providers
|
|
358
|
+
* (e.g., from Dropbox to Google Drive, or from S3 to Azure). The transfer happens
|
|
359
|
+
* server-side, so the file data flows: Source Provider → Server → Destination Provider.
|
|
360
|
+
*
|
|
361
|
+
* @param sourceProviderEntity - The source file storage provider entity
|
|
362
|
+
* @param destinationProviderEntity - The destination file storage provider entity
|
|
363
|
+
* @param sourcePath - The path to the file in the source provider
|
|
364
|
+
* @param destinationPath - The path where the file should be saved in the destination provider
|
|
365
|
+
* @param options - Optional user context for OAuth providers
|
|
366
|
+
* @returns A promise that resolves to a CopyBetweenProvidersResult
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* // Copy a file from Dropbox to Google Drive
|
|
371
|
+
* const sourceProvider = await entityMgr.FindById('FileStorageProvider', 'dropbox-id');
|
|
372
|
+
* const destProvider = await entityMgr.FindById('FileStorageProvider', 'gdrive-id');
|
|
373
|
+
*
|
|
374
|
+
* const result = await copyObjectBetweenProviders(
|
|
375
|
+
* sourceProvider,
|
|
376
|
+
* destProvider,
|
|
377
|
+
* 'documents/report.pdf',
|
|
378
|
+
* 'imported/report.pdf',
|
|
379
|
+
* {
|
|
380
|
+
* sourceUserContext: { userID: currentUser.ID, contextUser },
|
|
381
|
+
* destinationUserContext: { userID: currentUser.ID, contextUser }
|
|
382
|
+
* }
|
|
383
|
+
* );
|
|
384
|
+
*
|
|
385
|
+
* if (result.success) {
|
|
386
|
+
* console.log(`Transferred ${result.bytesTransferred} bytes`);
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
export declare const copyObjectBetweenProviders: (sourceProviderEntity: FileStorageProviderEntity, destinationProviderEntity: FileStorageProviderEntity, sourcePath: string, destinationPath: string, options?: CopyBetweenProvidersOptions) => Promise<CopyBetweenProvidersResult>;
|
|
391
|
+
/**
|
|
392
|
+
* Result from a single provider's search attempt
|
|
393
|
+
*/
|
|
394
|
+
export interface ProviderSearchResult {
|
|
395
|
+
/** Provider ID */
|
|
396
|
+
providerID: string;
|
|
397
|
+
/** Provider name for display */
|
|
398
|
+
providerName: string;
|
|
399
|
+
/** Whether this provider's search succeeded */
|
|
400
|
+
success: boolean;
|
|
401
|
+
/** Error message if search failed or provider doesn't support search */
|
|
402
|
+
errorMessage?: string;
|
|
403
|
+
/** Search results (empty array if failed) */
|
|
404
|
+
results: FileSearchResult[];
|
|
405
|
+
/** Total matches from this provider */
|
|
406
|
+
totalMatches?: number;
|
|
407
|
+
/** Whether there are more results available */
|
|
408
|
+
hasMore: boolean;
|
|
409
|
+
/** Pagination token for this provider */
|
|
410
|
+
nextPageToken?: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Aggregated results from searching across multiple providers
|
|
414
|
+
*/
|
|
415
|
+
export interface MultiProviderSearchResult {
|
|
416
|
+
/** Results grouped by provider */
|
|
417
|
+
providerResults: ProviderSearchResult[];
|
|
418
|
+
/** Total results across all providers */
|
|
419
|
+
totalResultsReturned: number;
|
|
420
|
+
/** Number of providers that succeeded */
|
|
421
|
+
successfulProviders: number;
|
|
422
|
+
/** Number of providers that failed */
|
|
423
|
+
failedProviders: number;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Options for multi-provider search
|
|
427
|
+
*/
|
|
428
|
+
export interface SearchAcrossProvidersOptions {
|
|
429
|
+
/** Maximum results per provider (default: 50) */
|
|
430
|
+
maxResultsPerProvider?: number;
|
|
431
|
+
/** File types to filter by (e.g., ['pdf', 'docx']) */
|
|
432
|
+
fileTypes?: string[];
|
|
433
|
+
/** Whether to search file contents (default: false) */
|
|
434
|
+
searchContent?: boolean;
|
|
435
|
+
/** User context for OAuth providers - maps provider ID to user context */
|
|
436
|
+
providerUserContexts?: Map<string, UserContextOptions>;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Searches for files across multiple storage providers in parallel.
|
|
440
|
+
*
|
|
441
|
+
* This utility function enables searching for files across multiple storage providers
|
|
442
|
+
* simultaneously. Each provider is queried in parallel using Promise.allSettled,
|
|
443
|
+
* ensuring that failures in one provider don't affect results from others.
|
|
444
|
+
*
|
|
445
|
+
* Providers that don't support search (SupportsSearch = false) will return a result
|
|
446
|
+
* with success=false and an appropriate error message rather than being silently skipped.
|
|
447
|
+
*
|
|
448
|
+
* @param providerEntities - Array of provider entities to search
|
|
449
|
+
* @param query - Search query string
|
|
450
|
+
* @param options - Optional search configuration including user contexts for OAuth providers
|
|
451
|
+
* @returns A promise that resolves to aggregated results grouped by provider
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* // Search across Google Drive and Dropbox
|
|
456
|
+
* const providers = [googleDriveProvider, dropboxProvider];
|
|
457
|
+
* const userContexts = new Map([
|
|
458
|
+
* [googleDriveProvider.ID, { userID: currentUser.ID, contextUser }],
|
|
459
|
+
* [dropboxProvider.ID, { userID: currentUser.ID, contextUser }]
|
|
460
|
+
* ]);
|
|
461
|
+
*
|
|
462
|
+
* const result = await searchAcrossProviders(providers, 'quarterly report', {
|
|
463
|
+
* maxResultsPerProvider: 25,
|
|
464
|
+
* fileTypes: ['pdf', 'docx'],
|
|
465
|
+
* providerUserContexts: userContexts
|
|
466
|
+
* });
|
|
467
|
+
*
|
|
468
|
+
* // Process results by provider
|
|
469
|
+
* for (const providerResult of result.providerResults) {
|
|
470
|
+
* if (providerResult.success) {
|
|
471
|
+
* console.log(`${providerResult.providerName}: ${providerResult.results.length} results`);
|
|
472
|
+
* } else {
|
|
473
|
+
* console.log(`${providerResult.providerName}: ${providerResult.errorMessage}`);
|
|
474
|
+
* }
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
export declare const searchAcrossProviders: (providerEntities: FileStorageProviderEntity[], query: string, options?: SearchAcrossProvidersOptions) => Promise<MultiProviderSearchResult>;
|
|
479
|
+
/**
|
|
480
|
+
* Information needed to search a single account
|
|
481
|
+
*/
|
|
482
|
+
export interface AccountSearchInput {
|
|
483
|
+
/** The file storage account entity */
|
|
484
|
+
accountEntity: FileStorageAccountEntity;
|
|
485
|
+
/** The file storage provider entity for this account */
|
|
486
|
+
providerEntity: FileStorageProviderEntity;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Result from a single account's search attempt
|
|
490
|
+
*/
|
|
491
|
+
export interface AccountSearchResult {
|
|
492
|
+
/** Account ID */
|
|
493
|
+
accountID: string;
|
|
494
|
+
/** Account name for display */
|
|
495
|
+
accountName: string;
|
|
496
|
+
/** Provider ID */
|
|
497
|
+
providerID: string;
|
|
498
|
+
/** Provider name for display */
|
|
499
|
+
providerName: string;
|
|
500
|
+
/** Whether this account's search succeeded */
|
|
501
|
+
success: boolean;
|
|
502
|
+
/** Error message if search failed or provider doesn't support search */
|
|
503
|
+
errorMessage?: string;
|
|
504
|
+
/** Search results (empty array if failed) */
|
|
505
|
+
results: FileSearchResult[];
|
|
506
|
+
/** Total matches from this account */
|
|
507
|
+
totalMatches?: number;
|
|
508
|
+
/** Whether there are more results available */
|
|
509
|
+
hasMore: boolean;
|
|
510
|
+
/** Pagination token for this account */
|
|
511
|
+
nextPageToken?: string;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Aggregated results from searching across multiple accounts
|
|
515
|
+
*/
|
|
516
|
+
export interface MultiAccountSearchResult {
|
|
517
|
+
/** Results grouped by account */
|
|
518
|
+
accountResults: AccountSearchResult[];
|
|
519
|
+
/** Total results across all accounts */
|
|
520
|
+
totalResultsReturned: number;
|
|
521
|
+
/** Number of accounts that succeeded */
|
|
522
|
+
successfulAccounts: number;
|
|
523
|
+
/** Number of accounts that failed */
|
|
524
|
+
failedAccounts: number;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Options for multi-account search
|
|
528
|
+
*/
|
|
529
|
+
export interface SearchAcrossAccountsOptions {
|
|
530
|
+
/** Maximum results per account (default: 50) */
|
|
531
|
+
maxResultsPerAccount?: number;
|
|
532
|
+
/** File types to filter by (e.g., ['pdf', 'docx']) */
|
|
533
|
+
fileTypes?: string[];
|
|
534
|
+
/** Whether to search file contents (default: false) */
|
|
535
|
+
searchContent?: boolean;
|
|
536
|
+
/** Context user for credential decryption */
|
|
537
|
+
contextUser: UserInfo;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Searches for files across multiple storage accounts in parallel.
|
|
541
|
+
*
|
|
542
|
+
* This is the enterprise version of search that uses the account-based credential model.
|
|
543
|
+
* Each account is searched independently, allowing multiple accounts from the same
|
|
544
|
+
* provider type to be searched (e.g., two different Dropbox accounts).
|
|
545
|
+
*
|
|
546
|
+
* @param accounts - Array of account/provider pairs to search
|
|
547
|
+
* @param query - Search query string
|
|
548
|
+
* @param options - Search configuration including context user for credentials
|
|
549
|
+
* @returns A promise that resolves to aggregated results grouped by account
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const accounts = [
|
|
554
|
+
* { accountEntity: researchDropbox, providerEntity: dropboxProvider },
|
|
555
|
+
* { accountEntity: marketingDropbox, providerEntity: dropboxProvider },
|
|
556
|
+
* { accountEntity: engineeringGDrive, providerEntity: gdriveProvider }
|
|
557
|
+
* ];
|
|
558
|
+
*
|
|
559
|
+
* const result = await searchAcrossAccounts(accounts, 'quarterly report', {
|
|
560
|
+
* maxResultsPerAccount: 25,
|
|
561
|
+
* fileTypes: ['pdf', 'docx'],
|
|
562
|
+
* contextUser: currentUser
|
|
563
|
+
* });
|
|
564
|
+
*
|
|
565
|
+
* for (const accountResult of result.accountResults) {
|
|
566
|
+
* if (accountResult.success) {
|
|
567
|
+
* console.log(`${accountResult.accountName}: ${accountResult.results.length} results`);
|
|
568
|
+
* }
|
|
569
|
+
* }
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
export declare const searchAcrossAccounts: (accounts: AccountSearchInput[], query: string, options: SearchAcrossAccountsOptions) => Promise<MultiAccountSearchResult>;
|
|
155
573
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEpG,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,eAAe,EAAqB,gBAAgB,EAAyB,MAAM,2BAA2B,CAAC;AAExH;;;GA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