@geekmidas/storage 0.0.4 → 0.1.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/README.md +71 -1
- package/dist/{AmazonStorageClient-DT9DeKVz.cjs → AmazonStorageClient-BKzXhCX0.cjs} +40 -10
- package/dist/AmazonStorageClient-BKzXhCX0.cjs.map +1 -0
- package/dist/{AmazonStorageClient-DJMWn8vO.mjs → AmazonStorageClient-CwUey48q.mjs} +15 -7
- package/dist/AmazonStorageClient-CwUey48q.mjs.map +1 -0
- package/dist/{AmazonStorageClient-C16fG3G4.d.cts → AmazonStorageClient-Gz0Fh1sy.d.mts} +7 -3
- package/dist/{AmazonStorageClient-CP8Tx5oE.d.mts → AmazonStorageClient-aduVU3_p.d.cts} +7 -3
- package/dist/AmazonStorageClient.cjs +1 -1
- package/dist/AmazonStorageClient.d.cts +2 -2
- package/dist/AmazonStorageClient.d.mts +2 -2
- package/dist/AmazonStorageClient.mjs +2 -2
- package/dist/{StorageClient-CZGIC_fz.mjs → StorageClient-4ADnTPnJ.mjs} +2 -1
- package/dist/StorageClient-4ADnTPnJ.mjs.map +1 -0
- package/dist/StorageClient-BDRVrMJj.cjs +2 -1
- package/dist/StorageClient-BDRVrMJj.cjs.map +1 -0
- package/dist/{StorageClient-D-y4QLDq.d.cts → StorageClient-CcOAW3YV.d.cts} +5 -1
- package/dist/{StorageClient-CJbHRTVV.d.mts → StorageClient-XgMsiUrd.d.mts} +5 -1
- package/dist/StorageClient.d.cts +1 -1
- package/dist/StorageClient.d.mts +1 -1
- package/dist/StorageClient.mjs +1 -1
- package/dist/aws.cjs +1 -1
- package/dist/aws.d.cts +2 -2
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/package.json +28 -3
- package/src/AmazonStorageClient.ts +22 -3
- package/src/StorageClient.ts +2 -0
- package/src/__tests__/AmazonStorageClient.spec.ts +183 -0
- package/dist/__tests__/AmazonStorageClient.spec.cjs +0 -234
- package/dist/__tests__/AmazonStorageClient.spec.d.cts +0 -1
- package/dist/__tests__/AmazonStorageClient.spec.d.mts +0 -1
- package/dist/__tests__/AmazonStorageClient.spec.mjs +0 -233
- package/dist/__tests__/StorageClient.spec.cjs +0 -81
- package/dist/__tests__/StorageClient.spec.d.cts +0 -1
- package/dist/__tests__/StorageClient.spec.d.mts +0 -1
- package/dist/__tests__/StorageClient.spec.mjs +0 -81
- package/dist/chunk-DWy1uDak.cjs +0 -39
- package/dist/magic-string.es-BvJNBYzY.mjs +0 -1014
- package/dist/magic-string.es-CKiDiYoS.cjs +0 -1015
- package/dist/vi.bdSIJ99Y-CucmVasy.mjs +0 -14928
- package/dist/vi.bdSIJ99Y-D0m6qImj.cjs +0 -14926
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A comprehensive, type-safe storage client for cloud storage services with suppor
|
|
|
11
11
|
- **Direct uploads**: Upload files directly to storage without intermediate servers
|
|
12
12
|
- **Flexible configuration**: Support for custom endpoints (useful for MinIO, LocalStack, etc.)
|
|
13
13
|
- **Modern async/await API**: Promise-based interface throughout
|
|
14
|
+
- **URL caching**: Built-in support for caching presigned URLs to reduce API calls and improve performance
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -32,6 +33,7 @@ npm install @aws-sdk/client-s3 @aws-sdk/s3-presigned-post @aws-sdk/s3-request-pr
|
|
|
32
33
|
|
|
33
34
|
```typescript
|
|
34
35
|
import { AmazonStorageClient } from '@geekmidas/storage/aws';
|
|
36
|
+
import { InMemoryCache } from '@geekmidas/cache/memory';
|
|
35
37
|
|
|
36
38
|
// Create client with credentials
|
|
37
39
|
const storage = AmazonStorageClient.create({
|
|
@@ -41,6 +43,16 @@ const storage = AmazonStorageClient.create({
|
|
|
41
43
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
42
44
|
});
|
|
43
45
|
|
|
46
|
+
// Create client with caching enabled
|
|
47
|
+
const cache = new InMemoryCache<string>();
|
|
48
|
+
const storageWithCache = AmazonStorageClient.create({
|
|
49
|
+
bucket: 'my-bucket',
|
|
50
|
+
region: 'us-east-1',
|
|
51
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
52
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
53
|
+
cache,
|
|
54
|
+
});
|
|
55
|
+
|
|
44
56
|
// Upload a file directly
|
|
45
57
|
await storage.upload('documents/readme.txt', 'Hello, World!', 'text/plain');
|
|
46
58
|
|
|
@@ -82,6 +94,7 @@ The core interface that all storage providers implement:
|
|
|
82
94
|
```typescript
|
|
83
95
|
interface StorageClient {
|
|
84
96
|
readonly provider: StorageProvider;
|
|
97
|
+
readonly cache?: Cache<string>;
|
|
85
98
|
|
|
86
99
|
// Direct upload
|
|
87
100
|
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
@@ -114,6 +127,8 @@ AmazonStorageClient.create(options: AmazonStorageClientCreateOptions)
|
|
|
114
127
|
- `secretAccessKey`: AWS secret access key
|
|
115
128
|
- `endpoint`: Custom S3 endpoint (useful for MinIO, LocalStack)
|
|
116
129
|
- `acl`: Canned ACL for uploads (default: `authenticated-read`)
|
|
130
|
+
- `cache`: Optional cache implementation for storing presigned URLs
|
|
131
|
+
- `forcePathStyle`: Force path-style URLs (useful for MinIO)
|
|
117
132
|
|
|
118
133
|
#### Methods
|
|
119
134
|
|
|
@@ -132,7 +147,7 @@ await storage.upload('files/binary.dat', buffer, 'application/octet-stream');
|
|
|
132
147
|
|
|
133
148
|
##### `getDownloadURL(file: File, expiresIn?: number): Promise<string>`
|
|
134
149
|
|
|
135
|
-
Generate a presigned download URL.
|
|
150
|
+
Generate a presigned download URL. When a cache is configured, URLs will be cached based on the file path.
|
|
136
151
|
|
|
137
152
|
```typescript
|
|
138
153
|
// Simple download URL
|
|
@@ -148,6 +163,12 @@ const url = await storage.getDownloadURL({
|
|
|
148
163
|
const url = await storage.getDownloadURL({ path: 'documents/file.pdf' }, 3600);
|
|
149
164
|
```
|
|
150
165
|
|
|
166
|
+
**Caching behavior:**
|
|
167
|
+
- URLs are cached with key format: `download-url:{file.path}`
|
|
168
|
+
- Cache TTL is set to `expiresIn - 60` seconds (with 1 minute buffer)
|
|
169
|
+
- URLs with expiration < 60 seconds are not cached
|
|
170
|
+
- Cached URLs are returned immediately without generating new presigned URLs
|
|
171
|
+
|
|
151
172
|
##### `getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>`
|
|
152
173
|
|
|
153
174
|
Generate a presigned PUT upload URL.
|
|
@@ -257,6 +278,7 @@ enum StorageProvider {
|
|
|
257
278
|
```typescript
|
|
258
279
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
259
280
|
import { AmazonStorageClient, AmazonCannedAccessControlList } from '@geekmidas/storage/aws';
|
|
281
|
+
import { InMemoryCache } from '@geekmidas/cache/memory';
|
|
260
282
|
|
|
261
283
|
const s3Client = new S3Client({
|
|
262
284
|
region: 'us-east-1',
|
|
@@ -266,11 +288,21 @@ const s3Client = new S3Client({
|
|
|
266
288
|
},
|
|
267
289
|
});
|
|
268
290
|
|
|
291
|
+
// Without cache
|
|
269
292
|
const storage = new AmazonStorageClient(
|
|
270
293
|
s3Client,
|
|
271
294
|
'my-bucket',
|
|
272
295
|
AmazonCannedAccessControlList.PublicRead
|
|
273
296
|
);
|
|
297
|
+
|
|
298
|
+
// With cache
|
|
299
|
+
const cache = new InMemoryCache<string>();
|
|
300
|
+
const storageWithCache = new AmazonStorageClient(
|
|
301
|
+
s3Client,
|
|
302
|
+
'my-bucket',
|
|
303
|
+
AmazonCannedAccessControlList.PublicRead,
|
|
304
|
+
cache
|
|
305
|
+
);
|
|
274
306
|
```
|
|
275
307
|
|
|
276
308
|
### Access Control Lists (ACLs)
|
|
@@ -294,6 +326,44 @@ Available ACLs:
|
|
|
294
326
|
- `LogDeliveryWrite` - Log delivery service gets write access
|
|
295
327
|
- `AwsExecRead` - Amazon EC2 gets read access for AMI bundles
|
|
296
328
|
|
|
329
|
+
### Caching
|
|
330
|
+
|
|
331
|
+
Caching presigned URLs can significantly reduce the number of API calls to AWS S3 and improve performance.
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
import { AmazonStorageClient } from '@geekmidas/storage/aws';
|
|
335
|
+
import { InMemoryCache } from '@geekmidas/cache/memory';
|
|
336
|
+
import { UpstashCache } from '@geekmidas/cache/upstash';
|
|
337
|
+
|
|
338
|
+
// In-memory cache for development/testing
|
|
339
|
+
const memoryCache = new InMemoryCache<string>();
|
|
340
|
+
const storage = AmazonStorageClient.create({
|
|
341
|
+
bucket: 'my-bucket',
|
|
342
|
+
cache: memoryCache,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Redis cache for production
|
|
346
|
+
const redisCache = new UpstashCache<string>({
|
|
347
|
+
url: process.env.UPSTASH_REDIS_URL,
|
|
348
|
+
token: process.env.UPSTASH_REDIS_TOKEN,
|
|
349
|
+
});
|
|
350
|
+
const productionStorage = AmazonStorageClient.create({
|
|
351
|
+
bucket: 'my-bucket',
|
|
352
|
+
cache: redisCache,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// Cache behavior example
|
|
356
|
+
const url1 = await storage.getDownloadURL({ path: 'file.pdf' }); // Generates new URL
|
|
357
|
+
const url2 = await storage.getDownloadURL({ path: 'file.pdf' }); // Returns cached URL
|
|
358
|
+
console.log(url1 === url2); // true
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Cache keys and TTL:**
|
|
362
|
+
- Download URLs are cached with key: `download-url:{path}`
|
|
363
|
+
- Cache TTL is automatically calculated as `expiresIn - 60` seconds
|
|
364
|
+
- URLs expiring in less than 60 seconds are not cached
|
|
365
|
+
- Upload URLs are not cached (they are typically single-use)
|
|
366
|
+
|
|
297
367
|
### Error Handling
|
|
298
368
|
|
|
299
369
|
```typescript
|
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
2
24
|
const require_StorageClient = require('./StorageClient-BDRVrMJj.cjs');
|
|
3
|
-
const __aws_sdk_client_s3 =
|
|
4
|
-
const __aws_sdk_s3_presigned_post =
|
|
5
|
-
const __aws_sdk_s3_request_presigner =
|
|
25
|
+
const __aws_sdk_client_s3 = __toESM(require("@aws-sdk/client-s3"));
|
|
26
|
+
const __aws_sdk_s3_presigned_post = __toESM(require("@aws-sdk/s3-presigned-post"));
|
|
27
|
+
const __aws_sdk_s3_request_presigner = __toESM(require("@aws-sdk/s3-request-presigner"));
|
|
6
28
|
|
|
7
29
|
//#region src/AmazonStorageClient.ts
|
|
8
30
|
var AmazonStorageClient = class AmazonStorageClient {
|
|
9
31
|
provider = require_StorageClient.StorageProvider.AWSS3;
|
|
10
32
|
static create(options) {
|
|
11
|
-
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false } = options;
|
|
33
|
+
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
|
|
12
34
|
const hasCredentials = accessKeyId && secretAccessKey;
|
|
13
35
|
const credentials = hasCredentials ? {
|
|
14
36
|
accessKeyId,
|
|
@@ -20,12 +42,13 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
20
42
|
endpoint,
|
|
21
43
|
forcePathStyle
|
|
22
44
|
});
|
|
23
|
-
return new AmazonStorageClient(client, bucket, acl);
|
|
45
|
+
return new AmazonStorageClient(client, bucket, acl, cache);
|
|
24
46
|
}
|
|
25
|
-
constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead) {
|
|
47
|
+
constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead, cache) {
|
|
26
48
|
this.client = client;
|
|
27
49
|
this.bucket = bucket;
|
|
28
50
|
this.acl = acl;
|
|
51
|
+
this.cache = cache;
|
|
29
52
|
}
|
|
30
53
|
getVersionDownloadURL(file, versionId) {
|
|
31
54
|
const ResponseContentDisposition = file.name ? `attachment; filename=${encodeURIComponent(file.name)}` : void 0;
|
|
@@ -48,14 +71,20 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
48
71
|
createdAt: version.LastModified || /* @__PURE__ */ new Date()
|
|
49
72
|
}));
|
|
50
73
|
}
|
|
51
|
-
getDownloadURL(file, expiresIn = 60 * 60) {
|
|
74
|
+
async getDownloadURL(file, expiresIn = 60 * 60) {
|
|
75
|
+
const cacheKey = `download-url:${file.path}`;
|
|
76
|
+
const cachedURL = await this.cache?.get(cacheKey);
|
|
77
|
+
if (cachedURL) return cachedURL;
|
|
52
78
|
const ResponseContentDisposition = file.name ? `attachment; filename=${encodeURIComponent(file.name)}` : void 0;
|
|
53
79
|
const command = new __aws_sdk_client_s3.GetObjectCommand({
|
|
54
80
|
Bucket: this.bucket,
|
|
55
81
|
Key: file.path,
|
|
56
82
|
ResponseContentDisposition
|
|
57
83
|
});
|
|
58
|
-
|
|
84
|
+
const url = await (0, __aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn });
|
|
85
|
+
const cacheExpiration = Math.max(expiresIn - 60, 0);
|
|
86
|
+
if (cacheExpiration) await this.cache?.set(cacheKey, url, cacheExpiration);
|
|
87
|
+
return url;
|
|
59
88
|
}
|
|
60
89
|
async getUploadURL(params, expiresIn = 60 * 60) {
|
|
61
90
|
const command = new __aws_sdk_client_s3.PutObjectCommand({
|
|
@@ -121,4 +150,5 @@ Object.defineProperty(exports, 'AmazonStorageClient', {
|
|
|
121
150
|
get: function () {
|
|
122
151
|
return AmazonStorageClient;
|
|
123
152
|
}
|
|
124
|
-
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=AmazonStorageClient-BKzXhCX0.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmazonStorageClient-BKzXhCX0.cjs","names":["StorageProvider","options: AmazonStorageClientCreateOptions","S3Client","client: S3Client","bucket: string","cache?: Cache<string>","file: File","versionId: string","GetObjectCommand","key: string","ListObjectVersionsCommand","params: GetUploadParams","PutObjectCommand","data: string | Buffer","contentType: string"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n GetObjectCommand,\n ListObjectVersionsCommand,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { createPresignedPost } from '@aws-sdk/s3-presigned-post';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\n\nimport type { Cache } from '@geekmidas/cache';\nimport {\n type DocumentVersion,\n type File,\n type GetUploadParams,\n type GetUploadResponse,\n type StorageClient,\n StorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n readonly provider = StorageProvider.AWSS3;\n\n static create(\n options: AmazonStorageClientCreateOptions,\n ): AmazonStorageClient {\n const {\n bucket,\n region,\n accessKeyId,\n acl,\n endpoint,\n secretAccessKey,\n forcePathStyle = false,\n cache,\n } = options;\n const hasCredentials = accessKeyId && secretAccessKey;\n const credentials = hasCredentials\n ? { accessKeyId, secretAccessKey }\n : undefined;\n\n const client = new S3Client({\n region,\n credentials,\n endpoint,\n forcePathStyle,\n });\n\n return new AmazonStorageClient(client, bucket, acl, cache);\n }\n constructor(\n private readonly client: S3Client,\n private readonly bucket: string,\n private readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n readonly cache?: Cache<string>,\n ) {}\n\n getVersionDownloadURL(file: File, versionId: string): Promise<string> {\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n VersionId: versionId,\n });\n\n return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n }\n\n async getVersions(key: string): Promise<DocumentVersion[]> {\n const command = new ListObjectVersionsCommand({\n Bucket: this.bucket,\n Prefix: key,\n });\n\n const { Versions = [] } = await this.client.send(command);\n\n return Versions.map((version) => ({\n id: version.VersionId || '',\n createdAt: version.LastModified || new Date(),\n }));\n }\n\n async getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n const cacheKey = `download-url:${file.path}`;\n const cachedURL = await this.cache?.get(cacheKey);\n\n if (cachedURL) {\n return cachedURL;\n }\n\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n });\n\n const url = await getSignedUrl(this.client, command, { expiresIn });\n const cacheExpiration = Math.max(expiresIn - 60, 0);\n\n if (cacheExpiration) {\n await this.cache?.set(cacheKey, url, cacheExpiration);\n }\n\n return url;\n }\n\n async getUploadURL(\n params: GetUploadParams,\n expiresIn = 60 * 60,\n ): Promise<string> {\n const command = new PutObjectCommand({\n Bucket: this.bucket,\n Key: params.path,\n ContentType: params.contentType,\n ContentLength: params.contentLength,\n });\n\n return getSignedUrl(this.client, command, { expiresIn });\n }\n\n async getUpload(\n params: GetUploadParams,\n expiresIn = 5,\n ): Promise<GetUploadResponse> {\n const { path } = params;\n const { fields: values, url } = await createPresignedPost(this.client, {\n Expires: expiresIn * 60,\n Bucket: this.bucket,\n Fields: {\n acl: this.acl,\n },\n Conditions: [\n // content length restrictions: 0-1MB]\n // ['content-length-range', 0, contentLength],\n // specify content-type to be more generic- images only\n // ['starts-with', '$Content-Type', 'image/'],\n // ['starts-with', '$Content-Type', contentType],\n ],\n Key: path,\n });\n\n const keys = Object.keys(values);\n const fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n return { url, fields };\n }\n\n async upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void> {\n const Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n const params = {\n Bucket: this.bucket,\n Key: key,\n Body,\n ContentType: contentType,\n };\n\n const command = new PutObjectCommand(params);\n\n await this.client.send(command);\n }\n}\n\nexport enum AmazonCannedAccessControlList {\n AuthenticatedRead = 'authenticated-read',\n Private = 'private',\n PublicRead = 'public-read',\n PublicReadWrite = 'public-read-write',\n AwsExecRead = 'aws-exec-read',\n BucketOwnerRead = 'bucket-owner-read',\n BucketOwnerFullControl = 'bucket-owner-full-control',\n LogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n bucket: string;\n region?: string;\n acl?: AmazonCannedAccessControlList;\n accessKeyId?: string;\n secretAccessKey?: string;\n endpoint?: string;\n forcePathStyle?: boolean;\n cache?: Cache<string>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,sBAAb,MAAa,oBAA6C;CACxD,AAAS,WAAWA,sCAAgB;CAEpC,OAAO,OACLC,SACqB;EACrB,MAAM,EACJ,QACA,QACA,a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E,MAAM,kBAAkB,KAAK,IAAI,YAAY,IAAI,EAAE;AAEnD,MAAI,gBACF,OAAM,KAAK,OAAO,IAAI,UAAU,KAAK,gBAAgB;AAGvD,SAAO;CACR;CAED,MAAM,aACJG,QACA,YAAY,KAAK,IACA;EACjB,MAAM,UAAU,IAAIC,qCAAiB;GACnC,QAAQ,KAAK;GACb,KAAK,OAAO;GACZ,aAAa,OAAO;GACpB,eAAe,OAAO;EACvB;AAED,SAAO,iDAAa,KAAK,QAAQ,SAAS,EAAE,UAAW,EAAC;CACzD;CAED,MAAM,UACJD,QACA,YAAY,GACgB;EAC5B,MAAM,EAAE,MAAM,GAAG;EACjB,MAAM,EAAE,QAAQ,QAAQ,KAAK,GAAG,MAAM,qDAAoB,KAAK,QAAQ;GACrE,SAAS,YAAY;GACrB,QAAQ,KAAK;GACb,QAAQ,EACN,KAAK,KAAK,IACX;GACD,YAAY,CAMX;GACD,KAAK;EACN,EAAC;EAEF,MAAM,OAAO,OAAO,KAAK,OAAO;EAChC,MAAM,SAAS,KAAK,IAAI,CAAC,SAAS;GAAE;GAAK,OAAO,OAAO,QAAQ;EAAI,GAAE;AAErE,SAAO;GAAE;GAAK;EAAQ;CACvB;CAED,MAAM,OACJF,KACAI,MACAC,aACe;EACf,MAAM,cAAc,SAAS,WAAW,OAAO,KAAK,MAAM,SAAS,GAAG;EAEtE,MAAM,SAAS;GACb,QAAQ,KAAK;GACb,KAAK;GACL;GACA,aAAa;EACd;EAED,MAAM,UAAU,IAAIF,qCAAiB;AAErC,QAAM,KAAK,OAAO,KAAK,QAAQ;CAChC;AACF;AAED,IAAY,0FAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StorageProvider } from "./StorageClient-
|
|
1
|
+
import { StorageProvider } from "./StorageClient-4ADnTPnJ.mjs";
|
|
2
2
|
import { GetObjectCommand, ListObjectVersionsCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
3
3
|
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
|
|
4
4
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
@@ -7,7 +7,7 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
|
7
7
|
var AmazonStorageClient = class AmazonStorageClient {
|
|
8
8
|
provider = StorageProvider.AWSS3;
|
|
9
9
|
static create(options) {
|
|
10
|
-
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false } = options;
|
|
10
|
+
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
|
|
11
11
|
const hasCredentials = accessKeyId && secretAccessKey;
|
|
12
12
|
const credentials = hasCredentials ? {
|
|
13
13
|
accessKeyId,
|
|
@@ -19,12 +19,13 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
19
19
|
endpoint,
|
|
20
20
|
forcePathStyle
|
|
21
21
|
});
|
|
22
|
-
return new AmazonStorageClient(client, bucket, acl);
|
|
22
|
+
return new AmazonStorageClient(client, bucket, acl, cache);
|
|
23
23
|
}
|
|
24
|
-
constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead) {
|
|
24
|
+
constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead, cache) {
|
|
25
25
|
this.client = client;
|
|
26
26
|
this.bucket = bucket;
|
|
27
27
|
this.acl = acl;
|
|
28
|
+
this.cache = cache;
|
|
28
29
|
}
|
|
29
30
|
getVersionDownloadURL(file, versionId) {
|
|
30
31
|
const ResponseContentDisposition = file.name ? `attachment; filename=${encodeURIComponent(file.name)}` : void 0;
|
|
@@ -47,14 +48,20 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
47
48
|
createdAt: version.LastModified || /* @__PURE__ */ new Date()
|
|
48
49
|
}));
|
|
49
50
|
}
|
|
50
|
-
getDownloadURL(file, expiresIn = 60 * 60) {
|
|
51
|
+
async getDownloadURL(file, expiresIn = 60 * 60) {
|
|
52
|
+
const cacheKey = `download-url:${file.path}`;
|
|
53
|
+
const cachedURL = await this.cache?.get(cacheKey);
|
|
54
|
+
if (cachedURL) return cachedURL;
|
|
51
55
|
const ResponseContentDisposition = file.name ? `attachment; filename=${encodeURIComponent(file.name)}` : void 0;
|
|
52
56
|
const command = new GetObjectCommand({
|
|
53
57
|
Bucket: this.bucket,
|
|
54
58
|
Key: file.path,
|
|
55
59
|
ResponseContentDisposition
|
|
56
60
|
});
|
|
57
|
-
|
|
61
|
+
const url = await getSignedUrl(this.client, command, { expiresIn });
|
|
62
|
+
const cacheExpiration = Math.max(expiresIn - 60, 0);
|
|
63
|
+
if (cacheExpiration) await this.cache?.set(cacheKey, url, cacheExpiration);
|
|
64
|
+
return url;
|
|
58
65
|
}
|
|
59
66
|
async getUploadURL(params, expiresIn = 60 * 60) {
|
|
60
67
|
const command = new PutObjectCommand({
|
|
@@ -109,4 +116,5 @@ let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessC
|
|
|
109
116
|
}({});
|
|
110
117
|
|
|
111
118
|
//#endregion
|
|
112
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
119
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
120
|
+
//# sourceMappingURL=AmazonStorageClient-CwUey48q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmazonStorageClient-CwUey48q.mjs","names":["options: AmazonStorageClientCreateOptions","client: S3Client","bucket: string","cache?: Cache<string>","file: File","versionId: string","key: string","params: GetUploadParams","data: string | Buffer","contentType: string"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n GetObjectCommand,\n ListObjectVersionsCommand,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { createPresignedPost } from '@aws-sdk/s3-presigned-post';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\n\nimport type { Cache } from '@geekmidas/cache';\nimport {\n type DocumentVersion,\n type File,\n type GetUploadParams,\n type GetUploadResponse,\n type StorageClient,\n StorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n readonly provider = StorageProvider.AWSS3;\n\n static create(\n options: AmazonStorageClientCreateOptions,\n ): AmazonStorageClient {\n const {\n bucket,\n region,\n accessKeyId,\n acl,\n endpoint,\n secretAccessKey,\n forcePathStyle = false,\n cache,\n } = options;\n const hasCredentials = accessKeyId && secretAccessKey;\n const credentials = hasCredentials\n ? { accessKeyId, secretAccessKey }\n : undefined;\n\n const client = new S3Client({\n region,\n credentials,\n endpoint,\n forcePathStyle,\n });\n\n return new AmazonStorageClient(client, bucket, acl, cache);\n }\n constructor(\n private readonly client: S3Client,\n private readonly bucket: string,\n private readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n readonly cache?: Cache<string>,\n ) {}\n\n getVersionDownloadURL(file: File, versionId: string): Promise<string> {\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n VersionId: versionId,\n });\n\n return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n }\n\n async getVersions(key: string): Promise<DocumentVersion[]> {\n const command = new ListObjectVersionsCommand({\n Bucket: this.bucket,\n Prefix: key,\n });\n\n const { Versions = [] } = await this.client.send(command);\n\n return Versions.map((version) => ({\n id: version.VersionId || '',\n createdAt: version.LastModified || new Date(),\n }));\n }\n\n async getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n const cacheKey = `download-url:${file.path}`;\n const cachedURL = await this.cache?.get(cacheKey);\n\n if (cachedURL) {\n return cachedURL;\n }\n\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n });\n\n const url = await getSignedUrl(this.client, command, { expiresIn });\n const cacheExpiration = Math.max(expiresIn - 60, 0);\n\n if (cacheExpiration) {\n await this.cache?.set(cacheKey, url, cacheExpiration);\n }\n\n return url;\n }\n\n async getUploadURL(\n params: GetUploadParams,\n expiresIn = 60 * 60,\n ): Promise<string> {\n const command = new PutObjectCommand({\n Bucket: this.bucket,\n Key: params.path,\n ContentType: params.contentType,\n ContentLength: params.contentLength,\n });\n\n return getSignedUrl(this.client, command, { expiresIn });\n }\n\n async getUpload(\n params: GetUploadParams,\n expiresIn = 5,\n ): Promise<GetUploadResponse> {\n const { path } = params;\n const { fields: values, url } = await createPresignedPost(this.client, {\n Expires: expiresIn * 60,\n Bucket: this.bucket,\n Fields: {\n acl: this.acl,\n },\n Conditions: [\n // content length restrictions: 0-1MB]\n // ['content-length-range', 0, contentLength],\n // specify content-type to be more generic- images only\n // ['starts-with', '$Content-Type', 'image/'],\n // ['starts-with', '$Content-Type', contentType],\n ],\n Key: path,\n });\n\n const keys = Object.keys(values);\n const fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n return { url, fields };\n }\n\n async upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void> {\n const Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n const params = {\n Bucket: this.bucket,\n Key: key,\n Body,\n ContentType: contentType,\n };\n\n const command = new PutObjectCommand(params);\n\n await this.client.send(command);\n }\n}\n\nexport enum AmazonCannedAccessControlList {\n AuthenticatedRead = 'authenticated-read',\n Private = 'private',\n PublicRead = 'public-read',\n PublicReadWrite = 'public-read-write',\n AwsExecRead = 'aws-exec-read',\n BucketOwnerRead = 'bucket-owner-read',\n BucketOwnerFullControl = 'bucket-owner-full-control',\n LogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n bucket: string;\n region?: string;\n acl?: AmazonCannedAccessControlList;\n accessKeyId?: string;\n secretAccessKey?: string;\n endpoint?: string;\n forcePathStyle?: boolean;\n cache?: Cache<string>;\n}\n"],"mapp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adResponse, StorageClient, StorageProvider } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
|
+
import { Cache } from "@geekmidas/cache";
|
|
3
4
|
|
|
4
5
|
//#region src/AmazonStorageClient.d.ts
|
|
5
6
|
declare class AmazonStorageClient implements StorageClient {
|
|
6
7
|
private readonly client;
|
|
7
8
|
private readonly bucket;
|
|
8
9
|
private readonly acl;
|
|
10
|
+
readonly cache?: Cache<string>;
|
|
9
11
|
readonly provider = StorageProvider.AWSS3;
|
|
10
12
|
static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
|
|
11
|
-
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList);
|
|
13
|
+
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList, cache?: Cache<string>);
|
|
12
14
|
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
13
15
|
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
14
16
|
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
@@ -34,6 +36,8 @@ interface AmazonStorageClientCreateOptions {
|
|
|
34
36
|
secretAccessKey?: string;
|
|
35
37
|
endpoint?: string;
|
|
36
38
|
forcePathStyle?: boolean;
|
|
39
|
+
cache?: Cache<string>;
|
|
37
40
|
}
|
|
38
41
|
//#endregion
|
|
39
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
42
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
43
|
+
//# sourceMappingURL=AmazonStorageClient-Gz0Fh1sy.d.mts.map
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-CcOAW3YV.cjs";
|
|
2
2
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
|
+
import { Cache } from "@geekmidas/cache";
|
|
3
4
|
|
|
4
5
|
//#region src/AmazonStorageClient.d.ts
|
|
5
6
|
declare class AmazonStorageClient implements StorageClient {
|
|
6
7
|
private readonly client;
|
|
7
8
|
private readonly bucket;
|
|
8
9
|
private readonly acl;
|
|
10
|
+
readonly cache?: Cache<string>;
|
|
9
11
|
readonly provider = StorageProvider.AWSS3;
|
|
10
12
|
static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
|
|
11
|
-
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList);
|
|
13
|
+
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList, cache?: Cache<string>);
|
|
12
14
|
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
13
15
|
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
14
16
|
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
@@ -34,6 +36,8 @@ interface AmazonStorageClientCreateOptions {
|
|
|
34
36
|
secretAccessKey?: string;
|
|
35
37
|
endpoint?: string;
|
|
36
38
|
forcePathStyle?: boolean;
|
|
39
|
+
cache?: Cache<string>;
|
|
37
40
|
}
|
|
38
41
|
//#endregion
|
|
39
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
42
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
43
|
+
//# sourceMappingURL=AmazonStorageClient-aduVU3_p.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
const require_AmazonStorageClient = require('./AmazonStorageClient-BKzXhCX0.cjs');
|
|
1
2
|
require('./StorageClient-BDRVrMJj.cjs');
|
|
2
|
-
const require_AmazonStorageClient = require('./AmazonStorageClient-DT9DeKVz.cjs');
|
|
3
3
|
|
|
4
4
|
exports.AmazonCannedAccessControlList = require_AmazonStorageClient.AmazonCannedAccessControlList;
|
|
5
5
|
exports.AmazonStorageClient = require_AmazonStorageClient.AmazonStorageClient;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-CcOAW3YV.cjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-aduVU3_p.cjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-XgMsiUrd.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-Gz0Fh1sy.mjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-4ADnTPnJ.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-CwUey48q.mjs";
|
|
3
3
|
|
|
4
4
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageClient-4ADnTPnJ.mjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n id: string;\n createdAt: Date;\n}\n\nexport enum StorageProvider {\n AWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n GCP = 'geekimdas.toolbox.storage.gcp',\n AZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n readonly provider: StorageProvider;\n readonly cache?: Cache<string>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the upload URL.\n */\n getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n /**\n * Get a URL to download a file from.\n *\n * @param file - The file to get the download URL for.\n * @param expiresIn - The number of seconds the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the download URL.\n */\n getDownloadURL(file: File, expiresIn?: number): Promise<string>;\n /**\n * Get the versions for a key.\n *\n * @param key - The key to get the versions for.\n */\n getVersions(key: string): Promise<DocumentVersion[]>;\n\n /**\n * Get a URL to download a version of a file from.\n *\n * @param file - The file to get the download URL for.\n * @param versionId - The version ID to get the download URL for.\n */\n getVersionDownloadURL(file: File, versionId: string): Promise<string>;\n /**\n *\n * @param key - The key to upload the file to.\n * @param data - The data to upload.\n * @param contentType - The content type of the data.\n */\n upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n */\n getUpload(\n params: GetUploadParams,\n expiresIn?: number,\n ): Promise<GetUploadResponse>;\n}\n\nexport interface GetUploadParams {\n path: string;\n contentType: string;\n contentLength: number;\n}\n\nexport type UploadField = {\n key: string;\n value: string;\n};\n\nexport type GetUploadResponse = {\n url: string;\n fields: UploadField[];\n};\n\nexport interface File {\n name?: string;\n path: string;\n}\n"],"mappings":";AAMA,IAAY,8DAAL;AACL;AACA;AACA;;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageClient-BDRVrMJj.cjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n id: string;\n createdAt: Date;\n}\n\nexport enum StorageProvider {\n AWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n GCP = 'geekimdas.toolbox.storage.gcp',\n AZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n readonly provider: StorageProvider;\n readonly cache?: Cache<string>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the upload URL.\n */\n getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n /**\n * Get a URL to download a file from.\n *\n * @param file - The file to get the download URL for.\n * @param expiresIn - The number of seconds the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the download URL.\n */\n getDownloadURL(file: File, expiresIn?: number): Promise<string>;\n /**\n * Get the versions for a key.\n *\n * @param key - The key to get the versions for.\n */\n getVersions(key: string): Promise<DocumentVersion[]>;\n\n /**\n * Get a URL to download a version of a file from.\n *\n * @param file - The file to get the download URL for.\n * @param versionId - The version ID to get the download URL for.\n */\n getVersionDownloadURL(file: File, versionId: string): Promise<string>;\n /**\n *\n * @param key - The key to upload the file to.\n * @param data - The data to upload.\n * @param contentType - The content type of the data.\n */\n upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n */\n getUpload(\n params: GetUploadParams,\n expiresIn?: number,\n ): Promise<GetUploadResponse>;\n}\n\nexport interface GetUploadParams {\n path: string;\n contentType: string;\n contentLength: number;\n}\n\nexport type UploadField = {\n key: string;\n value: string;\n};\n\nexport type GetUploadResponse = {\n url: string;\n fields: UploadField[];\n};\n\nexport interface File {\n name?: string;\n path: string;\n}\n"],"mappings":";;AAMA,IAAY,8DAAL;AACL;AACA;AACA;;AACD"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Cache } from "@geekmidas/cache";
|
|
2
|
+
|
|
1
3
|
//#region src/StorageClient.d.ts
|
|
2
4
|
interface DocumentVersion {
|
|
3
5
|
id: string;
|
|
@@ -10,6 +12,7 @@ declare enum StorageProvider {
|
|
|
10
12
|
}
|
|
11
13
|
interface StorageClient {
|
|
12
14
|
readonly provider: StorageProvider;
|
|
15
|
+
readonly cache?: Cache<string>;
|
|
13
16
|
/**
|
|
14
17
|
* Get a URL to upload a file to.
|
|
15
18
|
*
|
|
@@ -74,4 +77,5 @@ interface File {
|
|
|
74
77
|
path: string;
|
|
75
78
|
}
|
|
76
79
|
//#endregion
|
|
77
|
-
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
80
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
81
|
+
//# sourceMappingURL=StorageClient-CcOAW3YV.d.cts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Cache } from "@geekmidas/cache";
|
|
2
|
+
|
|
1
3
|
//#region src/StorageClient.d.ts
|
|
2
4
|
interface DocumentVersion {
|
|
3
5
|
id: string;
|
|
@@ -10,6 +12,7 @@ declare enum StorageProvider {
|
|
|
10
12
|
}
|
|
11
13
|
interface StorageClient {
|
|
12
14
|
readonly provider: StorageProvider;
|
|
15
|
+
readonly cache?: Cache<string>;
|
|
13
16
|
/**
|
|
14
17
|
* Get a URL to upload a file to.
|
|
15
18
|
*
|
|
@@ -74,4 +77,5 @@ interface File {
|
|
|
74
77
|
path: string;
|
|
75
78
|
}
|
|
76
79
|
//#endregion
|
|
77
|
-
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
80
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
81
|
+
//# sourceMappingURL=StorageClient-XgMsiUrd.d.mts.map
|
package/dist/StorageClient.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-CcOAW3YV.cjs";
|
|
2
2
|
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
package/dist/StorageClient.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
package/dist/StorageClient.mjs
CHANGED
package/dist/aws.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
const require_AmazonStorageClient = require('./AmazonStorageClient-BKzXhCX0.cjs');
|
|
1
2
|
require('./StorageClient-BDRVrMJj.cjs');
|
|
2
|
-
const require_AmazonStorageClient = require('./AmazonStorageClient-DT9DeKVz.cjs');
|
|
3
3
|
|
|
4
4
|
exports.AmazonCannedAccessControlList = require_AmazonStorageClient.AmazonCannedAccessControlList;
|
|
5
5
|
exports.AmazonStorageClient = require_AmazonStorageClient.AmazonStorageClient;
|
package/dist/aws.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-CcOAW3YV.cjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-aduVU3_p.cjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient, DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient };
|
package/dist/aws.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-Gz0Fh1sy.mjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient, DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient };
|
package/dist/aws.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-4ADnTPnJ.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-CwUey48q.mjs";
|
|
3
3
|
|
|
4
4
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StorageClient } from "./StorageClient-
|
|
1
|
+
import { StorageClient } from "./StorageClient-CcOAW3YV.cjs";
|
|
2
2
|
export { StorageClient };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StorageClient } from "./StorageClient-
|
|
1
|
+
import { StorageClient } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
export { StorageClient };
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/storage",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/geekmidas/toolbox"
|
|
8
|
+
},
|
|
5
9
|
"publishConfig": {
|
|
6
10
|
"registry": "https://registry.npmjs.org/",
|
|
7
11
|
"access": "public"
|
|
@@ -21,10 +25,31 @@
|
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {},
|
|
23
27
|
"peerDependencies": {
|
|
24
|
-
"zod": "~
|
|
28
|
+
"zod": "~4.1.13",
|
|
25
29
|
"@aws-sdk/client-s3": "~3.844.0",
|
|
26
30
|
"@aws-sdk/s3-presigned-post": "^3.844.0",
|
|
27
|
-
"@aws-sdk/s3-request-presigner": "~3.844.0"
|
|
31
|
+
"@aws-sdk/s3-request-presigner": "~3.844.0",
|
|
32
|
+
"@geekmidas/cache": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@geekmidas/cache": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"zod": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"@aws-sdk/client-s3": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@aws-sdk/s3-presigned-post": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@aws-sdk/s3-request-presigner": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@geekmidas/cache": "^0.1.0"
|
|
28
53
|
},
|
|
29
54
|
"scripts": {}
|
|
30
55
|
}
|