@geekmidas/storage 10.0.0-alpha.98 → 10.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +13 -49
  3. package/dist/AmazonStorageClient-BHpWawGD.d.mts +45 -0
  4. package/dist/AmazonStorageClient-BHpWawGD.d.mts.map +1 -0
  5. package/dist/AmazonStorageClient-BNoY2PL6.d.cts +45 -0
  6. package/dist/AmazonStorageClient-BNoY2PL6.d.cts.map +1 -0
  7. package/dist/AmazonStorageClient-BvoZepKJ.cjs +161 -0
  8. package/dist/AmazonStorageClient-BvoZepKJ.cjs.map +1 -0
  9. package/dist/AmazonStorageClient-Dz-KCJ_4.mjs +127 -0
  10. package/dist/AmazonStorageClient-Dz-KCJ_4.mjs.map +1 -0
  11. package/dist/AmazonStorageClient.cjs +5 -0
  12. package/dist/AmazonStorageClient.d.cts +3 -0
  13. package/dist/AmazonStorageClient.d.mts +3 -0
  14. package/dist/AmazonStorageClient.mjs +4 -0
  15. package/dist/StorageClient-4ADnTPnJ.mjs +11 -0
  16. package/dist/StorageClient-4ADnTPnJ.mjs.map +1 -0
  17. package/dist/StorageClient-BDRVrMJj.cjs +17 -0
  18. package/dist/StorageClient-BDRVrMJj.cjs.map +1 -0
  19. package/dist/{registry-ClEvHGpM.d.cts → StorageClient-COs9SOsU.d.cts} +5 -27
  20. package/dist/StorageClient-COs9SOsU.d.cts.map +1 -0
  21. package/dist/{registry-ClEvHGpM.d.mts → StorageClient-DH4tP-Mf.d.mts} +5 -27
  22. package/dist/StorageClient-DH4tP-Mf.d.mts.map +1 -0
  23. package/dist/StorageClient.cjs +3 -0
  24. package/dist/StorageClient.d.cts +2 -0
  25. package/dist/StorageClient.d.mts +2 -0
  26. package/dist/StorageClient.mjs +3 -0
  27. package/dist/aws.cjs +4 -198
  28. package/dist/aws.d.cts +3 -50
  29. package/dist/aws.d.mts +3 -50
  30. package/dist/aws.mjs +3 -189
  31. package/dist/index.cjs +0 -55
  32. package/dist/index.d.cts +2 -87
  33. package/dist/index.d.mts +2 -87
  34. package/dist/index.mjs +0 -45
  35. package/package.json +9 -27
  36. package/src/AmazonStorageClient.ts +207 -0
  37. package/src/StorageClient.ts +108 -0
  38. package/src/__tests__/AmazonStorageClient.spec.ts +606 -0
  39. package/src/__tests__/StorageClient.spec.ts +98 -0
  40. package/src/aws.ts +11 -0
  41. package/src/index.ts +1 -0
  42. package/tsconfig.json +9 -0
  43. package/tsdown.config.ts +9 -0
  44. package/dist/aws.cjs.map +0 -1
  45. package/dist/aws.d.cts.map +0 -1
  46. package/dist/aws.d.mts.map +0 -1
  47. package/dist/aws.mjs.map +0 -1
  48. package/dist/errors-BB8jdHif.cjs +0 -157
  49. package/dist/errors-BB8jdHif.cjs.map +0 -1
  50. package/dist/errors-COXs1iNg.mjs +0 -116
  51. package/dist/errors-COXs1iNg.mjs.map +0 -1
  52. package/dist/index.cjs.map +0 -1
  53. package/dist/index.d.cts.map +0 -1
  54. package/dist/index.d.mts.map +0 -1
  55. package/dist/index.mjs.map +0 -1
  56. package/dist/registry-ClEvHGpM.d.cts.map +0 -1
  57. package/dist/registry-ClEvHGpM.d.mts.map +0 -1
  58. package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
  59. package/dist/s3Url.cjs +0 -109
  60. package/dist/s3Url.cjs.map +0 -1
  61. package/dist/s3Url.d.cts +0 -52
  62. package/dist/s3Url.d.cts.map +0 -1
  63. package/dist/s3Url.d.mts +0 -52
  64. package/dist/s3Url.d.mts.map +0 -1
  65. package/dist/s3Url.mjs +0 -90
  66. package/dist/s3Url.mjs.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,79 @@
1
+ # @geekmidas/storage
2
+
3
+ ## 10.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @geekmidas/cache@10.0.0
9
+
10
+ ## 9.0.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
15
+
16
+ All packages now share one version, enforced by a changesets `fixed` group. The
17
+ baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
18
+ backwards; this release takes the whole set to 9.0.2 together.
19
+
20
+ Independent versions made "which version of the docs applies to me"
21
+ unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
22
+ number per release makes versioned documentation possible, and lets 9 freeze as
23
+ the current paradigm while the constructs rework is developed against it.
24
+
25
+ Every release now publishes every package, and a major anywhere is a major
26
+ everywhere. Peer ranges get simpler in return.
27
+
28
+ - Updated dependencies [[`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42)]:
29
+ - @geekmidas/cache@9.0.2
30
+
31
+ ## 2.0.4
32
+
33
+ ### Patch Changes
34
+
35
+ - 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
36
+ registry. The previous release only published the four packages that had
37
+ version bumps; the remaining packages failed with "cannot publish over the
38
+ previously published versions" because their versions were unchanged.
39
+ - Updated dependencies [[`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309)]:
40
+ - @geekmidas/cache@1.1.2
41
+
42
+ ## 2.0.3
43
+
44
+ ### Patch Changes
45
+
46
+ - 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
47
+
48
+ - Updated dependencies [[`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651)]:
49
+ - @geekmidas/cache@1.1.1
50
+
51
+ ## 2.0.2
52
+
53
+ ### Patch Changes
54
+
55
+ - ✨ [`f843d08`](https://github.com/geekmidas/toolbox/commit/f843d08e512d5d5410fb93376a8b9b127434ff39) Thanks [@geekmidas](https://github.com/geekmidas)! - Add response type and content dispotion
56
+
57
+ ## 2.0.1
58
+
59
+ ### Patch Changes
60
+
61
+ - ✨ [`d19d376`](https://github.com/geekmidas/toolbox/commit/d19d376738017d21f5df1e814fd9898b610554df) Thanks [@geekmidas](https://github.com/geekmidas)! - Add delete for storage client
62
+
63
+ ## 2.0.0
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [[`be4f7a9`](https://github.com/geekmidas/toolbox/commit/be4f7a9bd5de7f08adbca582916d6902e0c24de2)]:
68
+ - @geekmidas/cache@1.1.0
69
+
70
+ ## 1.0.0
71
+
72
+ ### Major Changes
73
+
74
+ - [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [[`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8)]:
79
+ - @geekmidas/cache@1.0.0
package/README.md CHANGED
@@ -85,49 +85,6 @@ const storage = AmazonStorageClient.create({
85
85
  });
