@onlineapps/conn-base-storage 1.0.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/API.md +618 -0
- package/README.md +341 -0
- package/SHARED_URL_ADDRESSING.md +258 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +213 -0
- package/coverage/coverage-final.json +3 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/index.js.html +1579 -0
- package/coverage/internal-url-adapter.js.html +604 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/index.js.html +1579 -0
- package/coverage/lcov-report/internal-url-adapter.js.html +604 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +434 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/jest.config.js +13 -0
- package/jest.integration.config.js +9 -0
- package/package.json +33 -0
- package/src/index.js +853 -0
- package/src/internal-url-adapter.js +174 -0
- package/src/sharedUrlAdapter.js +258 -0
- package/test/component/storage.component.test.js +363 -0
- package/test/integration/setup.js +3 -0
- package/test/integration/storage.integration.test.js +224 -0
- package/test/unit/internal-url-adapter.test.js +211 -0
- package/test/unit/legacy.storage.test.js.bak +614 -0
- package/test/unit/storage.extended.unit.test.js +435 -0
- package/test/unit/storage.unit.test.js +373 -0
package/API.md
ADDED
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
<a name="module_@onlineapps/conn-base-storage"></a>
|
|
2
|
+
|
|
3
|
+
## @onlineapps/conn-base-storage
|
|
4
|
+
MinIO storage connector with automatic SHA256 fingerprinting for OA Drive.
|
|
5
|
+
Provides immutable content storage with verification, caching, and presigned URLs.
|
|
6
|
+
|
|
7
|
+
**See**: [GitHub Repository](https://github.com/onlineapps/oa-drive/tree/main/shared/connector/conn-base-storage)
|
|
8
|
+
**Since**: 1.0.0
|
|
9
|
+
**Author**: OA Drive Team
|
|
10
|
+
**License**: MIT
|
|
11
|
+
|
|
12
|
+
* [@onlineapps/conn-base-storage](#module_@onlineapps/conn-base-storage)
|
|
13
|
+
* _static_
|
|
14
|
+
* [.VERSION](#module_@onlineapps/conn-base-storage.VERSION) : <code>string</code>
|
|
15
|
+
* _inner_
|
|
16
|
+
* [~StorageConnector](#module_@onlineapps/conn-base-storage..StorageConnector)
|
|
17
|
+
* [new StorageConnector()](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
18
|
+
* [new StorageConnector([config])](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
19
|
+
* [~StorageConnector](#module_@onlineapps/conn-base-storage..StorageConnector)
|
|
20
|
+
* [new StorageConnector()](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
21
|
+
* [new StorageConnector([config])](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
22
|
+
* [~initialize()](#module_@onlineapps/conn-base-storage..initialize) ⇒ <code>Promise.<boolean></code>
|
|
23
|
+
* [~generateFingerprint(content)](#module_@onlineapps/conn-base-storage..generateFingerprint) ⇒ <code>string</code>
|
|
24
|
+
* [~uploadWithFingerprint(bucket, content, [pathPrefix])](#module_@onlineapps/conn-base-storage..uploadWithFingerprint) ⇒ <code>Promise.<UploadResult></code> \| <code>string</code> \| <code>string</code> \| <code>string</code> \| <code>string</code> \| <code>boolean</code>
|
|
25
|
+
* [~downloadWithVerification(bucket, path, expectedFingerprint)](#module_@onlineapps/conn-base-storage..downloadWithVerification) ⇒ <code>Promise.<string></code>
|
|
26
|
+
* [~getPresignedUrl(bucket, path, [expiry])](#module_@onlineapps/conn-base-storage..getPresignedUrl) ⇒ <code>Promise.<string></code>
|
|
27
|
+
* [~listWithFingerprints(bucket, [prefix])](#module_@onlineapps/conn-base-storage..listWithFingerprints) ⇒ <code>Promise.<Array.<ObjectInfo>></code>
|
|
28
|
+
* [~deleteObject(bucket, path)](#module_@onlineapps/conn-base-storage..deleteObject) ⇒ <code>Promise.<boolean></code>
|
|
29
|
+
* [~getPublicUrl(bucket, path)](#module_@onlineapps/conn-base-storage..getPublicUrl) ⇒ <code>string</code>
|
|
30
|
+
* [~ensureBucket(bucketName)](#module_@onlineapps/conn-base-storage..ensureBucket) ⇒ <code>Promise.<boolean></code>
|
|
31
|
+
* [~validateBucketName(name)](#module_@onlineapps/conn-base-storage..validateBucketName) ⇒ <code>string</code>
|
|
32
|
+
* [~getObjectNameWithFingerprint(originalName, fingerprint)](#module_@onlineapps/conn-base-storage..getObjectNameWithFingerprint) ⇒ <code>string</code>
|
|
33
|
+
* [~extractFingerprintFromName(objectName)](#module_@onlineapps/conn-base-storage..extractFingerprintFromName) ⇒ <code>string</code> \| <code>null</code>
|
|
34
|
+
* [~clearCache()](#module_@onlineapps/conn-base-storage..clearCache) ⇒ <code>void</code>
|
|
35
|
+
* [~getInternalUrl(bucket, path)](#module_@onlineapps/conn-base-storage..getInternalUrl) ⇒ <code>string</code>
|
|
36
|
+
* ~~[~getPublicUrl(bucket, path)](#module_@onlineapps/conn-base-storage..getPublicUrl) ⇒ <code>string</code>~~
|
|
37
|
+
* [~getPresignedUrl(bucket, objectName, [expiry])](#module_@onlineapps/conn-base-storage..getPresignedUrl) ⇒ <code>Promise.<string></code>
|
|
38
|
+
* [~listObjectsWithFingerprints(bucket, [prefix])](#module_@onlineapps/conn-base-storage..listObjectsWithFingerprints) ⇒ <code>Promise.<Array.<Object>></code>
|
|
39
|
+
* [~create(config)](#module_@onlineapps/conn-base-storage..create) ⇒ <code>StorageConnector</code>
|
|
40
|
+
* [~UploadResult](#module_@onlineapps/conn-base-storage..UploadResult) : <code>Object</code>
|
|
41
|
+
* [~ObjectInfo](#module_@onlineapps/conn-base-storage..ObjectInfo) : <code>Object</code>
|
|
42
|
+
|
|
43
|
+
<a name="module_@onlineapps/conn-base-storage.VERSION"></a>
|
|
44
|
+
|
|
45
|
+
### @onlineapps/conn-base-storage.VERSION : <code>string</code>
|
|
46
|
+
Current version
|
|
47
|
+
|
|
48
|
+
**Kind**: static constant of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
49
|
+
<a name="module_@onlineapps/conn-base-storage..StorageConnector"></a>
|
|
50
|
+
|
|
51
|
+
### @onlineapps/conn-base-storage~StorageConnector
|
|
52
|
+
**Kind**: inner class of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
53
|
+
|
|
54
|
+
* [~StorageConnector](#module_@onlineapps/conn-base-storage..StorageConnector)
|
|
55
|
+
* [new StorageConnector()](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
56
|
+
* [new StorageConnector([config])](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
57
|
+
|
|
58
|
+
<a name="new_module_@onlineapps/conn-base-storage..StorageConnector_new"></a>
|
|
59
|
+
|
|
60
|
+
#### new StorageConnector()
|
|
61
|
+
Storage connector for MinIO with automatic fingerprinting
|
|
62
|
+
|
|
63
|
+
**Example** *(Basic Usage)*
|
|
64
|
+
```js
|
|
65
|
+
const storage = new StorageConnector({
|
|
66
|
+
endPoint: 'minio.example.com',
|
|
67
|
+
port: 9000,
|
|
68
|
+
accessKey: 'minioadmin',
|
|
69
|
+
secretKey: 'minioadmin'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await storage.initialize();
|
|
73
|
+
const result = await storage.uploadWithFingerprint(
|
|
74
|
+
'documents',
|
|
75
|
+
{ type: 'invoice', amount: 1500 },
|
|
76
|
+
'invoices'
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
**Example** *(With Caching)*
|
|
80
|
+
```js
|
|
81
|
+
const storage = new StorageConnector({
|
|
82
|
+
cacheEnabled: true,
|
|
83
|
+
maxCacheSize: 200
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
<a name="new_module_@onlineapps/conn-base-storage..StorageConnector_new"></a>
|
|
87
|
+
|
|
88
|
+
#### new StorageConnector([config])
|
|
89
|
+
Creates a new StorageConnector instance
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
| Param | Type | Default | Description |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| [config] | <code>Object</code> | <code>{}</code> | Configuration options |
|
|
95
|
+
| [config.endPoint] | <code>string</code> | <code>"'localhost'"</code> | MinIO server endpoint |
|
|
96
|
+
| [config.port] | <code>number</code> | <code>9000</code> | MinIO server port |
|
|
97
|
+
| [config.useSSL] | <code>boolean</code> | <code>false</code> | Use SSL/TLS |
|
|
98
|
+
| [config.accessKey] | <code>string</code> | <code>"'minioadmin'"</code> | Access key |
|
|
99
|
+
| [config.secretKey] | <code>string</code> | <code>"'minioadmin'"</code> | Secret key |
|
|
100
|
+
| [config.defaultBucket] | <code>string</code> | <code>"'api-storage'"</code> | Default bucket name |
|
|
101
|
+
| [config.cacheEnabled] | <code>boolean</code> | <code>true</code> | Enable content caching |
|
|
102
|
+
| [config.maxCacheSize] | <code>number</code> | <code>100</code> | Maximum cache entries |
|
|
103
|
+
| [config.logLevel] | <code>string</code> | <code>"'info'"</code> | Logging level |
|
|
104
|
+
|
|
105
|
+
**Example** *(Full Configuration)*
|
|
106
|
+
```js
|
|
107
|
+
const storage = new StorageConnector({
|
|
108
|
+
endPoint: 'minio.example.com',
|
|
109
|
+
port: 9000,
|
|
110
|
+
useSSL: true,
|
|
111
|
+
accessKey: 'AKIAIOSFODNN7EXAMPLE',
|
|
112
|
+
secretKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
|
113
|
+
defaultBucket: 'production-storage',
|
|
114
|
+
cacheEnabled: true,
|
|
115
|
+
maxCacheSize: 500
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
<a name="module_@onlineapps/conn-base-storage..StorageConnector"></a>
|
|
119
|
+
|
|
120
|
+
### @onlineapps/conn-base-storage~StorageConnector
|
|
121
|
+
**Kind**: inner class of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
122
|
+
|
|
123
|
+
* [~StorageConnector](#module_@onlineapps/conn-base-storage..StorageConnector)
|
|
124
|
+
* [new StorageConnector()](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
125
|
+
* [new StorageConnector([config])](#new_module_@onlineapps/conn-base-storage..StorageConnector_new)
|
|
126
|
+
|
|
127
|
+
<a name="new_module_@onlineapps/conn-base-storage..StorageConnector_new"></a>
|
|
128
|
+
|
|
129
|
+
#### new StorageConnector()
|
|
130
|
+
Storage connector for MinIO with automatic fingerprinting
|
|
131
|
+
|
|
132
|
+
**Example** *(Basic Usage)*
|
|
133
|
+
```js
|
|
134
|
+
const storage = new StorageConnector({
|
|
135
|
+
endPoint: 'minio.example.com',
|
|
136
|
+
port: 9000,
|
|
137
|
+
accessKey: 'minioadmin',
|
|
138
|
+
secretKey: 'minioadmin'
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await storage.initialize();
|
|
142
|
+
const result = await storage.uploadWithFingerprint(
|
|
143
|
+
'documents',
|
|
144
|
+
{ type: 'invoice', amount: 1500 },
|
|
145
|
+
'invoices'
|
|
146
|
+
);
|
|
147
|
+
```
|
|
148
|
+
**Example** *(With Caching)*
|
|
149
|
+
```js
|
|
150
|
+
const storage = new StorageConnector({
|
|
151
|
+
cacheEnabled: true,
|
|
152
|
+
maxCacheSize: 200
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
<a name="new_module_@onlineapps/conn-base-storage..StorageConnector_new"></a>
|
|
156
|
+
|
|
157
|
+
#### new StorageConnector([config])
|
|
158
|
+
Creates a new StorageConnector instance
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
| Param | Type | Default | Description |
|
|
162
|
+
| --- | --- | --- | --- |
|
|
163
|
+
| [config] | <code>Object</code> | <code>{}</code> | Configuration options |
|
|
164
|
+
| [config.endPoint] | <code>string</code> | <code>"'localhost'"</code> | MinIO server endpoint |
|
|
165
|
+
| [config.port] | <code>number</code> | <code>9000</code> | MinIO server port |
|
|
166
|
+
| [config.useSSL] | <code>boolean</code> | <code>false</code> | Use SSL/TLS |
|
|
167
|
+
| [config.accessKey] | <code>string</code> | <code>"'minioadmin'"</code> | Access key |
|
|
168
|
+
| [config.secretKey] | <code>string</code> | <code>"'minioadmin'"</code> | Secret key |
|
|
169
|
+
| [config.defaultBucket] | <code>string</code> | <code>"'api-storage'"</code> | Default bucket name |
|
|
170
|
+
| [config.cacheEnabled] | <code>boolean</code> | <code>true</code> | Enable content caching |
|
|
171
|
+
| [config.maxCacheSize] | <code>number</code> | <code>100</code> | Maximum cache entries |
|
|
172
|
+
| [config.logLevel] | <code>string</code> | <code>"'info'"</code> | Logging level |
|
|
173
|
+
|
|
174
|
+
**Example** *(Full Configuration)*
|
|
175
|
+
```js
|
|
176
|
+
const storage = new StorageConnector({
|
|
177
|
+
endPoint: 'minio.example.com',
|
|
178
|
+
port: 9000,
|
|
179
|
+
useSSL: true,
|
|
180
|
+
accessKey: 'AKIAIOSFODNN7EXAMPLE',
|
|
181
|
+
secretKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
|
182
|
+
defaultBucket: 'production-storage',
|
|
183
|
+
cacheEnabled: true,
|
|
184
|
+
maxCacheSize: 500
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
<a name="module_@onlineapps/conn-base-storage..initialize"></a>
|
|
188
|
+
|
|
189
|
+
### @onlineapps/conn-base-storage~initialize() ⇒ <code>Promise.<boolean></code>
|
|
190
|
+
Initialize connector and ensure bucket exists
|
|
191
|
+
|
|
192
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
193
|
+
**Returns**: <code>Promise.<boolean></code> - Returns true when initialized
|
|
194
|
+
**Throws**:
|
|
195
|
+
|
|
196
|
+
- <code>Error</code> If initialization fails
|
|
197
|
+
|
|
198
|
+
**Example**
|
|
199
|
+
```js
|
|
200
|
+
try {
|
|
201
|
+
await storage.initialize();
|
|
202
|
+
console.log('Storage ready');
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error('Failed to initialize:', error);
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
<a name="module_@onlineapps/conn-base-storage..generateFingerprint"></a>
|
|
208
|
+
|
|
209
|
+
### @onlineapps/conn-base-storage~generateFingerprint(content) ⇒ <code>string</code>
|
|
210
|
+
Generate SHA256 fingerprint for content
|
|
211
|
+
|
|
212
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
213
|
+
**Returns**: <code>string</code> - SHA256 hash in hex format
|
|
214
|
+
|
|
215
|
+
| Param | Type | Description |
|
|
216
|
+
| --- | --- | --- |
|
|
217
|
+
| content | <code>string</code> \| <code>Buffer</code> \| <code>Object</code> | Content to fingerprint |
|
|
218
|
+
|
|
219
|
+
**Example** *(String Content)*
|
|
220
|
+
```js
|
|
221
|
+
const hash = storage.generateFingerprint('Hello World');
|
|
222
|
+
// Returns: SHA256 hash
|
|
223
|
+
```
|
|
224
|
+
**Example** *(Object Content)*
|
|
225
|
+
```js
|
|
226
|
+
const hash = storage.generateFingerprint({ name: 'John', age: 30 });
|
|
227
|
+
// Returns consistent hash for the object
|
|
228
|
+
```
|
|
229
|
+
<a name="module_@onlineapps/conn-base-storage..uploadWithFingerprint"></a>
|
|
230
|
+
|
|
231
|
+
### @onlineapps/conn-base-storage~uploadWithFingerprint(bucket, content, [pathPrefix]) ⇒ <code>Promise.<UploadResult></code> \| <code>string</code> \| <code>string</code> \| <code>string</code> \| <code>string</code> \| <code>boolean</code>
|
|
232
|
+
Upload content with automatic fingerprinting
|
|
233
|
+
|
|
234
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
235
|
+
**Returns**: <code>Promise.<UploadResult></code> - Upload result with fingerprint<code>string</code> - result.fingerprint - SHA256 fingerprint<code>string</code> - result.bucket - Bucket name<code>string</code> - result.path - Storage path<code>string</code> - result.url - Public URL<code>boolean</code> - result.existed - Whether object already existed
|
|
236
|
+
**Throws**:
|
|
237
|
+
|
|
238
|
+
- <code>Error</code> If upload fails
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
| Param | Type | Default | Description |
|
|
242
|
+
| --- | --- | --- | --- |
|
|
243
|
+
| bucket | <code>string</code> | | Bucket name |
|
|
244
|
+
| content | <code>string</code> \| <code>Buffer</code> \| <code>Object</code> | | Content to upload |
|
|
245
|
+
| [pathPrefix] | <code>string</code> | <code>"''"</code> | Path prefix for organization |
|
|
246
|
+
|
|
247
|
+
**Example** *(Upload JSON Object)*
|
|
248
|
+
```js
|
|
249
|
+
const result = await storage.uploadWithFingerprint(
|
|
250
|
+
'invoices',
|
|
251
|
+
{ invoiceId: 'INV-123', amount: 1500 },
|
|
252
|
+
'2024/01'
|
|
253
|
+
);
|
|
254
|
+
console.log(`Stored at: ${result.url}`);
|
|
255
|
+
console.log(`Fingerprint: ${result.fingerprint}`);
|
|
256
|
+
```
|
|
257
|
+
**Example** *(Upload String Content)*
|
|
258
|
+
```js
|
|
259
|
+
const result = await storage.uploadWithFingerprint(
|
|
260
|
+
'documents',
|
|
261
|
+
'Important document content',
|
|
262
|
+
'contracts'
|
|
263
|
+
);
|
|
264
|
+
```
|
|
265
|
+
**Example** *(Upload Buffer)*
|
|
266
|
+
```js
|
|
267
|
+
const buffer = Buffer.from('Binary data');
|
|
268
|
+
const result = await storage.uploadWithFingerprint(
|
|
269
|
+
'files',
|
|
270
|
+
buffer
|
|
271
|
+
);
|
|
272
|
+
```
|
|
273
|
+
<a name="module_@onlineapps/conn-base-storage..downloadWithVerification"></a>
|
|
274
|
+
|
|
275
|
+
### @onlineapps/conn-base-storage~downloadWithVerification(bucket, path, expectedFingerprint) ⇒ <code>Promise.<string></code>
|
|
276
|
+
Download content and verify fingerprint
|
|
277
|
+
|
|
278
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
279
|
+
**Returns**: <code>Promise.<string></code> - Content as string
|
|
280
|
+
**Throws**:
|
|
281
|
+
|
|
282
|
+
- <code>Error</code> If download fails or fingerprint mismatch
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
| Param | Type | Description |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| bucket | <code>string</code> | Bucket name |
|
|
288
|
+
| path | <code>string</code> | Object path |
|
|
289
|
+
| expectedFingerprint | <code>string</code> | Expected SHA256 fingerprint |
|
|
290
|
+
|
|
291
|
+
**Example** *(Download with Verification)*
|
|
292
|
+
```js
|
|
293
|
+
const content = await storage.downloadWithVerification(
|
|
294
|
+
'invoices',
|
|
295
|
+
'2024/01/abc123.json',
|
|
296
|
+
'abc123...'
|
|
297
|
+
);
|
|
298
|
+
const data = JSON.parse(content);
|
|
299
|
+
```
|
|
300
|
+
**Example** *(Handle Verification Failure)*
|
|
301
|
+
```js
|
|
302
|
+
try {
|
|
303
|
+
const content = await storage.downloadWithVerification(
|
|
304
|
+
'documents',
|
|
305
|
+
'contract.json',
|
|
306
|
+
expectedHash
|
|
307
|
+
);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
if (error.message.includes('Fingerprint mismatch')) {
|
|
310
|
+
console.error('Content has been tampered!');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
<a name="module_@onlineapps/conn-base-storage..getPresignedUrl"></a>
|
|
315
|
+
|
|
316
|
+
### @onlineapps/conn-base-storage~getPresignedUrl(bucket, path, [expiry]) ⇒ <code>Promise.<string></code>
|
|
317
|
+
Get pre-signed URL for direct access
|
|
318
|
+
|
|
319
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
320
|
+
**Returns**: <code>Promise.<string></code> - Pre-signed URL
|
|
321
|
+
**Throws**:
|
|
322
|
+
|
|
323
|
+
- <code>Error</code> If URL generation fails
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
| Param | Type | Default | Description |
|
|
327
|
+
| --- | --- | --- | --- |
|
|
328
|
+
| bucket | <code>string</code> | | Bucket name |
|
|
329
|
+
| path | <code>string</code> | | Object path |
|
|
330
|
+
| [expiry] | <code>number</code> | <code>3600</code> | URL expiry in seconds |
|
|
331
|
+
|
|
332
|
+
**Example** *(Generate Temporary URL)*
|
|
333
|
+
```js
|
|
334
|
+
const url = await storage.getPresignedUrl(
|
|
335
|
+
'invoices',
|
|
336
|
+
'2024/01/invoice-123.json',
|
|
337
|
+
7200 // 2 hours
|
|
338
|
+
);
|
|
339
|
+
// Share URL with external service
|
|
340
|
+
```
|
|
341
|
+
**Example** *(Short-lived URL)*
|
|
342
|
+
```js
|
|
343
|
+
const url = await storage.getPresignedUrl(
|
|
344
|
+
'temp',
|
|
345
|
+
'report.pdf',
|
|
346
|
+
300 // 5 minutes
|
|
347
|
+
);
|
|
348
|
+
```
|
|
349
|
+
<a name="module_@onlineapps/conn-base-storage..listWithFingerprints"></a>
|
|
350
|
+
|
|
351
|
+
### @onlineapps/conn-base-storage~listWithFingerprints(bucket, [prefix]) ⇒ <code>Promise.<Array.<ObjectInfo>></code>
|
|
352
|
+
List objects with fingerprint metadata
|
|
353
|
+
|
|
354
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
355
|
+
**Returns**: <code>Promise.<Array.<ObjectInfo>></code> - List of objects with metadata
|
|
356
|
+
|
|
357
|
+
| Param | Type | Default | Description |
|
|
358
|
+
| --- | --- | --- | --- |
|
|
359
|
+
| bucket | <code>string</code> | | Bucket name |
|
|
360
|
+
| [prefix] | <code>string</code> | <code>"''"</code> | Path prefix to filter |
|
|
361
|
+
|
|
362
|
+
**Example** *(List All Objects)*
|
|
363
|
+
```js
|
|
364
|
+
const objects = await storage.listWithFingerprints('invoices');
|
|
365
|
+
objects.forEach(obj => {
|
|
366
|
+
console.log(`${obj.name}: ${obj.fingerprint}`);
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
**Example** *(List with Prefix)*
|
|
370
|
+
```js
|
|
371
|
+
const objects = await storage.listWithFingerprints(
|
|
372
|
+
'documents',
|
|
373
|
+
'2024/01/'
|
|
374
|
+
);
|
|
375
|
+
```
|
|
376
|
+
<a name="module_@onlineapps/conn-base-storage..deleteObject"></a>
|
|
377
|
+
|
|
378
|
+
### @onlineapps/conn-base-storage~deleteObject(bucket, path) ⇒ <code>Promise.<boolean></code>
|
|
379
|
+
Delete object (use with caution - breaks immutability)
|
|
380
|
+
|
|
381
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
382
|
+
**Returns**: <code>Promise.<boolean></code> - Returns true on successful deletion
|
|
383
|
+
**Throws**:
|
|
384
|
+
|
|
385
|
+
- <code>Error</code> If deletion fails
|
|
386
|
+
|
|
387
|
+
**Warning**: This breaks immutability - use only when necessary
|
|
388
|
+
|
|
389
|
+
| Param | Type | Description |
|
|
390
|
+
| --- | --- | --- |
|
|
391
|
+
| bucket | <code>string</code> | Bucket name |
|
|
392
|
+
| path | <code>string</code> | Object path |
|
|
393
|
+
|
|
394
|
+
**Example**
|
|
395
|
+
```js
|
|
396
|
+
await storage.deleteObject('temp', 'temporary-file.json');
|
|
397
|
+
```
|
|
398
|
+
<a name="module_@onlineapps/conn-base-storage..getPublicUrl"></a>
|
|
399
|
+
|
|
400
|
+
### @onlineapps/conn-base-storage~getPublicUrl(bucket, path) ⇒ <code>string</code>
|
|
401
|
+
Get public URL for an object
|
|
402
|
+
|
|
403
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
404
|
+
**Returns**: <code>string</code> - Public URL
|
|
405
|
+
|
|
406
|
+
| Param | Type | Description |
|
|
407
|
+
| --- | --- | --- |
|
|
408
|
+
| bucket | <code>string</code> | Bucket name |
|
|
409
|
+
| path | <code>string</code> | Object path |
|
|
410
|
+
|
|
411
|
+
**Example**
|
|
412
|
+
```js
|
|
413
|
+
const url = storage.getPublicUrl('invoices', '2024/invoice-123.json');
|
|
414
|
+
// Returns: http://localhost:9000/invoices/2024/invoice-123.json
|
|
415
|
+
```
|
|
416
|
+
<a name="module_@onlineapps/conn-base-storage..ensureBucket"></a>
|
|
417
|
+
|
|
418
|
+
### @onlineapps/conn-base-storage~ensureBucket(bucketName) ⇒ <code>Promise.<boolean></code>
|
|
419
|
+
Create bucket if not exists
|
|
420
|
+
|
|
421
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
422
|
+
**Returns**: <code>Promise.<boolean></code> - Returns true when bucket exists
|
|
423
|
+
**Throws**:
|
|
424
|
+
|
|
425
|
+
- <code>Error</code> If bucket creation fails
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
| Param | Type | Description |
|
|
429
|
+
| --- | --- | --- |
|
|
430
|
+
| bucketName | <code>string</code> | Bucket name to ensure |
|
|
431
|
+
|
|
432
|
+
**Example**
|
|
433
|
+
```js
|
|
434
|
+
await storage.ensureBucket('new-bucket');
|
|
435
|
+
```
|
|
436
|
+
<a name="module_@onlineapps/conn-base-storage..validateBucketName"></a>
|
|
437
|
+
|
|
438
|
+
### @onlineapps/conn-base-storage~validateBucketName(name) ⇒ <code>string</code>
|
|
439
|
+
Validate bucket name according to S3 standards
|
|
440
|
+
|
|
441
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
442
|
+
**Returns**: <code>string</code> - Valid bucket name or default
|
|
443
|
+
|
|
444
|
+
| Param | Type | Description |
|
|
445
|
+
| --- | --- | --- |
|
|
446
|
+
| name | <code>string</code> | Bucket name to validate |
|
|
447
|
+
|
|
448
|
+
**Example**
|
|
449
|
+
```js
|
|
450
|
+
const validName = storage.validateBucketName('My-Bucket');
|
|
451
|
+
// Returns: 'oa-drive-storage' (invalid characters)
|
|
452
|
+
```
|
|
453
|
+
<a name="module_@onlineapps/conn-base-storage..getObjectNameWithFingerprint"></a>
|
|
454
|
+
|
|
455
|
+
### @onlineapps/conn-base-storage~getObjectNameWithFingerprint(originalName, fingerprint) ⇒ <code>string</code>
|
|
456
|
+
Get object name with fingerprint appended
|
|
457
|
+
|
|
458
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
459
|
+
**Returns**: <code>string</code> - Name with fingerprint
|
|
460
|
+
|
|
461
|
+
| Param | Type | Description |
|
|
462
|
+
| --- | --- | --- |
|
|
463
|
+
| originalName | <code>string</code> | Original file name |
|
|
464
|
+
| fingerprint | <code>string</code> | SHA256 fingerprint |
|
|
465
|
+
|
|
466
|
+
**Example**
|
|
467
|
+
```js
|
|
468
|
+
const name = storage.getObjectNameWithFingerprint('document.pdf', 'abc123...');
|
|
469
|
+
// Returns: 'document-abc123...pdf'
|
|
470
|
+
```
|
|
471
|
+
<a name="module_@onlineapps/conn-base-storage..extractFingerprintFromName"></a>
|
|
472
|
+
|
|
473
|
+
### @onlineapps/conn-base-storage~extractFingerprintFromName(objectName) ⇒ <code>string</code> \| <code>null</code>
|
|
474
|
+
Extract fingerprint from object name
|
|
475
|
+
|
|
476
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
477
|
+
**Returns**: <code>string</code> \| <code>null</code> - Extracted fingerprint or null
|
|
478
|
+
|
|
479
|
+
| Param | Type | Description |
|
|
480
|
+
| --- | --- | --- |
|
|
481
|
+
| objectName | <code>string</code> | Object name with fingerprint |
|
|
482
|
+
|
|
483
|
+
**Example**
|
|
484
|
+
```js
|
|
485
|
+
const fp = storage.extractFingerprintFromName('document-abc123def456.pdf');
|
|
486
|
+
// Returns: 'abc123def456' if valid format
|
|
487
|
+
```
|
|
488
|
+
<a name="module_@onlineapps/conn-base-storage..clearCache"></a>
|
|
489
|
+
|
|
490
|
+
### @onlineapps/conn-base-storage~clearCache() ⇒ <code>void</code>
|
|
491
|
+
Clear all caches
|
|
492
|
+
|
|
493
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
494
|
+
**Example**
|
|
495
|
+
```js
|
|
496
|
+
storage.clearCache();
|
|
497
|
+
// All cached content cleared
|
|
498
|
+
```
|
|
499
|
+
<a name="module_@onlineapps/conn-base-storage..getInternalUrl"></a>
|
|
500
|
+
|
|
501
|
+
### @onlineapps/conn-base-storage~getInternalUrl(bucket, path) ⇒ <code>string</code>
|
|
502
|
+
Get internal URL for service-to-service communication
|
|
503
|
+
|
|
504
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
505
|
+
**Returns**: <code>string</code> - Internal URL with internal:// protocol
|
|
506
|
+
|
|
507
|
+
| Param | Type | Description |
|
|
508
|
+
| --- | --- | --- |
|
|
509
|
+
| bucket | <code>string</code> | Bucket name |
|
|
510
|
+
| path | <code>string</code> | Object path |
|
|
511
|
+
|
|
512
|
+
**Example**
|
|
513
|
+
```js
|
|
514
|
+
const url = storage.getInternalUrl('invoices', 'invoice-123.json');
|
|
515
|
+
// Returns: 'internal://storage/invoices/invoice-123.json'
|
|
516
|
+
```
|
|
517
|
+
<a name="module_@onlineapps/conn-base-storage..getPublicUrl"></a>
|
|
518
|
+
|
|
519
|
+
### ~~@onlineapps/conn-base-storage~getPublicUrl(bucket, path) ⇒ <code>string</code>~~
|
|
520
|
+
***Use getInternalUrl() for service-to-service communication***
|
|
521
|
+
|
|
522
|
+
Get public URL for an object
|
|
523
|
+
|
|
524
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
525
|
+
**Returns**: <code>string</code> - Internal URL for backward compatibility
|
|
526
|
+
|
|
527
|
+
| Param | Type | Description |
|
|
528
|
+
| --- | --- | --- |
|
|
529
|
+
| bucket | <code>string</code> | Bucket name |
|
|
530
|
+
| path | <code>string</code> | Object path |
|
|
531
|
+
|
|
532
|
+
<a name="module_@onlineapps/conn-base-storage..getPresignedUrl"></a>
|
|
533
|
+
|
|
534
|
+
### @onlineapps/conn-base-storage~getPresignedUrl(bucket, objectName, [expiry]) ⇒ <code>Promise.<string></code>
|
|
535
|
+
Get presigned URL for temporary access
|
|
536
|
+
|
|
537
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
538
|
+
**Returns**: <code>Promise.<string></code> - Pre-signed URL
|
|
539
|
+
**Throws**:
|
|
540
|
+
|
|
541
|
+
- <code>Error</code> If URL generation fails
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
| Param | Type | Default | Description |
|
|
545
|
+
| --- | --- | --- | --- |
|
|
546
|
+
| bucket | <code>string</code> | | Bucket name |
|
|
547
|
+
| objectName | <code>string</code> | | Object name |
|
|
548
|
+
| [expiry] | <code>number</code> | <code>86400</code> | URL expiry in seconds (default 24 hours) |
|
|
549
|
+
|
|
550
|
+
**Example**
|
|
551
|
+
```js
|
|
552
|
+
const url = await storage.getPresignedUrl('documents', 'contract.pdf', 3600);
|
|
553
|
+
```
|
|
554
|
+
<a name="module_@onlineapps/conn-base-storage..listObjectsWithFingerprints"></a>
|
|
555
|
+
|
|
556
|
+
### @onlineapps/conn-base-storage~listObjectsWithFingerprints(bucket, [prefix]) ⇒ <code>Promise.<Array.<Object>></code>
|
|
557
|
+
List objects with extracted fingerprints
|
|
558
|
+
|
|
559
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
560
|
+
**Returns**: <code>Promise.<Array.<Object>></code> - List of objects with fingerprints
|
|
561
|
+
|
|
562
|
+
| Param | Type | Default | Description |
|
|
563
|
+
| --- | --- | --- | --- |
|
|
564
|
+
| bucket | <code>string</code> | | Bucket name |
|
|
565
|
+
| [prefix] | <code>string</code> | <code>"''"</code> | Path prefix to filter |
|
|
566
|
+
|
|
567
|
+
**Example**
|
|
568
|
+
```js
|
|
569
|
+
const objects = await storage.listObjectsWithFingerprints('invoices', '2024/');
|
|
570
|
+
```
|
|
571
|
+
<a name="module_@onlineapps/conn-base-storage..create"></a>
|
|
572
|
+
|
|
573
|
+
### @onlineapps/conn-base-storage~create(config) ⇒ <code>StorageConnector</code>
|
|
574
|
+
Factory function to create storage instance
|
|
575
|
+
|
|
576
|
+
**Kind**: inner method of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
577
|
+
**Returns**: <code>StorageConnector</code> - New storage connector instance
|
|
578
|
+
|
|
579
|
+
| Param | Type | Description |
|
|
580
|
+
| --- | --- | --- |
|
|
581
|
+
| config | <code>Object</code> | Configuration object |
|
|
582
|
+
|
|
583
|
+
**Example**
|
|
584
|
+
```js
|
|
585
|
+
const storage = StorageConnector.create({
|
|
586
|
+
endPoint: 'minio.example.com',
|
|
587
|
+
accessKey: 'key',
|
|
588
|
+
secretKey: 'secret'
|
|
589
|
+
});
|
|
590
|
+
```
|
|
591
|
+
<a name="module_@onlineapps/conn-base-storage..UploadResult"></a>
|
|
592
|
+
|
|
593
|
+
### @onlineapps/conn-base-storage~UploadResult : <code>Object</code>
|
|
594
|
+
**Kind**: inner typedef of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
595
|
+
**Properties**
|
|
596
|
+
|
|
597
|
+
| Name | Type | Description |
|
|
598
|
+
| --- | --- | --- |
|
|
599
|
+
| fingerprint | <code>string</code> | SHA256 fingerprint of content |
|
|
600
|
+
| bucket | <code>string</code> | Bucket name |
|
|
601
|
+
| path | <code>string</code> | Storage path |
|
|
602
|
+
| url | <code>string</code> | Public or internal URL |
|
|
603
|
+
| existed | <code>boolean</code> | Whether object already existed |
|
|
604
|
+
|
|
605
|
+
<a name="module_@onlineapps/conn-base-storage..ObjectInfo"></a>
|
|
606
|
+
|
|
607
|
+
### @onlineapps/conn-base-storage~ObjectInfo : <code>Object</code>
|
|
608
|
+
**Kind**: inner typedef of [<code>@onlineapps/conn-base-storage</code>](#module_@onlineapps/conn-base-storage)
|
|
609
|
+
**Properties**
|
|
610
|
+
|
|
611
|
+
| Name | Type | Description |
|
|
612
|
+
| --- | --- | --- |
|
|
613
|
+
| name | <code>string</code> | Object name |
|
|
614
|
+
| size | <code>number</code> | Object size in bytes |
|
|
615
|
+
| lastModified | <code>Date</code> | Last modification date |
|
|
616
|
+
| [fingerprint] | <code>string</code> | SHA256 fingerprint if available |
|
|
617
|
+
| [uploadedAt] | <code>string</code> | Upload timestamp |
|
|
618
|
+
|