@memberjunction/storage 2.38.0 → 2.40.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 +539 -20
  10. package/dist/drivers/BoxFileStorage.d.ts.map +1 -1
  11. package/dist/drivers/BoxFileStorage.js +521 -20
  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 +4 -4
  38. package/readme.md +211 -1
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileStorageBase = exports.UnsupportedOperationError = void 0;
4
4
  /**
5
- * Error thrown when a method is not supported by a storage provider
5
+ * Error thrown when a storage provider does not support a particular operation.
6
+ * This custom error provides clear information about which operation was attempted
7
+ * and which provider doesn't support it.
6
8
  */
7
9
  class UnsupportedOperationError extends Error {
10
+ /**
11
+ * Creates a new UnsupportedOperationError instance.
12
+ *
13
+ * @param methodName - The name of the method that is not supported
14
+ * @param providerName - The name of the storage provider that doesn't support the method
15
+ */
8
16
  constructor(methodName, providerName) {
9
17
  super(`Operation '${methodName}' is not supported by the ${providerName} provider`);
10
18
  this.name = 'UnsupportedOperationError';
@@ -12,21 +20,61 @@ class UnsupportedOperationError extends Error {
12
20
  }
13
21
  exports.UnsupportedOperationError = UnsupportedOperationError;
14
22
  /**
15
- * Represents an abstract base class for file storage. Provides methods for creating pre-authorized upload and download URLs, as well as deleting objects. This
16
- * interface is implemented in specific driver classes for each storage provider.
23
+ * Represents an abstract base class for file storage operations.
24
+ *
25
+ * This class defines a common interface for interacting with various cloud storage providers,
26
+ * allowing for consistent file operations regardless of the underlying storage system.
27
+ * Each storage provider implementation extends this base class and provides
28
+ * concrete implementations for all abstract methods.
29
+ *
30
+ * The class provides methods for:
31
+ * - Generating pre-authenticated upload and download URLs
32
+ * - Managing files (creating, copying, moving, deleting)
33
+ * - Managing directories (creating, deleting, listing contents)
34
+ * - Retrieving file metadata and content
35
+ * - Checking for file and directory existence
36
+ *
37
+ * Implementation notes:
38
+ * - All methods are designed to be provider-agnostic
39
+ * - Error handling should be implemented in derived classes to provide consistent behavior
40
+ * - Methods return Promises to support asynchronous operations across various providers
41
+ * - When a storage provider doesn't support a particular operation, implementations should throw UnsupportedOperationError
17
42
  */
18
43
  class FileStorageBase {
19
44
  /**
20
- * Helper method to throw an UnsupportedOperationError
21
- * @param methodName The name of the method that is not supported
45
+ * Helper method to throw an UnsupportedOperationError with appropriate context.
46
+ * This method simplifies implementation of methods not supported by specific providers.
47
+ *
48
+ * @param methodName - The name of the method that is not supported
49
+ * @throws UnsupportedOperationError with information about the unsupported method and provider
22
50
  */
23
51
  throwUnsupportedOperationError(methodName) {
24
52
  throw new UnsupportedOperationError(methodName, this.providerName);
25
53
  }
26
54
  /**
27
55
  * Optional initialization method for storage providers that require async setup.
56
+ *
28
57
  * This method can be overridden by subclasses that need to perform async initialization
29
- * after construction, such as setting up access tokens or establishing connections.
58
+ * after construction, such as setting up access tokens, establishing connections,
59
+ * or verifying permissions.
60
+ *
61
+ * The default implementation does nothing and resolves immediately. Storage provider
62
+ * implementations should override this method if they need to perform async setup.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // In a specific provider implementation:
67
+ * public async initialize(): Promise<void> {
68
+ * // Set up OAuth tokens or other async initialization
69
+ * await this.refreshAccessToken();
70
+ * await this.verifyBucketAccess();
71
+ * }
72
+ *
73
+ * // Usage:
74
+ * const storage = new MyStorageProvider();
75
+ * await storage.initialize();
76
+ * // Now the provider is ready to use
77
+ * ```
30
78
  *
31
79
  * @returns A Promise that resolves when initialization is complete.
32
80
  */
@@ -1 +1 @@
1
- {"version":3,"file":"FileStorageBase.js","sourceRoot":"","sources":["../../src/generic/FileStorageBase.ts"],"names":[],"mappings":";;;AAuBA;;GAEG;AACH,MAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,UAAkB,EAAE,YAAoB;QAClD,KAAK,CAAC,cAAc,UAAU,6BAA6B,YAAY,WAAW,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AALD,8DAKC;AAED;;;GAGG;AACH,MAAsB,eAAe;IAMnC;;;OAGG;IACO,8BAA8B,CAAC,UAAkB;QACzD,MAAM,IAAI,yBAAyB,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACrE,CAAC;IA+OD;;;;;;OAMG;IACI,KAAK,CAAC,UAAU;QACrB,sCAAsC;IACxC,CAAC;CACF;AArQD,0CAqQC"}
1
+ {"version":3,"file":"FileStorageBase.js","sourceRoot":"","sources":["../../src/generic/FileStorageBase.ts"],"names":[],"mappings":";;;AAqDA;;;;GAIG;AACH,MAAa,yBAA0B,SAAQ,KAAK;IAClD;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,YAAoB;QAClD,KAAK,CAAC,cAAc,UAAU,6BAA6B,YAAY,WAAW,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAXD,8DAWC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAsB,eAAe;IAOnC;;;;;;OAMG;IACO,8BAA8B,CAAC,UAAkB;QACzD,MAAM,IAAI,yBAAyB,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACrE,CAAC;IA2XD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACI,KAAK,CAAC,UAAU;QACrB,sCAAsC;IACxC,CAAC;CACF;AAzaD,0CAyaC"}
package/dist/util.d.ts CHANGED
@@ -1,11 +1,50 @@
1
1
  import { FileStorageProviderEntity } from '@memberjunction/core-entities';
2
2
  /**
3
- * Creates an upload URL for a file in the specified file storage provider. Infers ContentType based on the file name, enforces a specific `Status` and may set
4
- * the `ProviderKey` value, dependening on the underlying file storage provider.
3
+ * Creates a pre-authenticated upload URL for a file in the specified file storage provider.
5
4
  *
6
- * @param providerEntity - The file storage provider entity.
7
- * @param input - The input object containing the file details.
8
- * @returns A promise that resolves to an object with the updated input and the upload URL.
5
+ * This utility function simplifies the process of creating upload URLs by handling common
6
+ * tasks such as:
7
+ * - Setting the content type based on the file extension if not provided
8
+ * - Setting the file status to 'Uploading'
9
+ * - Managing the provider key if returned by the storage provider
10
+ *
11
+ * The function returns both the updated input object (with additional metadata) and the
12
+ * pre-authenticated upload URL that can be used by clients to upload the file directly
13
+ * to the storage provider.
14
+ *
15
+ * @param providerEntity - The file storage provider entity containing connection details
16
+ * @param input - The input object containing the file details:
17
+ * - ID: A unique identifier for the file
18
+ * - Name: The filename to use for storage
19
+ * - ProviderID: The ID of the storage provider to use
20
+ * - ContentType: (Optional) The MIME type of the file
21
+ * - ProviderKey: (Optional) Provider-specific key for the file
22
+ * @returns A promise that resolves to an object containing:
23
+ * - updatedInput: The input object with additional metadata (Status, ContentType, and possibly ProviderKey)
24
+ * - UploadUrl: The pre-authenticated URL for uploading the file
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Create a pre-authenticated upload URL for a PDF document
29
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
30
+ * const result = await createUploadUrl(
31
+ * fileStorageProvider,
32
+ * {
33
+ * ID: '123',
34
+ * Name: 'report.pdf',
35
+ * ProviderID: fileStorageProvider.ID
36
+ * }
37
+ * );
38
+ *
39
+ * // The content type is automatically determined from the file extension
40
+ * console.log(result.updatedInput.ContentType); // 'application/pdf'
41
+ *
42
+ * // The status is set to 'Uploading'
43
+ * console.log(result.updatedInput.Status); // 'Uploading'
44
+ *
45
+ * // The upload URL can be sent to the client for direct upload
46
+ * console.log(result.UploadUrl);
47
+ * ```
9
48
  */
10
49
  export declare const createUploadUrl: <TInput extends {
11
50
  ID: string;
@@ -21,28 +60,96 @@ export declare const createUploadUrl: <TInput extends {
21
60
  UploadUrl: string;
22
61
  }>;
23
62
  /**
24
- * Creates a pre-authorized download URL for a file from the specified file storage provider.
63
+ * Creates a pre-authenticated download URL for a file from the specified file storage provider.
64
+ *
65
+ * This utility function simplifies the process of generating download URLs by instantiating
66
+ * the appropriate storage provider driver and delegating to its CreatePreAuthDownloadUrl method.
67
+ * The returned URL can be provided directly to clients for downloading the file without
68
+ * requiring additional authentication.
69
+ *
70
+ * @param providerEntity - The file storage provider entity containing connection details
71
+ * @param providerKeyOrName - The provider key or name of the file to download
72
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
73
+ * @returns A promise that resolves to the pre-authenticated download URL as a string
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Get a pre-authenticated download URL for a file
78
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
79
+ *
80
+ * // Using the file name
81
+ * const downloadUrl = await createDownloadUrl(fileStorageProvider, 'reports/annual-report.pdf');
25
82
  *
26
- * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
27
- * @param {string} providerKeyOrName - The provider key or Name for the file to download.
28
- * @returns {Promise<string>} - The pre-authorized download URL.
83
+ * // Or using the provider key if returned during upload
84
+ * const downloadUrl = await createDownloadUrl(fileStorageProvider, file.ProviderKey);
85
+ *
86
+ * // The download URL can be provided to clients for direct download
87
+ * console.log(downloadUrl);
88
+ * ```
29
89
  */
30
90
  export declare const createDownloadUrl: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string) => Promise<string>;
31
91
  /**
32
- * Moves an object from one location to another within the file storage provider.
92
+ * Moves an object from one location to another within the specified file storage provider.
93
+ *
94
+ * This utility function handles moving files by instantiating the appropriate storage
95
+ * provider driver and delegating to its MoveObject method. It can be used to rename files
96
+ * or move them to different directories within the same storage provider.
97
+ *
98
+ * @param providerEntity - The file storage provider entity containing connection details
99
+ * @param oldProviderKeyOrName - The key or name of the object's current location
100
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
101
+ * @param newProviderKeyOrName - The key or name for the object's new location
102
+ * @returns A promise that resolves to a boolean indicating whether the move operation was successful
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * // Move a file from one location to another
107
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
108
+ *
109
+ * // Move a file to a different directory
110
+ * const success = await moveObject(
111
+ * fileStorageProvider,
112
+ * 'drafts/report.docx',
113
+ * 'published/final-report.docx'
114
+ * );
33
115
  *
34
- * @param providerEntity - The file storage provider entity.
35
- * @param oldProviderKeyOrName - The key or name of the old location of the object.
36
- * @param newProviderKeyOrName - The key or name of the new location to move the object to.
37
- * @returns A promise that resolves to a boolean indicating whether the object was successfully moved.
116
+ * if (success) {
117
+ * console.log('File successfully moved');
118
+ * } else {
119
+ * console.log('Failed to move file');
120
+ * }
121
+ * ```
38
122
  */
39
123
  export declare const moveObject: (providerEntity: FileStorageProviderEntity, oldProviderKeyOrName: string, newProviderKeyOrName: string) => Promise<boolean>;
40
124
  /**
41
- * Delete a previously uploaded file from the specified file storage provider.
125
+ * Deletes a file from the specified file storage provider.
126
+ *
127
+ * This utility function handles file deletion by instantiating the appropriate storage
128
+ * provider driver and delegating to its DeleteObject method. It provides a simple way
129
+ * to remove files that are no longer needed.
130
+ *
131
+ * @param providerEntity - The file storage provider entity containing connection details
132
+ * @param providerKeyOrName - The key or name of the file to delete
133
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
134
+ * @returns A promise that resolves to a boolean indicating whether the deletion was successful
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Delete a file from storage
139
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
140
+ *
141
+ * // Delete using the file name
142
+ * const deleted = await deleteObject(fileStorageProvider, 'temp/obsolete-document.pdf');
143
+ *
144
+ * // Or using the provider key if returned during upload
145
+ * const deleted = await deleteObject(fileStorageProvider, file.ProviderKey);
42
146
  *
43
- * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
44
- * @param {string} providerKeyOrName - The provider key or Name of the file to delete.
45
- * @returns {Promise<boolean>} - The success of he delete operation.
147
+ * if (deleted) {
148
+ * console.log('File successfully deleted');
149
+ * } else {
150
+ * console.log('Failed to delete file - it may not exist or there was an error');
151
+ * }
152
+ * ```
46
153
  */
47
154
  export declare const deleteObject: (providerEntity: FileStorageProviderEntity, providerKeyOrName: string) => Promise<boolean>;
48
155
  //# sourceMappingURL=util.d.ts.map
@@ -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;AAK1E;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;QACL,MAAM;UAAQ,MAAM;gBAAc,MAAM;kBAAgB,MAAM;kBAAgB,MAAM;mBAEzF,yBAAyB,SAClC,MAAM,KACZ,QAAQ;IACT,YAAY,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB,CAaA,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,mBAA0B,yBAAyB,qBAAqB,MAAM,KAAG,QAAQ,MAAM,CAG5H,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,mBAA0B,yBAAyB,wBAAwB,MAAM,wBAAwB,MAAM,qBAGrI,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,mBAAoB,yBAAyB,qBAAqB,MAAM,qBAGhG,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAK1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,eAAe;QACL,MAAM;UAAQ,MAAM;gBAAc,MAAM;kBAAgB,MAAM;kBAAgB,MAAM;mBAEzF,yBAAyB,SAClC,MAAM,KACZ,QAAQ;IACT,YAAY,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB,CAaA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,iBAAiB,mBAA0B,yBAAyB,qBAAqB,MAAM,KAAG,QAAQ,MAAM,CAG5H,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,UAAU,mBACL,yBAAyB,wBACnB,MAAM,wBACN,MAAM,KAC3B,QAAQ,OAAO,CAGjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,YAAY,mBACP,yBAAyB,qBACtB,MAAM,KACxB,QAAQ,OAAO,CAGjB,CAAC"}
package/dist/util.js CHANGED
@@ -8,12 +8,51 @@ const global_1 = require("@memberjunction/global");
8
8
  const mime_types_1 = __importDefault(require("mime-types"));
9
9
  const FileStorageBase_1 = require("./generic/FileStorageBase");
10
10
  /**
11
- * Creates an upload URL for a file in the specified file storage provider. Infers ContentType based on the file name, enforces a specific `Status` and may set
12
- * the `ProviderKey` value, dependening on the underlying file storage provider.
11
+ * Creates a pre-authenticated upload URL for a file in the specified file storage provider.
13
12
  *
14
- * @param providerEntity - The file storage provider entity.
15
- * @param input - The input object containing the file details.
16
- * @returns A promise that resolves to an object with the updated input and the upload URL.
13
+ * This utility function simplifies the process of creating upload URLs by handling common
14
+ * tasks such as:
15
+ * - Setting the content type based on the file extension if not provided
16
+ * - Setting the file status to 'Uploading'
17
+ * - Managing the provider key if returned by the storage provider
18
+ *
19
+ * The function returns both the updated input object (with additional metadata) and the
20
+ * pre-authenticated upload URL that can be used by clients to upload the file directly
21
+ * to the storage provider.
22
+ *
23
+ * @param providerEntity - The file storage provider entity containing connection details
24
+ * @param input - The input object containing the file details:
25
+ * - ID: A unique identifier for the file
26
+ * - Name: The filename to use for storage
27
+ * - ProviderID: The ID of the storage provider to use
28
+ * - ContentType: (Optional) The MIME type of the file
29
+ * - ProviderKey: (Optional) Provider-specific key for the file
30
+ * @returns A promise that resolves to an object containing:
31
+ * - updatedInput: The input object with additional metadata (Status, ContentType, and possibly ProviderKey)
32
+ * - UploadUrl: The pre-authenticated URL for uploading the file
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Create a pre-authenticated upload URL for a PDF document
37
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
38
+ * const result = await createUploadUrl(
39
+ * fileStorageProvider,
40
+ * {
41
+ * ID: '123',
42
+ * Name: 'report.pdf',
43
+ * ProviderID: fileStorageProvider.ID
44
+ * }
45
+ * );
46
+ *
47
+ * // The content type is automatically determined from the file extension
48
+ * console.log(result.updatedInput.ContentType); // 'application/pdf'
49
+ *
50
+ * // The status is set to 'Uploading'
51
+ * console.log(result.updatedInput.Status); // 'Uploading'
52
+ *
53
+ * // The upload URL can be sent to the client for direct upload
54
+ * console.log(result.UploadUrl);
55
+ * ```
17
56
  */
18
57
  const createUploadUrl = async (providerEntity, input) => {
19
58
  const { Name, ProviderID } = input;
@@ -27,11 +66,32 @@ const createUploadUrl = async (providerEntity, input) => {
27
66
  };
28
67
  exports.createUploadUrl = createUploadUrl;
29
68
  /**
30
- * Creates a pre-authorized download URL for a file from the specified file storage provider.
69
+ * Creates a pre-authenticated download URL for a file from the specified file storage provider.
70
+ *
71
+ * This utility function simplifies the process of generating download URLs by instantiating
72
+ * the appropriate storage provider driver and delegating to its CreatePreAuthDownloadUrl method.
73
+ * The returned URL can be provided directly to clients for downloading the file without
74
+ * requiring additional authentication.
75
+ *
76
+ * @param providerEntity - The file storage provider entity containing connection details
77
+ * @param providerKeyOrName - The provider key or name of the file to download
78
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
79
+ * @returns A promise that resolves to the pre-authenticated download URL as a string
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Get a pre-authenticated download URL for a file
84
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
85
+ *
86
+ * // Using the file name
87
+ * const downloadUrl = await createDownloadUrl(fileStorageProvider, 'reports/annual-report.pdf');
31
88
  *
32
- * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
33
- * @param {string} providerKeyOrName - The provider key or Name for the file to download.
34
- * @returns {Promise<string>} - The pre-authorized download URL.
89
+ * // Or using the provider key if returned during upload
90
+ * const downloadUrl = await createDownloadUrl(fileStorageProvider, file.ProviderKey);
91
+ *
92
+ * // The download URL can be provided to clients for direct download
93
+ * console.log(downloadUrl);
94
+ * ```
35
95
  */
36
96
  const createDownloadUrl = async (providerEntity, providerKeyOrName) => {
37
97
  const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
@@ -39,12 +99,36 @@ const createDownloadUrl = async (providerEntity, providerKeyOrName) => {
39
99
  };
40
100
  exports.createDownloadUrl = createDownloadUrl;
41
101
  /**
42
- * Moves an object from one location to another within the file storage provider.
102
+ * Moves an object from one location to another within the specified file storage provider.
103
+ *
104
+ * This utility function handles moving files by instantiating the appropriate storage
105
+ * provider driver and delegating to its MoveObject method. It can be used to rename files
106
+ * or move them to different directories within the same storage provider.
107
+ *
108
+ * @param providerEntity - The file storage provider entity containing connection details
109
+ * @param oldProviderKeyOrName - The key or name of the object's current location
110
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
111
+ * @param newProviderKeyOrName - The key or name for the object's new location
112
+ * @returns A promise that resolves to a boolean indicating whether the move operation was successful
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Move a file from one location to another
117
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
118
+ *
119
+ * // Move a file to a different directory
120
+ * const success = await moveObject(
121
+ * fileStorageProvider,
122
+ * 'drafts/report.docx',
123
+ * 'published/final-report.docx'
124
+ * );
43
125
  *
44
- * @param providerEntity - The file storage provider entity.
45
- * @param oldProviderKeyOrName - The key or name of the old location of the object.
46
- * @param newProviderKeyOrName - The key or name of the new location to move the object to.
47
- * @returns A promise that resolves to a boolean indicating whether the object was successfully moved.
126
+ * if (success) {
127
+ * console.log('File successfully moved');
128
+ * } else {
129
+ * console.log('Failed to move file');
130
+ * }
131
+ * ```
48
132
  */
49
133
  const moveObject = async (providerEntity, oldProviderKeyOrName, newProviderKeyOrName) => {
50
134
  const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
@@ -52,11 +136,34 @@ const moveObject = async (providerEntity, oldProviderKeyOrName, newProviderKeyOr
52
136
  };
53
137
  exports.moveObject = moveObject;
54
138
  /**
55
- * Delete a previously uploaded file from the specified file storage provider.
139
+ * Deletes a file from the specified file storage provider.
140
+ *
141
+ * This utility function handles file deletion by instantiating the appropriate storage
142
+ * provider driver and delegating to its DeleteObject method. It provides a simple way
143
+ * to remove files that are no longer needed.
144
+ *
145
+ * @param providerEntity - The file storage provider entity containing connection details
146
+ * @param providerKeyOrName - The key or name of the file to delete
147
+ * (use the ProviderKey if it was returned during upload, otherwise use the file Name)
148
+ * @returns A promise that resolves to a boolean indicating whether the deletion was successful
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Delete a file from storage
153
+ * const fileStorageProvider = await entityMgr.FindById('FileStorageProvider', 'azure-main');
154
+ *
155
+ * // Delete using the file name
156
+ * const deleted = await deleteObject(fileStorageProvider, 'temp/obsolete-document.pdf');
157
+ *
158
+ * // Or using the provider key if returned during upload
159
+ * const deleted = await deleteObject(fileStorageProvider, file.ProviderKey);
56
160
  *
57
- * @param {FileStorageProviderEntity} providerEntity - The file storage provider entity.
58
- * @param {string} providerKeyOrName - The provider key or Name of the file to delete.
59
- * @returns {Promise<boolean>} - The success of he delete operation.
161
+ * if (deleted) {
162
+ * console.log('File successfully deleted');
163
+ * } else {
164
+ * console.log('Failed to delete file - it may not exist or there was an error');
165
+ * }
166
+ * ```
60
167
  */
61
168
  const deleteObject = (providerEntity, providerKeyOrName) => {
62
169
  const driver = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(FileStorageBase_1.FileStorageBase, providerEntity.ServerDriverKey);
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AACA,mDAAkD;AAClD,4DAA8B;AAC9B,+DAA4D;AAE5D;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,KAAK,EAGlC,cAAyC,EACzC,KAAa,EAIZ,EAAE;IACH,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAEnC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,oBAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC;IAC/F,MAAM,MAAM,GAAG,WAAW,CAAC;IAE3B,MAAM,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAE/H,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACrF,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IAE5E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,eAAe,mBAqB1B;AAEF;;;;;;GAMG;AACI,MAAM,iBAAiB,GAAG,KAAK,EAAE,cAAyC,EAAE,iBAAyB,EAAmB,EAAE;IAC/H,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAC/H,O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GAAG,CAC1B,cAAyC,EACzC,iBAAyB,EACP,EAAE;IACpB,MAAM,MAAM,GAAG,iBAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAkB,iCAAe,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAC/H,OAAO,MAAM,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAChD,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/storage",
3
- "version": "2.38.0",
3
+ "version": "2.40.0",
4
4
  "description": "This library provides a set of objects that handle the interface between the server-side API and various cloud storage providers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,9 +32,9 @@
32
32
  "@microsoft/mgt-sharepoint-provider": "^3.1.3",
33
33
  "googleapis": "^134.0.0",
34
34
  "dropbox": "^10.34.0",
35
- "@memberjunction/core": "2.38.0",
36
- "@memberjunction/core-entities": "2.38.0",
37
- "@memberjunction/global": "2.38.0",
35
+ "@memberjunction/core": "2.40.0",
36
+ "@memberjunction/core-entities": "2.40.0",
37
+ "@memberjunction/global": "2.40.0",
38
38
  "env-var": "^7.4.1",
39
39
  "mime-types": "^2.1.35"
40
40
  }