@edirect/storage-gateway 11.0.34 → 11.0.35
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/README.md +337 -3
- package/dist/README.md +337 -3
- package/dist/package.json +1 -1
- package/dist/src/storage-gateway/index.d.ts +2 -2
- package/dist/src/storage-gateway/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @edirect/storage-gateway
|
|
2
2
|
|
|
3
|
-
Storage Gateway
|
|
3
|
+
Storage Gateway client library for eDirect applications. Provides a simple interface to interact with the Storage Gateway API for managing storage configurations and file operations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,8 +8,342 @@ Storage Gateway module for eDirect applications.
|
|
|
8
8
|
npm install @edirect/storage-gateway
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
14
|
+
import { StorageGatewayClient } from '@edirect/storage-gateway';
|
|
15
|
+
|
|
16
|
+
// Create client without headers
|
|
17
|
+
const client = new StorageGatewayClient('https://api.example.com');
|
|
18
|
+
|
|
19
|
+
// Or with authentication headers
|
|
20
|
+
const client = new StorageGatewayClient('https://api.example.com', {
|
|
21
|
+
authorization: 'Bearer your-token-here',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// List storage configurations
|
|
25
|
+
const configs = await client.listStorageConfigurations();
|
|
26
|
+
|
|
27
|
+
// Upload a file
|
|
28
|
+
const file = new File(['content'], 'example.txt');
|
|
29
|
+
const result = await client.uploadFile({
|
|
30
|
+
storageKey: 'my-storage',
|
|
31
|
+
file: file,
|
|
32
|
+
path: 'documents/example.txt',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Reference
|
|
37
|
+
|
|
38
|
+
### Constructor
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
new StorageGatewayClient(baseUrl: string, headers?: StorageGatewayHeaders)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Parameters:**
|
|
45
|
+
- `baseUrl` - The base URL of the Storage Gateway API
|
|
46
|
+
- `headers` (optional) - Headers to include in all requests
|
|
47
|
+
|
|
48
|
+
**Types:**
|
|
49
|
+
```typescript
|
|
50
|
+
interface StorageGatewayHeaders {
|
|
51
|
+
authorization: string;
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Storage Configuration Methods
|
|
59
|
+
|
|
60
|
+
### listStorageConfigurations
|
|
61
|
+
|
|
62
|
+
List all storage configurations with optional pagination.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const configs = await client.listStorageConfigurations();
|
|
66
|
+
|
|
67
|
+
// With pagination
|
|
68
|
+
const configs = await client.listStorageConfigurations({
|
|
69
|
+
skip: 0,
|
|
70
|
+
take: 10,
|
|
71
|
+
});
|
|
15
72
|
```
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
- `params.skip` (optional) - Number of records to skip
|
|
76
|
+
- `params.take` (optional) - Number of records to return
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### createStorageConfiguration
|
|
81
|
+
|
|
82
|
+
Create a new storage configuration.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const config = await client.createStorageConfiguration({
|
|
86
|
+
key: 'my-storage',
|
|
87
|
+
provider: 's3',
|
|
88
|
+
credentials: {
|
|
89
|
+
accessKeyId: 'your-access-key',
|
|
90
|
+
secretAccessKey: 'your-secret-key',
|
|
91
|
+
region: 'us-east-1',
|
|
92
|
+
bucket: 'my-bucket',
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Parameters:**
|
|
98
|
+
- `data` - Configuration data object
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### getStorageConfiguration
|
|
103
|
+
|
|
104
|
+
Get a specific storage configuration by key.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const config = await client.getStorageConfiguration('my-storage');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Parameters:**
|
|
111
|
+
- `key` - The storage configuration key
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### updateStorageConfiguration
|
|
116
|
+
|
|
117
|
+
Update an existing storage configuration.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const updated = await client.updateStorageConfiguration({
|
|
121
|
+
key: 'my-storage',
|
|
122
|
+
data: {
|
|
123
|
+
credentials: {
|
|
124
|
+
accessKeyId: 'new-access-key',
|
|
125
|
+
secretAccessKey: 'new-secret-key',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `params.key` - The storage configuration key
|
|
133
|
+
- `params.data` - Updated configuration data
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### deleteStorageConfiguration
|
|
138
|
+
|
|
139
|
+
Delete a storage configuration.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
await client.deleteStorageConfiguration('my-storage');
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Parameters:**
|
|
146
|
+
- `key` - The storage configuration key to delete
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Storage Operations Methods
|
|
151
|
+
|
|
152
|
+
### listFiles
|
|
153
|
+
|
|
154
|
+
List files in storage.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const files = await client.listFiles({
|
|
158
|
+
storageKey: 'my-storage',
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// With path filter
|
|
162
|
+
const files = await client.listFiles({
|
|
163
|
+
storageKey: 'my-storage',
|
|
164
|
+
path: 'documents/',
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Parameters:**
|
|
169
|
+
- `params.storageKey` - The storage configuration key
|
|
170
|
+
- `params.path` (optional) - Path to list files from
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### uploadFile
|
|
175
|
+
|
|
176
|
+
Upload a file to storage.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const file = new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' });
|
|
180
|
+
|
|
181
|
+
const result = await client.uploadFile({
|
|
182
|
+
storageKey: 'my-storage',
|
|
183
|
+
file: file,
|
|
184
|
+
path: 'documents/hello.txt',
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Parameters:**
|
|
189
|
+
- `params.storageKey` - The storage configuration key
|
|
190
|
+
- `params.file` - The file to upload (File or Blob)
|
|
191
|
+
- `params.path` (optional) - Destination path for the file
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### downloadFile
|
|
196
|
+
|
|
197
|
+
Download a file from storage.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const blob = await client.downloadFile({
|
|
201
|
+
storageKey: 'my-storage',
|
|
202
|
+
path: 'documents/hello.txt',
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Save to file (Node.js)
|
|
206
|
+
const buffer = await blob.arrayBuffer();
|
|
207
|
+
fs.writeFileSync('downloaded.txt', Buffer.from(buffer));
|
|
208
|
+
|
|
209
|
+
// Or create download link (Browser)
|
|
210
|
+
const url = URL.createObjectURL(blob);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Parameters:**
|
|
214
|
+
- `params.storageKey` - The storage configuration key
|
|
215
|
+
- `params.path` - Path to the file to download
|
|
216
|
+
|
|
217
|
+
**Returns:** `Promise<Blob>`
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### getFileInfo
|
|
222
|
+
|
|
223
|
+
Get file metadata information.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
const info = await client.getFileInfo({
|
|
227
|
+
storageKey: 'my-storage',
|
|
228
|
+
path: 'documents/hello.txt',
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
console.log(info);
|
|
232
|
+
// { name: 'hello.txt', size: 1024, lastModified: '2024-01-01T00:00:00Z', ... }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Parameters:**
|
|
236
|
+
- `params.storageKey` - The storage configuration key
|
|
237
|
+
- `params.path` - Path to the file
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### deleteFile
|
|
242
|
+
|
|
243
|
+
Delete a file from storage.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
await client.deleteFile({
|
|
247
|
+
storageKey: 'my-storage',
|
|
248
|
+
path: 'documents/hello.txt',
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Parameters:**
|
|
253
|
+
- `params.storageKey` - The storage configuration key
|
|
254
|
+
- `params.path` - Path to the file to delete
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Storage Provider Methods
|
|
259
|
+
|
|
260
|
+
### listStorageProviders
|
|
261
|
+
|
|
262
|
+
List available storage providers.
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
const providers = await client.listStorageProviders();
|
|
266
|
+
|
|
267
|
+
console.log(providers);
|
|
268
|
+
// ['s3', 'azure-blob', 'gcs', 'local', ...]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Complete Example
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { StorageGatewayClient } from '@edirect/storage-gateway';
|
|
277
|
+
|
|
278
|
+
async function main() {
|
|
279
|
+
// Initialize client
|
|
280
|
+
const client = new StorageGatewayClient('https://storage-gateway.example.com', {
|
|
281
|
+
authorization: 'Bearer your-jwt-token',
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// List available providers
|
|
285
|
+
const providers = await client.listStorageProviders();
|
|
286
|
+
console.log('Available providers:', providers);
|
|
287
|
+
|
|
288
|
+
// Create a new storage configuration
|
|
289
|
+
const config = await client.createStorageConfiguration({
|
|
290
|
+
key: 'documents-storage',
|
|
291
|
+
provider: 's3',
|
|
292
|
+
credentials: {
|
|
293
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
294
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
295
|
+
region: 'us-east-1',
|
|
296
|
+
bucket: 'my-documents-bucket',
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
console.log('Created config:', config);
|
|
300
|
+
|
|
301
|
+
// Upload a file
|
|
302
|
+
const file = new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' });
|
|
303
|
+
const uploadResult = await client.uploadFile({
|
|
304
|
+
storageKey: 'documents-storage',
|
|
305
|
+
file: file,
|
|
306
|
+
path: 'greetings/hello.txt',
|
|
307
|
+
});
|
|
308
|
+
console.log('Upload result:', uploadResult);
|
|
309
|
+
|
|
310
|
+
// List files
|
|
311
|
+
const files = await client.listFiles({
|
|
312
|
+
storageKey: 'documents-storage',
|
|
313
|
+
path: 'greetings/',
|
|
314
|
+
});
|
|
315
|
+
console.log('Files:', files);
|
|
316
|
+
|
|
317
|
+
// Get file info
|
|
318
|
+
const fileInfo = await client.getFileInfo({
|
|
319
|
+
storageKey: 'documents-storage',
|
|
320
|
+
path: 'greetings/hello.txt',
|
|
321
|
+
});
|
|
322
|
+
console.log('File info:', fileInfo);
|
|
323
|
+
|
|
324
|
+
// Download file
|
|
325
|
+
const blob = await client.downloadFile({
|
|
326
|
+
storageKey: 'documents-storage',
|
|
327
|
+
path: 'greetings/hello.txt',
|
|
328
|
+
});
|
|
329
|
+
const text = await blob.text();
|
|
330
|
+
console.log('Downloaded content:', text);
|
|
331
|
+
|
|
332
|
+
// Delete file
|
|
333
|
+
await client.deleteFile({
|
|
334
|
+
storageKey: 'documents-storage',
|
|
335
|
+
path: 'greetings/hello.txt',
|
|
336
|
+
});
|
|
337
|
+
console.log('File deleted');
|
|
338
|
+
|
|
339
|
+
// Delete storage configuration
|
|
340
|
+
await client.deleteStorageConfiguration('documents-storage');
|
|
341
|
+
console.log('Configuration deleted');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
main().catch(console.error);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT
|
package/dist/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @edirect/storage-gateway
|
|
2
2
|
|
|
3
|
-
Storage Gateway
|
|
3
|
+
Storage Gateway client library for eDirect applications. Provides a simple interface to interact with the Storage Gateway API for managing storage configurations and file operations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,8 +8,342 @@ Storage Gateway module for eDirect applications.
|
|
|
8
8
|
npm install @edirect/storage-gateway
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
14
|
+
import { StorageGatewayClient } from '@edirect/storage-gateway';
|
|
15
|
+
|
|
16
|
+
// Create client without headers
|
|
17
|
+
const client = new StorageGatewayClient('https://api.example.com');
|
|
18
|
+
|
|
19
|
+
// Or with authentication headers
|
|
20
|
+
const client = new StorageGatewayClient('https://api.example.com', {
|
|
21
|
+
authorization: 'Bearer your-token-here',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// List storage configurations
|
|
25
|
+
const configs = await client.listStorageConfigurations();
|
|
26
|
+
|
|
27
|
+
// Upload a file
|
|
28
|
+
const file = new File(['content'], 'example.txt');
|
|
29
|
+
const result = await client.uploadFile({
|
|
30
|
+
storageKey: 'my-storage',
|
|
31
|
+
file: file,
|
|
32
|
+
path: 'documents/example.txt',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Reference
|
|
37
|
+
|
|
38
|
+
### Constructor
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
new StorageGatewayClient(baseUrl: string, headers?: StorageGatewayHeaders)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Parameters:**
|
|
45
|
+
- `baseUrl` - The base URL of the Storage Gateway API
|
|
46
|
+
- `headers` (optional) - Headers to include in all requests
|
|
47
|
+
|
|
48
|
+
**Types:**
|
|
49
|
+
```typescript
|
|
50
|
+
interface StorageGatewayHeaders {
|
|
51
|
+
authorization: string;
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Storage Configuration Methods
|
|
59
|
+
|
|
60
|
+
### listStorageConfigurations
|
|
61
|
+
|
|
62
|
+
List all storage configurations with optional pagination.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const configs = await client.listStorageConfigurations();
|
|
66
|
+
|
|
67
|
+
// With pagination
|
|
68
|
+
const configs = await client.listStorageConfigurations({
|
|
69
|
+
skip: 0,
|
|
70
|
+
take: 10,
|
|
71
|
+
});
|
|
15
72
|
```
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
- `params.skip` (optional) - Number of records to skip
|
|
76
|
+
- `params.take` (optional) - Number of records to return
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### createStorageConfiguration
|
|
81
|
+
|
|
82
|
+
Create a new storage configuration.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const config = await client.createStorageConfiguration({
|
|
86
|
+
key: 'my-storage',
|
|
87
|
+
provider: 's3',
|
|
88
|
+
credentials: {
|
|
89
|
+
accessKeyId: 'your-access-key',
|
|
90
|
+
secretAccessKey: 'your-secret-key',
|
|
91
|
+
region: 'us-east-1',
|
|
92
|
+
bucket: 'my-bucket',
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Parameters:**
|
|
98
|
+
- `data` - Configuration data object
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### getStorageConfiguration
|
|
103
|
+
|
|
104
|
+
Get a specific storage configuration by key.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const config = await client.getStorageConfiguration('my-storage');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Parameters:**
|
|
111
|
+
- `key` - The storage configuration key
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### updateStorageConfiguration
|
|
116
|
+
|
|
117
|
+
Update an existing storage configuration.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const updated = await client.updateStorageConfiguration({
|
|
121
|
+
key: 'my-storage',
|
|
122
|
+
data: {
|
|
123
|
+
credentials: {
|
|
124
|
+
accessKeyId: 'new-access-key',
|
|
125
|
+
secretAccessKey: 'new-secret-key',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `params.key` - The storage configuration key
|
|
133
|
+
- `params.data` - Updated configuration data
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### deleteStorageConfiguration
|
|
138
|
+
|
|
139
|
+
Delete a storage configuration.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
await client.deleteStorageConfiguration('my-storage');
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Parameters:**
|
|
146
|
+
- `key` - The storage configuration key to delete
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Storage Operations Methods
|
|
151
|
+
|
|
152
|
+
### listFiles
|
|
153
|
+
|
|
154
|
+
List files in storage.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const files = await client.listFiles({
|
|
158
|
+
storageKey: 'my-storage',
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// With path filter
|
|
162
|
+
const files = await client.listFiles({
|
|
163
|
+
storageKey: 'my-storage',
|
|
164
|
+
path: 'documents/',
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Parameters:**
|
|
169
|
+
- `params.storageKey` - The storage configuration key
|
|
170
|
+
- `params.path` (optional) - Path to list files from
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### uploadFile
|
|
175
|
+
|
|
176
|
+
Upload a file to storage.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const file = new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' });
|
|
180
|
+
|
|
181
|
+
const result = await client.uploadFile({
|
|
182
|
+
storageKey: 'my-storage',
|
|
183
|
+
file: file,
|
|
184
|
+
path: 'documents/hello.txt',
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Parameters:**
|
|
189
|
+
- `params.storageKey` - The storage configuration key
|
|
190
|
+
- `params.file` - The file to upload (File or Blob)
|
|
191
|
+
- `params.path` (optional) - Destination path for the file
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### downloadFile
|
|
196
|
+
|
|
197
|
+
Download a file from storage.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const blob = await client.downloadFile({
|
|
201
|
+
storageKey: 'my-storage',
|
|
202
|
+
path: 'documents/hello.txt',
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Save to file (Node.js)
|
|
206
|
+
const buffer = await blob.arrayBuffer();
|
|
207
|
+
fs.writeFileSync('downloaded.txt', Buffer.from(buffer));
|
|
208
|
+
|
|
209
|
+
// Or create download link (Browser)
|
|
210
|
+
const url = URL.createObjectURL(blob);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Parameters:**
|
|
214
|
+
- `params.storageKey` - The storage configuration key
|
|
215
|
+
- `params.path` - Path to the file to download
|
|
216
|
+
|
|
217
|
+
**Returns:** `Promise<Blob>`
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### getFileInfo
|
|
222
|
+
|
|
223
|
+
Get file metadata information.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
const info = await client.getFileInfo({
|
|
227
|
+
storageKey: 'my-storage',
|
|
228
|
+
path: 'documents/hello.txt',
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
console.log(info);
|
|
232
|
+
// { name: 'hello.txt', size: 1024, lastModified: '2024-01-01T00:00:00Z', ... }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Parameters:**
|
|
236
|
+
- `params.storageKey` - The storage configuration key
|
|
237
|
+
- `params.path` - Path to the file
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### deleteFile
|
|
242
|
+
|
|
243
|
+
Delete a file from storage.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
await client.deleteFile({
|
|
247
|
+
storageKey: 'my-storage',
|
|
248
|
+
path: 'documents/hello.txt',
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Parameters:**
|
|
253
|
+
- `params.storageKey` - The storage configuration key
|
|
254
|
+
- `params.path` - Path to the file to delete
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Storage Provider Methods
|
|
259
|
+
|
|
260
|
+
### listStorageProviders
|
|
261
|
+
|
|
262
|
+
List available storage providers.
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
const providers = await client.listStorageProviders();
|
|
266
|
+
|
|
267
|
+
console.log(providers);
|
|
268
|
+
// ['s3', 'azure-blob', 'gcs', 'local', ...]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Complete Example
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { StorageGatewayClient } from '@edirect/storage-gateway';
|
|
277
|
+
|
|
278
|
+
async function main() {
|
|
279
|
+
// Initialize client
|
|
280
|
+
const client = new StorageGatewayClient('https://storage-gateway.example.com', {
|
|
281
|
+
authorization: 'Bearer your-jwt-token',
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// List available providers
|
|
285
|
+
const providers = await client.listStorageProviders();
|
|
286
|
+
console.log('Available providers:', providers);
|
|
287
|
+
|
|
288
|
+
// Create a new storage configuration
|
|
289
|
+
const config = await client.createStorageConfiguration({
|
|
290
|
+
key: 'documents-storage',
|
|
291
|
+
provider: 's3',
|
|
292
|
+
credentials: {
|
|
293
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
294
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
295
|
+
region: 'us-east-1',
|
|
296
|
+
bucket: 'my-documents-bucket',
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
console.log('Created config:', config);
|
|
300
|
+
|
|
301
|
+
// Upload a file
|
|
302
|
+
const file = new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' });
|
|
303
|
+
const uploadResult = await client.uploadFile({
|
|
304
|
+
storageKey: 'documents-storage',
|
|
305
|
+
file: file,
|
|
306
|
+
path: 'greetings/hello.txt',
|
|
307
|
+
});
|
|
308
|
+
console.log('Upload result:', uploadResult);
|
|
309
|
+
|
|
310
|
+
// List files
|
|
311
|
+
const files = await client.listFiles({
|
|
312
|
+
storageKey: 'documents-storage',
|
|
313
|
+
path: 'greetings/',
|
|
314
|
+
});
|
|
315
|
+
console.log('Files:', files);
|
|
316
|
+
|
|
317
|
+
// Get file info
|
|
318
|
+
const fileInfo = await client.getFileInfo({
|
|
319
|
+
storageKey: 'documents-storage',
|
|
320
|
+
path: 'greetings/hello.txt',
|
|
321
|
+
});
|
|
322
|
+
console.log('File info:', fileInfo);
|
|
323
|
+
|
|
324
|
+
// Download file
|
|
325
|
+
const blob = await client.downloadFile({
|
|
326
|
+
storageKey: 'documents-storage',
|
|
327
|
+
path: 'greetings/hello.txt',
|
|
328
|
+
});
|
|
329
|
+
const text = await blob.text();
|
|
330
|
+
console.log('Downloaded content:', text);
|
|
331
|
+
|
|
332
|
+
// Delete file
|
|
333
|
+
await client.deleteFile({
|
|
334
|
+
storageKey: 'documents-storage',
|
|
335
|
+
path: 'greetings/hello.txt',
|
|
336
|
+
});
|
|
337
|
+
console.log('File deleted');
|
|
338
|
+
|
|
339
|
+
// Delete storage configuration
|
|
340
|
+
await client.deleteStorageConfiguration('documents-storage');
|
|
341
|
+
console.log('Configuration deleted');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
main().catch(console.error);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT
|
package/dist/package.json
CHANGED
|
@@ -4,8 +4,8 @@ export interface StorageGatewayHeaders {
|
|
|
4
4
|
}
|
|
5
5
|
export declare class StorageGatewayClient {
|
|
6
6
|
private BASE_URL;
|
|
7
|
-
private headers
|
|
8
|
-
constructor(baseUrl: string, headers
|
|
7
|
+
private headers?;
|
|
8
|
+
constructor(baseUrl: string, headers?: StorageGatewayHeaders);
|
|
9
9
|
private getHeaders;
|
|
10
10
|
/**
|
|
11
11
|
* List all storage configurations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage-gateway/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAwB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage-gateway/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAC,CAAwB;gBAE5B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAK5D,OAAO,CAAC,UAAU;IAMlB;;;;;;;;;;;;OAYG;IACU,yBAAyB,CAAC,MAAM,CAAC,EAAE;QAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;IAWD;;;;;;;;;;;;;;OAcG;IACU,0BAA0B,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAarE;;;;;;;;;;OAUG;IACU,uBAAuB,CAAC,GAAG,EAAE,MAAM;IAShD;;;;;;;;;;;;;;;OAeG;IACU,0BAA0B,CAAC,MAAM,EAAE;QAC9C,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B;IAaD;;;;;;;;;;OAUG;IACU,0BAA0B,CAAC,GAAG,EAAE,MAAM;IAcnD;;;;;;;;;;;;;;;OAeG;IACU,SAAS,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAOpE;;;;;;;;;;;;;;;;;;OAkBG;IACU,UAAU,CAAC,MAAM,EAAE;QAC9B,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;IAcD;;;;;;;;;;;;;;;OAeG;IACU,YAAY,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAOtE;;;;;;;;;;;;;;;OAeG;IACU,WAAW,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAOrE;;;;;;;;;;;;;;;OAeG;IACU,UAAU,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAYpE;;;;;;;;;OASG;IACU,oBAAoB;CAOlC"}
|