86
86
  ```
87
87
 
88
- ## Storage URLs and credentials
89
-
90
- A declared bucket reaches an app as one URL, `<ID>_URL`, and
91
- `createStorageClient(url)` picks the driver by its scheme. An `s3://` URL
92
- names the bucket as its host and the rest as query parameters:
93
-
94
- ```
95
- s3://uploads?region=eu-west-1
96
- s3://uploads?region=auto&endpoint=https://<account>.r2.cloudflarestorage.com
97
- ```
98
-
99
- Credentials are optional, and come from one of two places:
100
-
101
- - **The URL's userinfo** — `s3://KEY:SECRET@uploads?region=eu-west-1`. A key
102
- here signs for this bucket only and wins over anything in the environment.
103
- Percent-encode both halves: AWS secrets often contain `/` (`%2F`) and `+`
104
- (`%2B`). `s3Url.build` does this for you, and `s3Url.parse` decodes them.
105
- - **The SDK's default chain** — for a URL with no userinfo: the shared
106
- `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY`, a profile, or an execution role.
107
-
108
- ```typescript
109
- import { s3Url } from '@geekmidas/storage/aws';
110
-
111
- s3Url.build({
112
- bucket: 'uploads',
113
- region: 'eu-west-1',
114
- accessKeyId: 'AKIA…',
115
- secretAccessKey: 'wJal/rXUt+nFEMI…',
116
- });
117
- // 's3://AKIA…:wJal%2FrXUt%2BnFEMI…@uploads?region=eu-west-1'
118
- ```
119
-
120
- Prefer a key per bucket, scoped to that bucket, over one shared pair: an app
121
- that reads two buckets then holds two narrow keys rather than one that opens
122
- both. A URL with only one half of a pair (`s3://KEY@uploads`) is refused with
123
- `IncompleteStorageCredentials` — it is never completed from the environment.
124
-
125
- Every storage error that carries a URL (`MalformedStorageUrl`,
126
- `UnexpectedStorageScheme`, `MissingStorageBucket`,
127
- `UnregisteredStorageScheme`, `IncompleteStorageCredentials`) holds it with the
128
- userinfo replaced by `REDACTED`, and its message never includes the URL.
129
- `redactStorageUrl(url)` does the same for your own log lines.
130
-
131
88
  ## API Reference
132
89
 
133
90
  ### StorageClient Interface
@@ -443,13 +400,20 @@ npm run test:once
443
400
 
444
401
  ### Local Development with MinIO
445
402
 
446
- The suite starts the repo compose stack's MinIO itself (`geekmidas` /
447
- `geekmidas`, with a `geekmidas` bucket). It publishes on port 9000; when
448
- another project holds that port, move it:
403
+ 1. Start MinIO using Docker Compose:
404
+ ```bash
405
+ docker-compose up -d minio
406
+ ```
449
407
 
450
- ```bash
451
- MINIO_API_HOST_PORT=29000 MINIO_CONSOLE_HOST_PORT=29001 pnpm vitest run --project storage
452
- ```
408
+ 2. MinIO will be available at:
409
+ - API: http://localhost:9000
410
+ - Console: http://localhost:9001
411
+ - Credentials: minioadmin/minioadmin
412
+
413
+ 3. Run integration tests:
414
+ ```bash
415
+ npm run test:integration
416
+ ```
453
417
 
454
418
  ### Project Structure
455
419
 
