@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
package/readme.md CHANGED
@@ -1,3 +1,213 @@
1
1
  # @memberjunction/storage
2
2
 
3
- The `@memberjunction/storage` library provides a set of objects that handle the interface between the server-side API and various cloud storage providers.
3
+ The `@memberjunction/storage` library provides a unified interface for interacting with various cloud storage providers. It abstracts the complexities of different storage services behind a consistent API, making it easy to work with files stored across different cloud platforms.
4
+
5
+ [![MemberJunction Logo](https://memberjunction.com/images/MJ_Dark_Logo_Transparent_tm.png)](https://memberjunction.com)
6
+
7
+ ## Features
8
+
9
+ - **Unified API**: Consistent methods across all storage providers
10
+ - **Flexible Provider Selection**: Use any number of storage providers simultaneously based on your application needs
11
+ - **Commonly Supported Storage Providers**:
12
+ - [AWS S3](https://aws.amazon.com/s3/)
13
+ - [Azure Blob Storage](https://azure.microsoft.com/en-us/products/storage/blobs)
14
+ - [Google Cloud Storage](https://cloud.google.com/storage)
15
+ - [Google Drive](https://developers.google.com/drive/api/guides/about-sdk)
16
+ - [Microsoft SharePoint](https://learn.microsoft.com/en-us/sharepoint/dev/)
17
+ - [Dropbox](https://www.dropbox.com/developers/documentation)
18
+ - [Box](https://developer.box.com/guides/)
19
+ - **Common File Operations**:
20
+ - Upload files (via pre-authenticated URLs)
21
+ - Download files (via pre-authenticated URLs)
22
+ - Copy and move files
23
+ - Delete files and directories
24
+ - List files and directories
25
+ - Create and manage directories
26
+ - Get file metadata
27
+ - Check file/directory existence
28
+ - **Extensible**: Easy to add new storage providers
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install @memberjunction/storage
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Basic Setup
39
+
40
+ First, configure the environment variables required for your chosen storage provider(s). You can implement multiple providers simultaneously and switch between them based on your application requirements.
41
+
42
+ Refer to the documentation for each storage provider for detailed configuration requirements (see the "Storage Provider Configuration" section below).
43
+
44
+ #### Azure Blob Storage Example
45
+ ```bash
46
+ STORAGE_AZURE_CONTAINER=your-container-name
47
+ STORAGE_AZURE_ACCOUNT_NAME=your-account-name
48
+ STORAGE_AZURE_ACCOUNT_KEY=your-account-key
49
+ ```
50
+
51
+ ### Code Example
52
+
53
+ ```typescript
54
+ import { AzureFileStorage, createUploadUrl, createDownloadUrl, deleteObject } from '@memberjunction/storage';
55
+ import { FileStorageProviderEntity } from '@memberjunction/core-entities';
56
+
57
+ // Assuming you have a FileStorageProviderEntity loaded from your database
58
+ async function fileOperationsExample(provider: FileStorageProviderEntity) {
59
+ // Create pre-authenticated upload URL
60
+ const { updatedInput, UploadUrl } = await createUploadUrl(
61
+ provider,
62
+ {
63
+ ID: '123',
64
+ Name: 'document.pdf',
65
+ ProviderID: provider.ID
66
+ }
67
+ );
68
+
69
+ // The client can use the UploadUrl directly to upload the file
70
+ console.log(`Upload URL: ${UploadUrl}`);
71
+
72
+ // Later, create pre-authenticated download URL
73
+ const downloadUrl = await createDownloadUrl(provider, updatedInput.Name);
74
+ console.log(`Download URL: ${downloadUrl}`);
75
+
76
+ // Delete the file when no longer needed
77
+ const deleted = await deleteObject(provider, updatedInput.Name);
78
+ console.log(`File deleted: ${deleted}`);
79
+ }
80
+ ```
81
+
82
+ ### Direct Provider Usage
83
+
84
+ You can also work directly with a storage provider:
85
+
86
+ ```typescript
87
+ import { AzureFileStorage } from '@memberjunction/storage';
88
+
89
+ async function directProviderExample() {
90
+ const storage = new AzureFileStorage();
91
+
92
+ // List all files in a directory
93
+ const result = await storage.ListObjects('documents/');
94
+ console.log('Files:', result.objects);
95
+ console.log('Directories:', result.prefixes);
96
+
97
+ // Create a directory
98
+ await storage.CreateDirectory('documents/reports/');
99
+
100
+ // Upload a file directly
101
+ const content = Buffer.from('Hello, World!');
102
+ await storage.PutObject('documents/reports/hello.txt', content, 'text/plain');
103
+
104
+ // Copy a file
105
+ await storage.CopyObject('documents/reports/hello.txt', 'documents/archive/hello-copy.txt');
106
+
107
+ // Check if a file exists
108
+ const exists = await storage.ObjectExists('documents/reports/hello.txt');
109
+ }
110
+ ```
111
+
112
+ ## Architecture
113
+
114
+ The library uses a class hierarchy with `FileStorageBase` as the abstract base class that defines the common interface. Each storage provider implements this interface in its own way:
115
+
116
+ ```
117
+ FileStorageBase (Abstract Base Class)
118
+ ├── AWSFileStorage
119
+ ├── AzureFileStorage
120
+ ├── GoogleFileStorage
121
+ ├── GoogleDriveFileStorage
122
+ ├── SharePointFileStorage
123
+ ├── DropboxFileStorage
124
+ └── BoxFileStorage
125
+ ```
126
+
127
+ Utility functions provide a simplified interface for common operations.
128
+
129
+ ## Storage Provider Configuration
130
+
131
+ Each storage provider requires specific environment variables. Please refer to the official documentation for each provider for detailed information on authentication and additional configuration options.
132
+
133
+ ### AWS S3
134
+ - `STORAGE_AWS_BUCKET`: S3 bucket name
135
+ - `STORAGE_AWS_REGION`: AWS region (e.g., 'us-east-1')
136
+ - `STORAGE_AWS_ACCESS_KEY_ID`: AWS access key ID
137
+ - `STORAGE_AWS_SECRET_ACCESS_KEY`: AWS secret access key
138
+
139
+ For more information, see [AWS S3 Documentation](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started-nodejs.html).
140
+
141
+ ### Azure Blob Storage
142
+ - `STORAGE_AZURE_CONTAINER`: Container name
143
+ - `STORAGE_AZURE_ACCOUNT_NAME`: Account name
144
+ - `STORAGE_AZURE_ACCOUNT_KEY`: Account key
145
+
146
+ For more information, see [Azure Blob Storage Documentation](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs).
147
+
148
+ ### Google Cloud Storage
149
+ - `STORAGE_GOOGLE_BUCKET`: GCS bucket name
150
+ - `STORAGE_GOOGLE_KEY_FILE_PATH`: Path to service account key file (JSON)
151
+
152
+ For more information, see [Google Cloud Storage Documentation](https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-nodejs).
153
+
154
+ ### Google Drive
155
+ - `STORAGE_GOOGLE_DRIVE_CLIENT_ID`: OAuth client ID
156
+ - `STORAGE_GOOGLE_DRIVE_CLIENT_SECRET`: OAuth client secret
157
+ - `STORAGE_GOOGLE_DRIVE_REDIRECT_URI`: OAuth redirect URI
158
+ - `STORAGE_GOOGLE_DRIVE_REFRESH_TOKEN`: OAuth refresh token
159
+
160
+ For more information, see [Google Drive API Documentation](https://developers.google.com/drive/api/guides/about-sdk).
161
+
162
+ ### SharePoint
163
+ - `STORAGE_SHAREPOINT_SITE_URL`: SharePoint site URL
164
+ - `STORAGE_SHAREPOINT_CLIENT_ID`: Azure AD client ID
165
+ - `STORAGE_SHAREPOINT_CLIENT_SECRET`: Azure AD client secret
166
+ - `STORAGE_SHAREPOINT_TENANT_ID`: Azure AD tenant ID
167
+
168
+ For more information, see [Microsoft Graph API Documentation](https://learn.microsoft.com/en-us/graph/api/resources/sharepoint).
169
+
170
+ ### Dropbox
171
+ - `STORAGE_DROPBOX_ACCESS_TOKEN`: Dropbox access token
172
+ - `STORAGE_DROPBOX_REFRESH_TOKEN`: Dropbox refresh token (optional)
173
+ - `STORAGE_DROPBOX_APP_KEY`: Dropbox app key
174
+ - `STORAGE_DROPBOX_APP_SECRET`: Dropbox app secret
175
+
176
+ For more information, see [Dropbox API Documentation](https://www.dropbox.com/developers/documentation/javascript).
177
+
178
+ ### Box
179
+ - `STORAGE_BOX_CLIENT_ID`: Box client ID
180
+ - `STORAGE_BOX_CLIENT_SECRET`: Box client secret
181
+ - `STORAGE_BOX_ENTERPRISE_ID`: Box enterprise ID
182
+ - `STORAGE_BOX_JWT_KEY_ID`: Box JWT key ID
183
+ - `STORAGE_BOX_PRIVATE_KEY`: Box private key (base64 encoded)
184
+ - `STORAGE_BOX_PRIVATE_KEY_PASSPHRASE`: Box private key passphrase (optional)
185
+
186
+ For more information, see [Box Platform Documentation](https://developer.box.com/guides/authentication/).
187
+
188
+ ## Implementing Additional Providers
189
+
190
+ The library is designed to be extensible. You can implement new storage providers by:
191
+
192
+ 1. Creating a new class that extends `FileStorageBase`
193
+ 2. Implementing all required abstract methods
194
+ 3. Registering the class using the `@RegisterClass` decorator from `@memberjunction/global`
195
+
196
+ Refer to the existing provider implementations for guidance on how to implement a new provider.
197
+
198
+ ## Contributing
199
+
200
+ Contributions are welcome! To add a new storage provider:
201
+
202
+ 1. Create a new class in the `src/drivers` directory
203
+ 2. Extend the `FileStorageBase` class
204
+ 3. Implement all required methods
205
+ 4. Add exports to `src/index.ts`
206
+
207
+ ## License
208
+
209
+ ISC
210
+
211
+ ---
212
+
213
+ Part of the [MemberJunction](https://memberjunction.com) platform.