@@ -0,0 +1,45 @@
1
+ import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-DH4tP-Mf.mjs";
2
+ import { S3Client } from "@aws-sdk/client-s3";
3
+ import { Cache } from "@geekmidas/cache";
4
+
5
+ //#region src/AmazonStorageClient.d.ts
6
+ declare class AmazonStorageClient implements StorageClient {
7
+ private readonly client;
8
+ private readonly bucket;
9
+ private readonly acl;
10
+ readonly cache?: Cache;
11
+ readonly provider = StorageProvider.AWSS3;
12
+ static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
13
+ constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList, cache?: Cache);
14
+ private createGetObjectCommand;
15
+ getVersionDownloadURL(file: File, versionId: string): Promise<string>;
16
+ getVersions(key: string): Promise<DocumentVersion[]>;
17
+ getDownloadURL(file: File, expiresIn?: number): Promise<string>;
18
+ getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
19
+ getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
20
+ upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
21
+ delete(key: string): Promise<void>;
22
+ }
23
+ declare enum AmazonCannedAccessControlList {
24
+ AuthenticatedRead = "authenticated-read",
25
+ Private = "private",
26
+ PublicRead = "public-read",
27
+ PublicReadWrite = "public-read-write",
28
+ AwsExecRead = "aws-exec-read",
29
+ BucketOwnerRead = "bucket-owner-read",
30
+ BucketOwnerFullControl = "bucket-owner-full-control",
31
+ LogDeliveryWrite = "log-delivery-write",
32
+ }
33
+ interface AmazonStorageClientCreateOptions {
34
+ bucket: string;
35
+ region?: string;
36
+ acl?: AmazonCannedAccessControlList;
37
+ accessKeyId?: string;
38
+ secretAccessKey?: string;
39
+ endpoint?: string;
40
+ forcePathStyle?: boolean;
41
+ cache?: Cache;
42
+ }
43
+ //#endregion
44
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
45
+ //# sourceMappingURL=AmazonStorageClient-BHpWawGD.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmazonStorageClient-BHpWawGD.d.mts","names":[],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":[],"mappings":";;;;;cAoBa,mBAAA,YAA+B;;EAA/B,iBAAA,MAAoB;EAAA,iBAAA,GAAA;EAAA,SAkCd,KAAA,CAAA,EAAA,KAAA;EAAK,SAjCN,QAAA,GAAA,eAAA,CAAA,KAAA;EAAA,OAGP,MAAA,CAAA,OAAA,EAAA,gCAAA,CAAA,EACP,mBADO;EAAgC,WACvC,CAAA,MAAA,EA0BuB,QA1BvB,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EA4BkB,6BA5BlB,EAAA,KAAA,CAAA,EA6Be,KA7Bf;EAAmB,QA0BI,sBAAA;EAAQ,qBAEb,CAAA,IAAA,EAyBO,IAzBP,EAAA,SAAA,EAAA,MAAA,CAAA,EAyBiC,OAzBjC,CAAA,MAAA,CAAA;EAAkD,WACrD,CAAA,GAAA,EAAA,MAAA,CAAA,EA6Bc,OA7Bd,CA6BsB,eA7BtB,EAAA,CAAA;EAAK,cAwBK,CAAA,IAAA,EAmBD,IAnBC,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAmB2B,OAnB3B,CAAA,MAAA,CAAA;EAAI,YAAsB,CAAA,MAAA,EAuC7C,eAvC6C,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAyCnD,OAzCmD,CAAA,MAAA,CAAA;EAAO,SAKrB,CAAA,MAAA,EAgD/B,eAhD+B,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAkDrC,OAlDqC,CAkD7B,iBAlD6B,CAAA;EAAe,MAAvB,CAAA,GAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,GA4EhB,MA5EgB,EAAA,WAAA,EAAA,MAAA,CAAA,EA8E7B,OA9E6B,CAAA,IAAA,CAAA;EAAO,MAcZ,CAAA,GAAA,EAAA,MAAA,CAAA,EA+EA,OA/EA,CAAA,IAAA,CAAA;;AAoBlB,aAqEE,6BAAA;EArEa,iBAErB,GAAA,oBAAA;EAAO,OAYD,GAAA,SAAA;EAAe,UAEb,GAAA,aAAA;EAAiB,eAAzB,GAAA,mBAAA;EAAO,WA0BM,GAAA,eAAA;EAAM,eAEnB,GAAA,mBAAA;EAAO,sBAeiB,GAAA,2BAAA;EAAO,gBA5JS,GAAA,oBAAA;AAAa;AAsKzD,UAWU,gCAAA,CAX+B;EAW/B,MAAA,EAAA,MAAA;EAAgC,MAAA,CAAA,EAAA,MAAA;EAAA,GAGnC,CAAA,EAAA,6BAAA;EAA6B,WAK3B,CAAA,EAAA,MAAA;EAAK,eAAA,CAAA,EAAA,MAAA;;;UAAL"}
@@ -0,0 +1,45 @@
1
+ import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-COs9SOsU.cjs";
2
+ import { S3Client } from "@aws-sdk/client-s3";
3
+ import { Cache } from "@geekmidas/cache";
4
+
5
+ //#region src/AmazonStorageClient.d.ts
6
+ declare class AmazonStorageClient implements StorageClient {
7
+ private readonly client;
8
+ private readonly bucket;
9
+ private readonly acl;
10
+ readonly cache?: Cache;
11
+ readonly provider = StorageProvider.AWSS3;
12
+ static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
13
+ constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList, cache?: Cache);
14
+ private createGetObjectCommand;
15
+ getVersionDownloadURL(file: File, versionId: string): Promise<string>;
16
+ getVersions(key: string): Promise<DocumentVersion[]>;
17
+ getDownloadURL(file: File, expiresIn?: number): Promise<string>;
18
+ getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
19
+ getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
20
+ upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
21
+ delete(key: string): Promise<void>;
22
+ }
23
+ declare enum AmazonCannedAccessControlList {
24
+ AuthenticatedRead = "authenticated-read",
25
+ Private = "private",
26
+ PublicRead = "public-read",
27
+ PublicReadWrite = "public-read-write",
28
+ AwsExecRead = "aws-exec-read",
29
+ BucketOwnerRead = "bucket-owner-read",
30
+ BucketOwnerFullControl = "bucket-owner-full-control",
31
+ LogDeliveryWrite = "log-delivery-write",
32
+ }
33
+ interface AmazonStorageClientCreateOptions {
34
+ bucket: string;
35
+ region?: string;
36
+ acl?: AmazonCannedAccessControlList;
37
+ accessKeyId?: string;
38
+ secretAccessKey?: string;
39
+ endpoint?: string;
40
+ forcePathStyle?: boolean;
41
+ cache?: Cache;
42
+ }
43
+ //#endregion
44
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
45
+ //# sourceMappingURL=AmazonStorageClient-BNoY2PL6.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmazonStorageClient-BNoY2PL6.d.cts","names":[],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":[],"mappings":";;;;;cAoBa,mBAAA,YAA+B;;EAA/B,iBAAA,MAAoB;EAAA,iBAAA,GAAA;EAAA,SAkCd,KAAA,CAAA,EAAA,KAAA;EAAK,SAjCN,QAAA,GAAA,eAAA,CAAA,KAAA;EAAA,OAGP,MAAA,CAAA,OAAA,EAAA,gCAAA,CAAA,EACP,mBADO;EAAgC,WACvC,CAAA,MAAA,EA0BuB,QA1BvB,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EA4BkB,6BA5BlB,EAAA,KAAA,CAA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0,0 +1,161 @@
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
24
+ const require_StorageClient = require('./StorageClient-BDRVrMJj.cjs');
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"));
28
+
29
+ //#region src/AmazonStorageClient.ts
30
+ var AmazonStorageClient = class AmazonStorageClient {
31
+ provider = require_StorageClient.StorageProvider.AWSS3;
32
+ static create(options) {
33
+ const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
34
+ const hasCredentials = accessKeyId && secretAccessKey;
35
+ const credentials = hasCredentials ? {
36
+ accessKeyId,
37
+ secretAccessKey
38
+ } : void 0;
39
+ const client = new __aws_sdk_client_s3.S3Client({
40
+ region,
41
+ credentials,
42
+ endpoint,
43
+ forcePathStyle
44
+ });
45
+ return new AmazonStorageClient(client, bucket, acl, cache);
46
+ }
47
+ constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead, cache) {
48
+ this.client = client;
49
+ this.bucket = bucket;
50
+ this.acl = acl;
51
+ this.cache = cache;
52
+ }
53
+ createGetObjectCommand(file, overrides) {
54
+ const disposition = file.disposition ?? (file.name ? "attachment" : void 0);
55
+ const ResponseContentDisposition = disposition ? file.name ? `${disposition}; filename=${encodeURIComponent(file.name)}` : disposition : void 0;
56
+ return new __aws_sdk_client_s3.GetObjectCommand({
57
+ Bucket: this.bucket,
58
+ Key: file.path,
59
+ ResponseContentDisposition,
60
+ ResponseContentType: file.responseContentType,
61
+ ...overrides
62
+ });
63
+ }
64
+ getVersionDownloadURL(file, versionId) {
65
+ const command = this.createGetObjectCommand(file, { VersionId: versionId });
66
+ return (0, __aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: 60 * 60 * 24 });
67
+ }
68
+ async getVersions(key) {
69
+ const command = new __aws_sdk_client_s3.ListObjectVersionsCommand({
70
+ Bucket: this.bucket,
71
+ Prefix: key
72
+ });
73
+ const { Versions = [] } = await this.client.send(command);
74
+ return Versions.map((version) => ({
75
+ id: version.VersionId || "",
76
+ createdAt: version.LastModified || /* @__PURE__ */ new Date()
77
+ }));
78
+ }
79
+ async getDownloadURL(file, expiresIn = 60 * 60) {
80
+ const cacheKey = `download-url:${file.path}`;
81
+ const cachedURL = await this.cache?.get(cacheKey);
82
+ if (cachedURL) return cachedURL;
83
+ const command = this.createGetObjectCommand(file);
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;
88
+ }
89
+ async getUploadURL(params, expiresIn = 60 * 60) {
90
+ const command = new __aws_sdk_client_s3.PutObjectCommand({
91
+ Bucket: this.bucket,
92
+ Key: params.path,
93
+ ContentType: params.contentType,
94
+ ContentLength: params.contentLength
95
+ });
96
+ return (0, __aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn });
97
+ }
98
+ async getUpload(params, expiresIn = 5) {
99
+ const { path } = params;
100
+ const { fields: values, url } = await (0, __aws_sdk_s3_presigned_post.createPresignedPost)(this.client, {
101
+ Expires: expiresIn * 60,
102
+ Bucket: this.bucket,
103
+ Fields: { acl: this.acl },
104
+ Conditions: [],
105
+ Key: path
106
+ });
107
+ const keys = Object.keys(values);
108
+ const fields = keys.map((key) => ({
109
+ key,
110
+ value: values[key] || ""
111
+ }));
112
+ return {
113
+ url,
114
+ fields
115
+ };
116
+ }
117
+ async upload(key, data, contentType) {
118
+ const Body = typeof data === "string" ? Buffer.from(data, "base64") : data;
119
+ const params = {
120
+ Bucket: this.bucket,
121
+ Key: key,
122
+ Body,
123
+ ContentType: contentType
124
+ };
125
+ const command = new __aws_sdk_client_s3.PutObjectCommand(params);
126
+ await this.client.send(command);
127
+ }
128
+ async delete(key) {
129
+ const command = new __aws_sdk_client_s3.DeleteObjectCommand({
130
+ Bucket: this.bucket,
131
+ Key: key
132
+ });
133
+ await this.client.send(command);
134
+ }
135
+ };
136
+ let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList$1) {
137
+ AmazonCannedAccessControlList$1["AuthenticatedRead"] = "authenticated-read";
138
+ AmazonCannedAccessControlList$1["Private"] = "private";
139
+ AmazonCannedAccessControlList$1["PublicRead"] = "public-read";
140
+ AmazonCannedAccessControlList$1["PublicReadWrite"] = "public-read-write";
141
+ AmazonCannedAccessControlList$1["AwsExecRead"] = "aws-exec-read";
142
+ AmazonCannedAccessControlList$1["BucketOwnerRead"] = "bucket-owner-read";
143
+ AmazonCannedAccessControlList$1["BucketOwnerFullControl"] = "bucket-owner-full-control";
144
+ AmazonCannedAccessControlList$1["LogDeliveryWrite"] = "log-delivery-write";
145
+ return AmazonCannedAccessControlList$1;
146
+ }({});
147
+
148
+ //#endregion
149
+ Object.defineProperty(exports, 'AmazonCannedAccessControlList', {
150
+ enumerable: true,
151
+ get: function () {
152
+ return AmazonCannedAccessControlList;
153
+ }
154
+ });
155
+ Object.defineProperty(exports, 'AmazonStorageClient', {
156
+ enumerable: true,
157
+ get: function () {
158
+ return AmazonStorageClient;
159
+ }
160
+ });
161
+ //# sourceMappingURL=AmazonStorageClient-BvoZepKJ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmazonStorageClient-BvoZepKJ.cjs","names":["StorageProvider","options: AmazonStorageClientCreateOptions","S3Client","client: S3Client","bucket: string","cache?: Cache","file: File","overrides?: { VersionId?: string }","GetObjectCommand","versionId: string","key: string","ListObjectVersionsCommand","params: GetUploadParams","PutObjectCommand","data: string | Buffer","contentType: string","DeleteObjectCommand"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n\tDeleteObjectCommand,\n\tGetObjectCommand,\n\tListObjectVersionsCommand,\n\tPutObjectCommand,\n\tS3Client,\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\ttype DocumentVersion,\n\ttype File,\n\ttype GetUploadParams,\n\ttype GetUploadResponse,\n\ttype StorageClient,\n\tStorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n\treadonly provider = StorageProvider.AWSS3;\n\n\tstatic create(\n\t\toptions: AmazonStorageClientCreateOptions,\n\t): AmazonStorageClient {\n\t\tconst {\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\taccessKeyId,\n\t\t\tacl,\n\t\t\tendpoint,\n\t\t\tsecretAccessKey,\n\t\t\tforcePathStyle = false,\n\t\t\tcache,\n\t\t} = options;\n\t\tconst hasCredentials = accessKeyId && secretAccessKey;\n\t\tconst credentials = hasCredentials\n\t\t\t? { accessKeyId, secretAccessKey }\n\t\t\t: undefined;\n\n\t\tconst client = new S3Client({\n\t\t\tregion,\n\t\t\tcredentials,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\n\n\t\treturn new AmazonStorageClient(client, bucket, acl, cache);\n\t}\n\tconstructor(\n\t\tprivate readonly client: S3Client,\n\t\tprivate readonly bucket: string,\n\t\tprivate readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n\t\treadonly cache?: Cache,\n\t) {}\n\n\tprivate createGetObjectCommand(\n\t\tfile: File,\n\t\toverrides?: { VersionId?: string },\n\t): GetObjectCommand {\n\t\tconst disposition =\n\t\t\tfile.disposition ?? (file.name ? 'attachment' : undefined);\n\t\tconst ResponseContentDisposition = disposition\n\t\t\t? file.name\n\t\t\t\t? `${disposition}; filename=${encodeURIComponent(file.name)}`\n\t\t\t\t: disposition\n\t\t\t: undefined;\n\n\t\treturn new GetObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: file.path,\n\t\t\tResponseContentDisposition,\n\t\t\tResponseContentType: file.responseContentType,\n\t\t\t...overrides,\n\t\t});\n\t}\n\n\tgetVersionDownloadURL(file: File, versionId: string): Promise<string> {\n\t\tconst command = this.createGetObjectCommand(file, { VersionId: versionId });\n\t\treturn getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n\t}\n\n\tasync getVersions(key: string): Promise<DocumentVersion[]> {\n\t\tconst command = new ListObjectVersionsCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tPrefix: key,\n\t\t});\n\n\t\tconst { Versions = [] } = await this.client.send(command);\n\n\t\treturn Versions.map((version) => ({\n\t\t\tid: version.VersionId || '',\n\t\t\tcreatedAt: version.LastModified || new Date(),\n\t\t}));\n\t}\n\n\tasync getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n\t\tconst cacheKey = `download-url:${file.path}`;\n\t\tconst cachedURL = await this.cache?.get<string>(cacheKey);\n\n\t\tif (cachedURL) {\n\t\t\treturn cachedURL;\n\t\t}\n\n\t\tconst command = this.createGetObjectCommand(file);\n\t\tconst url = await getSignedUrl(this.client, command, { expiresIn });\n\t\tconst cacheExpiration = Math.max(expiresIn - 60, 0);\n\n\t\tif (cacheExpiration) {\n\t\t\tawait this.cache?.set(cacheKey, url, cacheExpiration);\n\t\t}\n\n\t\treturn url;\n\t}\n\n\tasync getUploadURL(\n\t\tparams: GetUploadParams,\n\t\texpiresIn = 60 * 60,\n\t): Promise<string> {\n\t\tconst command = new PutObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: params.path,\n\t\t\tContentType: params.contentType,\n\t\t\tContentLength: params.contentLength,\n\t\t});\n\n\t\treturn getSignedUrl(this.client, command, { expiresIn });\n\t}\n\n\tasync getUpload(\n\t\tparams: GetUploadParams,\n\t\texpiresIn = 5,\n\t): Promise<GetUploadResponse> {\n\t\tconst { path } = params;\n\t\tconst { fields: values, url } = await createPresignedPost(this.client, {\n\t\t\tExpires: expiresIn * 60,\n\t\t\tBucket: this.bucket,\n\t\t\tFields: {\n\t\t\t\tacl: this.acl,\n\t\t\t},\n\t\t\tConditions: [\n\t\t\t\t// content length restrictions: 0-1MB]\n\t\t\t\t// ['content-length-range', 0, contentLength],\n\t\t\t\t// specify content-type to be more generic- images only\n\t\t\t\t// ['starts-with', '$Content-Type', 'image/'],\n\t\t\t\t// ['starts-with', '$Content-Type', contentType],\n\t\t\t],\n\t\t\tKey: path,\n\t\t});\n\n\t\tconst keys = Object.keys(values);\n\t\tconst fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n\t\treturn { url, fields };\n\t}\n\n\tasync upload(\n\t\tkey: string,\n\t\tdata: string | Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n\t\tconst params = {\n\t\t\tBucket: this.bucket,\n\t\t\tKey: key,\n\t\t\tBody,\n\t\t\tContentType: contentType,\n\t\t};\n\n\t\tconst command = new PutObjectCommand(params);\n\n\t\tawait this.client.send(command);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tconst command = new DeleteObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: key,\n\t\t});\n\n\t\tawait this.client.send(command);\n\t}\n}\n\nexport enum AmazonCannedAccessControlList {\n\tAuthenticatedRead = 'authenticated-read',\n\tPrivate = 'private',\n\tPublicRead = 'public-read',\n\tPublicReadWrite = 'public-read-write',\n\tAwsExecRead = 'aws-exec-read',\n\tBucketOwnerRead = 'bucket-owner-read',\n\tBucketOwnerFullControl = 'bucket-owner-full-control',\n\tLogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n\tbucket: string;\n\tregion?: string;\n\tacl?: AmazonCannedAccessControlList;\n\taccessKeyId?: string;\n\tsecretAccessKey?: string;\n\tendpoint?: string;\n\tforcePathStyle?: boolean;\n\tcache?: Cache;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,sBAAb,MAAa,oBAA6C;CACzD,AAAS,WAAWA,sCAAgB;CAEpC,OAAO,OACNC,SACsB;EACtB,MAAM,EACL,QACA,QACA,aACA,KACA,UACA,iBACA,iBAAiB,OACjB,OACA,GAAG;EACJ,MAAM,iBAAiB,eAAe;EACtC,MAAM,cAAc,iBACjB;GAAE;GAAa;EAAiB;EAGnC,MAAM,SAAS,IAAIC,6BAAS;GAC3B;GACA;GACA;GACA;EACA;AAED,SAAO,IAAI,oBAAoB,QAAQ,QAAQ,KAAK;CACpD;CACD,YACkBC,QACAC,QACA,MAAM,8BAA8B,mBAC5CC,OACR;EAJgB;EACA;EACA;EACR;CACN;CAEJ,AAAQ,uBACPC,MACAC,WACmB;EACnB,MAAM,cACL,KAAK,gBAAgB,KAAK,OAAO;EAClC,MAAM,6BAA6B,cAChC,KAAK,QACH,EAAE,YAAY,aAAa,mBAAmB,KAAK,KAAK,CAAC,IAC1D;AAGJ,SAAO,IAAIC,qCAAiB;GAC3B,QAAQ,KAAK;GACb,KAAK,KAA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,KAAK,QAAQ;GACtE,SAAS,YAAY;GACrB,QAAQ,KAAK;GACb,QAAQ,EACP,KAAK,KAAK,IACV;GACD,YAAY,CAMX;GACD,KAAK;EACL,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;CACtB;CAED,MAAM,OACLF,KACAI,MACAC,aACgB;EAChB,MAAM,cAAc,SAAS,WAAW,OAAO,KAAK,MAAM,SAAS,GAAG;EAEtE,MAAM,SAAS;GACd,QAAQ,KAAK;GACb,KAAK;GACL;GACA,aAAa;EACb;EAED,MAAM,UAAU,IAAIF,qCAAiB;AAErC,QAAM,KAAK,OAAO,KAAK,QAAQ;CAC/B;CAED,MAAM,OAAOH,KAA4B;EACxC,MAAM,UAAU,IAAIM,wCAAoB;GACvC,QAAQ,KAAK;GACb,KAAK;EACL;AAED,QAAM,KAAK,OAAO,KAAK,QAAQ;CAC/B;AACD;AAED,IAAY,0FAAL;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA"}
@@ -0,0 +1,127 @@
1
+ import { StorageProvider } from "./StorageClient-4ADnTPnJ.mjs";
2
+ import { DeleteObjectCommand, GetObjectCommand, ListObjectVersionsCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
3
+ import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
4
+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
5
+
6
+ //#region src/AmazonStorageClient.ts
7
+ var AmazonStorageClient = class AmazonStorageClient {
8
+ provider = StorageProvider.AWSS3;
9
+ static create(options) {
10
+ const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
11
+ const hasCredentials = accessKeyId && secretAccessKey;
12
+ const credentials = hasCredentials ? {
13
+ accessKeyId,
14
+ secretAccessKey
15
+ } : void 0;
16
+ const client = new S3Client({
17
+ region,
18
+ credentials,
19
+ endpoint,
20
+ forcePathStyle
21
+ });
22
+ return new AmazonStorageClient(client, bucket, acl, cache);
23
+ }
24
+ constructor(client, bucket, acl = AmazonCannedAccessControlList.AuthenticatedRead, cache) {
25
+ this.client = client;
26
+ this.bucket = bucket;
27
+ this.acl = acl;
28
+ this.cache = cache;
29
+ }
30
+ createGetObjectCommand(file, overrides) {
31
+ const disposition = file.disposition ?? (file.name ? "attachment" : void 0);
32
+ const ResponseContentDisposition = disposition ? file.name ? `${disposition}; filename=${encodeURIComponent(file.name)}` : disposition : void 0;
33
+ return new GetObjectCommand({
34
+ Bucket: this.bucket,
35
+ Key: file.path,
36
+ ResponseContentDisposition,
37
+ ResponseContentType: file.responseContentType,
38
+ ...overrides
39
+ });
40
+ }
41
+ getVersionDownloadURL(file, versionId) {
42
+ const command = this.createGetObjectCommand(file, { VersionId: versionId });
43
+ return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });
44
+ }
45
+ async getVersions(key) {
46
+ const command = new ListObjectVersionsCommand({
47
+ Bucket: this.bucket,
48
+ Prefix: key
49
+ });
50
+ const { Versions = [] } = await this.client.send(command);
51
+ return Versions.map((version) => ({
52
+ id: version.VersionId || "",
53
+ createdAt: version.LastModified || /* @__PURE__ */ new Date()
54
+ }));
55
+ }
56
+ async getDownloadURL(file, expiresIn = 60 * 60) {
57
+ const cacheKey = `download-url:${file.path}`;
58
+ const cachedURL = await this.cache?.get(cacheKey);
59
+ if (cachedURL) return cachedURL;
60
+ const command = this.createGetObjectCommand(file);
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;
65
+ }
66
+ async getUploadURL(params, expiresIn = 60 * 60) {
67
+ const command = new PutObjectCommand({
68
+ Bucket: this.bucket,
69
+ Key: params.path,
70
+ ContentType: params.contentType,
71
+ ContentLength: params.contentLength
72
+ });
73
+ return getSignedUrl(this.client, command, { expiresIn });
74
+ }
75
+ async getUpload(params, expiresIn = 5) {
76
+ const { path } = params;
77
+ const { fields: values, url } = await createPresignedPost(this.client, {
78
+ Expires: expiresIn * 60,
79
+ Bucket: this.bucket,
80
+ Fields: { acl: this.acl },
81
+ Conditions: [],
82
+ Key: path
83
+ });
84
+ const keys = Object.keys(values);
85
+ const fields = keys.map((key) => ({
86
+ key,
87
+ value: values[key] || ""
88
+ }));
89
+ return {
90
+ url,
91
+ fields
92
+ };
93
+ }
94
+ async upload(key, data, contentType) {
95
+ const Body = typeof data === "string" ? Buffer.from(data, "base64") : data;
96
+ const params = {
97
+ Bucket: this.bucket,
98
+ Key: key,
99
+ Body,
100
+ ContentType: contentType
101
+ };
102
+ const command = new PutObjectCommand(params);
103
+ await this.client.send(command);
104
+ }
105
+ async delete(key) {
106
+ const command = new DeleteObjectCommand({
107
+ Bucket: this.bucket,
108
+ Key: key
109
+ });
110
+ await this.client.send(command);
111
+ }
112
+ };
113
+ let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList$1) {
114
+ AmazonCannedAccessControlList$1["AuthenticatedRead"] = "authenticated-read";
115
+ AmazonCannedAccessControlList$1["Private"] = "private";
116
+ AmazonCannedAccessControlList$1["PublicRead"] = "public-read";
117
+ AmazonCannedAccessControlList$1["PublicReadWrite"] = "public-read-write";
118
+ AmazonCannedAccessControlList$1["AwsExecRead"] = "aws-exec-read";
119
+ AmazonCannedAccessControlList$1["BucketOwnerRead"] = "bucket-owner-read";
120
+ AmazonCannedAccessControlList$1["BucketOwnerFullControl"] = "bucket-owner-full-control";
121
+ AmazonCannedAccessControlList$1["LogDeliveryWrite"] = "log-delivery-write";
122
+ return AmazonCannedAccessControlList$1;
123
+ }({});
124
+
125
+ //#endregion
126
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
127
+ //# sourceMappingURL=AmazonStorageClient-Dz-KCJ_4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmazonStorageClient-Dz-KCJ_4.mjs","names":["options: AmazonStorageClientCreateOptions","client: S3Client","bucket: string","cache?: Cache","file: File","overrides?: { VersionId?: string }","versionId: string","key: string","params: GetUploadParams","data: string | Buffer","contentType: string"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n\tDeleteObjectCommand,\n\tGetObjectCommand,\n\tListObjectVersionsCommand,\n\tPutObjectCommand,\n\tS3Client,\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\ttype DocumentVersion,\n\ttype File,\n\ttype GetUploadParams,\n\ttype GetUploadResponse,\n\ttype StorageClient,\n\tStorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n\treadonly provider = StorageProvider.AWSS3;\n\n\tstatic create(\n\t\toptions: AmazonStorageClientCreateOptions,\n\t): AmazonStorageClient {\n\t\tconst {\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\taccessKeyId,\n\t\t\tacl,\n\t\t\tendpoint,\n\t\t\tsecretAccessKey,\n\t\t\tforcePathStyle = false,\n\t\t\tcache,\n\t\t} = options;\n\t\tconst hasCredentials = accessKeyId && secretAccessKey;\n\t\tconst credentials = hasCredentials\n\t\t\t? { accessKeyId, secretAccessKey }\n\t\t\t: undefined;\n\n\t\tconst client = new S3Client({\n\t\t\tregion,\n\t\t\tcredentials,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\n\n\t\treturn new AmazonStorageClient(client, bucket, acl, cache);\n\t}\n\tconstructor(\n\t\tprivate readonly client: S3Client,\n\t\tprivate readonly bucket: string,\n\t\tprivate readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n\t\treadonly cache?: Cache,\n\t) {}\n\n\tprivate createGetObjectCommand(\n\t\tfile: File,\n\t\toverrides?: { VersionId?: string },\n\t): GetObjectCommand {\n\t\tconst disposition =\n\t\t\tfile.disposition ?? (file.name ? 'attachment' : undefined);\n\t\tconst ResponseContentDisposition = disposition\n\t\t\t? file.name\n\t\t\t\t? `${disposition}; filename=${encodeURIComponent(file.name)}`\n\t\t\t\t: disposition\n\t\t\t: undefined;\n\n\t\treturn new GetObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: file.path,\n\t\t\tResponseContentDisposition,\n\t\t\tResponseContentType: file.responseContentType,\n\t\t\t...overrides,\n\t\t});\n\t}\n\n\tgetVersionDownloadURL(file: File, versionId: string): Promise<string> {\n\t\tconst command = this.createGetObjectCommand(file, { VersionId: versionId });\n\t\treturn getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n\t}\n\n\tasync getVersions(key: string): Promise<DocumentVersion[]> {\n\t\tconst command = new ListObjectVersionsCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tPrefix: key,\n\t\t});\n\n\t\tconst { Versions = [] } = await this.client.send(command);\n\n\t\treturn Versions.map((version) => ({\n\t\t\tid: version.VersionId || '',\n\t\t\tcreatedAt: version.LastModified || new Date(),\n\t\t}));\n\t}\n\n\tasync getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n\t\tconst cacheKey = `download-url:${file.path}`;\n\t\tconst cachedURL = await this.cache?.get<string>(cacheKey);\n\n\t\tif (cachedURL) {\n\t\t\treturn cachedURL;\n\t\t}\n\n\t\tconst command = this.createGetObjectCommand(file);\n\t\tconst url = await getSignedUrl(this.client, command, { expiresIn });\n\t\tconst cacheExpiration = Math.max(expiresIn - 60, 0);\n\n\t\tif (cacheExpiration) {\n\t\t\tawait this.cache?.set(cacheKey, url, cacheExpiration);\n\t\t}\n\n\t\treturn url;\n\t}\n\n\tasync getUploadURL(\n\t\tparams: GetUploadParams,\n\t\texpiresIn = 60 * 60,\n\t): Promise<string> {\n\t\tconst command = new PutObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: params.path,\n\t\t\tContentType: params.contentType,\n\t\t\tContentLength: params.contentLength,\n\t\t});\n\n\t\treturn getSignedUrl(this.client, command, { expiresIn });\n\t}\n\n\tasync getUpload(\n\t\tparams: GetUploadParams,\n\t\texpiresIn = 5,\n\t): Promise<GetUploadResponse> {\n\t\tconst { path } = params;\n\t\tconst { fields: values, url } = await createPresignedPost(this.client, {\n\t\t\tExpires: expiresIn * 60,\n\t\t\tBucket: this.bucket,\n\t\t\tFields: {\n\t\t\t\tacl: this.acl,\n\t\t\t},\n\t\t\tConditions: [\n\t\t\t\t// content length restrictions: 0-1MB]\n\t\t\t\t// ['content-length-range', 0, contentLength],\n\t\t\t\t// specify content-type to be more generic- images only\n\t\t\t\t// ['starts-with', '$Content-Type', 'image/'],\n\t\t\t\t// ['starts-with', '$Content-Type', contentType],\n\t\t\t],\n\t\t\tKey: path,\n\t\t});\n\n\t\tconst keys = Object.keys(values);\n\t\tconst fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n\t\treturn { url, fields };\n\t}\n\n\tasync upload(\n\t\tkey: string,\n\t\tdata: string | Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n\t\tconst params = {\n\t\t\tBucket: this.bucket,\n\t\t\tKey: key,\n\t\t\tBody,\n\t\t\tContentType: contentType,\n\t\t};\n\n\t\tconst command = new PutObjectCommand(params);\n\n\t\tawait this.client.send(command);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tconst command = new DeleteObjectCommand({\n\t\t\tBucket: this.bucket,\n\t\t\tKey: key,\n\t\t});\n\n\t\tawait this.client.send(command);\n\t}\n}\n\nexport enum AmazonCannedAccessControlList {\n\tAuthenticatedRead = 'authenticated-read',\n\tPrivate = 'private',\n\tPublicRead = 'public-read',\n\tPublicReadWrite = 'public-read-write',\n\tAwsExecRead = 'aws-exec-read',\n\tBucketOwnerRead = 'bucket-owner-read',\n\tBucketOwnerFullControl = 'bucket-owner-full-control',\n\tLogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n\tbucket: string;\n\tregion?: string;\n\tacl?: AmazonCannedAccessControlList;\n\taccessKeyId?: string;\n\tsecretAccessKey?: string;\n\tendpoint?: string;\n\tforcePathStyle?: boolean;\n\tcache?: Cache;\n}\n"],"mappings":";;;;;;AAoBA,IAAa,sBAAb,MAAa,oBAA6C;CACzD,AAAS,WAAW,gBAAgB;CAEpC,OAAO,OACNA,SACsB;EACtB,MAAM,EACL,QACA,QACA,aACA,KACA,UACA,iBACA,iBAAiB,OACjB,OACA,GAAG;EACJ,MAAM,iBAAiB,eAAe;EACtC,MAAM,cAAc,iBACjB;GAAE;GAAa;EAAiB;EAGnC,MAAM,SAAS,IAAI,SAAS;GAC3B;GACA;GACA;GACA;EACA;AAED,SAAO,IAAI,oBAAoB,QAAQ,QAAQ,KAAK;CACpD;CACD,YACkBC,QACAC,QACA,MAAM,8BAA8B,mBAC5CC,OACR;EAJgB;EACA;EACA;EACR;CACN;CAEJ,AAAQ,uBACPC,MACAC,WACmB;EACnB,MAAM,cACL,KAAK,gBAAgB,KAAK,OAAO;EAClC,MAAM,6BAA6B,cAChC,KAAK,QACH,EAAE,YAAY,aAAa,mBAAmB,KAAK,KAAK,CAAC,IAC1D;AAGJ,SAAO,IAAI,iBAAiB;GAC3B,QAAQ,KAAK;GACb,KAAK,KAAK;GACV;GACA,qBAAqB,KAAK;GAC1B,GAAG;EACH;CACD;CAED,sBAAsBD,MAAYE,WAAoC;EACrE,MAAM,UAAU,KAAK,uBAAuB,MAAM,EAAE,WAAW,UAAW,EAAC;AAC3E,SAAO,aAAa,KAAK,QAAQ,SAAS,EAAE,WAAW,KAAK,KAAK,GAAI,EAAC;CACtE;CAED,MAAM,YAAYC,KAAyC;EAC1D,MAAM,UAAU,IAAI,0BAA0B;GAC7C,QAAQ,KAAK;GACb,QAAQ;EACR;EAED,MAAM,EAAE,WAAW,CAAE,GAAE,GAAG,MAAM,KAAK,OAAO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tE,MAAM,SAAS;GACd,QAAQ,KAAK;GACb,KAAK;GACL;GACA,aAAa;EACb;EAED,MAAM,UAAU,IAAI,iBAAiB;AAErC,QAAM,KAAK,OAAO,KAAK,QAAQ;CAC/B;CAED,MAAM,OAAOH,KAA4B;EACxC,MAAM,UAAU,IAAI,oBAAoB;GACvC,QAAQ,KAAK;GACb,KAAK;EACL;AAED,QAAM,KAAK,OAAO,KAAK,QAAQ;CAC/B;AACD;AAED,IAAY,0FAAL;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA"}
@@ -0,0 +1,5 @@
1
+ const require_AmazonStorageClient = require('./AmazonStorageClient-BvoZepKJ.cjs');
2
+ require('./StorageClient-BDRVrMJj.cjs');
3
+
4
+ exports.AmazonCannedAccessControlList = require_AmazonStorageClient.AmazonCannedAccessControlList;
5
+ exports.AmazonStorageClient = require_AmazonStorageClient.AmazonStorageClient;
@@ -0,0 +1,3 @@
1
+ import "./StorageClient-COs9SOsU.cjs";
2
+ import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-BNoY2PL6.cjs";
3
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
@@ -0,0 +1,3 @@
1
+ import "./StorageClient-DH4tP-Mf.mjs";
2
+ import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-BHpWawGD.mjs";
3
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
@@ -0,0 +1,4 @@
1
+ import "./StorageClient-4ADnTPnJ.mjs";
2
+ import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-Dz-KCJ_4.mjs";
3
+
4
+ export { AmazonCannedAccessControlList, AmazonStorageClient };
@@ -0,0 +1,11 @@
1
+ //#region src/StorageClient.ts
2
+ let StorageProvider = /* @__PURE__ */ function(StorageProvider$1) {
3
+ StorageProvider$1["AWSS3"] = "geekimdas.toolbox.storage.aws.s3";
4
+ StorageProvider$1["GCP"] = "geekimdas.toolbox.storage.gcp";
5
+ StorageProvider$1["AZURE"] = "geekimdas.toolbox.storage.azure";
6
+ return StorageProvider$1;
7
+ }({});
8
+
9
+ //#endregion
10
+ export { StorageProvider };
11
+ //# sourceMappingURL=StorageClient-4ADnTPnJ.mjs.map
@@ -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\tid: string;\n\tcreatedAt: Date;\n}\n\nexport enum StorageProvider {\n\tAWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n\tGCP = 'geekimdas.toolbox.storage.gcp',\n\tAZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n\treadonly provider: StorageProvider;\n\treadonly cache?: Cache;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the upload URL.\n\t */\n\tgetUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n\t/**\n\t * Get a URL to download a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param expiresIn - The number of seconds the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the download URL.\n\t */\n\tgetDownloadURL(file: File, expiresIn?: number): Promise<string>;\n\t/**\n\t * Get the versions for a key.\n\t *\n\t * @param key - The key to get the versions for.\n\t */\n\tgetVersions(key: string): Promise<DocumentVersion[]>;\n\n\t/**\n\t * Get a URL to download a version of a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param versionId - The version ID to get the download URL for.\n\t */\n\tgetVersionDownloadURL(file: File, versionId: string): Promise<string>;\n\t/**\n\t *\n\t * @param key - The key to upload the file to.\n\t * @param data - The data to upload.\n\t * @param contentType - The content type of the data.\n\t */\n\tupload(\n\t\tkey: string,\n\t\tdata: string | Buffer,\n\t\tcontentType: string,\n\t): Promise<void>;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t */\n\tgetUpload(\n\t\tparams: GetUploadParams,\n\t\texpiresIn?: number,\n\t): Promise<GetUploadResponse>;\n\t/**\n\t * Delete a file from storage.\n\t *\n\t * @param key - The key (path) of the file to delete.\n\t */\n\tdelete(key: string): Promise<void>;\n}\n\nexport interface GetUploadParams {\n\tpath: string;\n\tcontentType: string;\n\tcontentLength: number;\n}\n\nexport type UploadField = {\n\tkey: string;\n\tvalue: string;\n};\n\nexport type GetUploadResponse = {\n\turl: string;\n\tfields: UploadField[];\n};\n\nexport interface File {\n\tname?: string;\n\tpath: string;\n\t/**\n\t * Override the Content-Type of the response.\n\t * Useful when the stored object's content type differs from what the browser should receive.\n\t */\n\tresponseContentType?: string;\n\t/**\n\t * Control how the browser handles the file.\n\t * - `'attachment'` — prompts download (default when `name` is set)\n\t * - `'inline'` — displays in the browser\n\t */\n\tdisposition?: 'inline' | 'attachment';\n}\n"],"mappings":";AAMA,IAAY,8DAAL;AACN;AACA;AACA;;AACA"}
@@ -0,0 +1,17 @@
1
+
2
+ //#region src/StorageClient.ts
3
+ let StorageProvider = /* @__PURE__ */ function(StorageProvider$1) {
4
+ StorageProvider$1["AWSS3"] = "geekimdas.toolbox.storage.aws.s3";
5
+ StorageProvider$1["GCP"] = "geekimdas.toolbox.storage.gcp";
6
+ StorageProvider$1["AZURE"] = "geekimdas.toolbox.storage.azure";
7
+ return StorageProvider$1;
8
+ }({});
9
+
10
+ //#endregion
11
+ Object.defineProperty(exports, 'StorageProvider', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return StorageProvider;
15
+ }
16
+ });
17
+ //# sourceMappingURL=StorageClient-BDRVrMJj.cjs.map