@geekmidas/storage 10.0.0-alpha.3 → 10.0.0-alpha.31
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/dist/aws.cjs +53 -58
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +7 -10
- package/dist/aws.d.cts.map +1 -1
- package/dist/aws.d.mts +7 -10
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +35 -41
- package/dist/aws.mjs.map +1 -1
- package/dist/{errors-Bce0CJ11.cjs → errors-Bexjg-j-.cjs} +27 -28
- package/dist/errors-Bexjg-j-.cjs.map +1 -0
- package/dist/{errors-D5UnAd-X.mjs → errors-CpYcpJCY.mjs} +3 -3
- package/dist/errors-CpYcpJCY.mjs.map +1 -0
- package/dist/index.cjs +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +16 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-DBsAUTT3.d.cts → registry-ClEvHGpM.d.cts} +3 -6
- package/dist/registry-ClEvHGpM.d.cts.map +1 -0
- package/dist/{registry-DEqSHjx-.d.mts → registry-ClEvHGpM.d.mts} +3 -6
- package/dist/registry-ClEvHGpM.d.mts.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/s3Url.cjs +79 -4
- package/dist/s3Url.cjs.map +1 -0
- package/dist/s3Url.d.cts +38 -2
- package/dist/s3Url.d.cts.map +1 -0
- package/dist/s3Url.d.mts +38 -2
- package/dist/s3Url.d.mts.map +1 -0
- package/dist/s3Url.mjs +60 -3
- package/dist/{s3Url-Bo32UTTA.cjs.map → s3Url.mjs.map} +1 -1
- package/package.json +7 -7
- package/dist/chunk-B9dir_RE.mjs +0 -11
- package/dist/errors-Bce0CJ11.cjs.map +0 -1
- package/dist/errors-D5UnAd-X.mjs.map +0 -1
- package/dist/registry-DBsAUTT3.d.cts.map +0 -1
- package/dist/registry-DEqSHjx-.d.mts.map +0 -1
- package/dist/s3Url-BfztIltX.d.cts +0 -39
- package/dist/s3Url-BfztIltX.d.cts.map +0 -1
- package/dist/s3Url-Bo32UTTA.cjs +0 -103
- package/dist/s3Url-C8FGPNrG.mjs +0 -52
- package/dist/s3Url-C8FGPNrG.mjs.map +0 -1
- package/dist/s3Url-COpMIgF9.d.mts +0 -42
- package/dist/s3Url-COpMIgF9.d.mts.map +0 -1
package/dist/aws.cjs
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//#region src/StorageClient.ts
|
|
8
|
-
let StorageProvider = /* @__PURE__ */ function(StorageProvider$1) {
|
|
9
|
-
StorageProvider$1["AWSS3"] = "geekimdas.toolbox.storage.aws.s3";
|
|
10
|
-
StorageProvider$1["GCP"] = "geekimdas.toolbox.storage.gcp";
|
|
11
|
-
StorageProvider$1["AZURE"] = "geekimdas.toolbox.storage.azure";
|
|
12
|
-
return StorageProvider$1;
|
|
13
|
-
}({});
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_s3Url = require("./s3Url.cjs");
|
|
3
|
+
let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
|
|
4
|
+
let _aws_sdk_s3_presigned_post = require("@aws-sdk/s3-presigned-post");
|
|
5
|
+
let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
16
6
|
//#region src/AmazonStorageClient.ts
|
|
17
7
|
var AmazonStorageClient = class AmazonStorageClient {
|
|
18
|
-
|
|
8
|
+
client;
|
|
9
|
+
bucket;
|
|
10
|
+
acl;
|
|
11
|
+
cache;
|
|
12
|
+
provider = "geekimdas.toolbox.storage.aws.s3";
|
|
19
13
|
static create(options) {
|
|
20
14
|
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
|
|
21
|
-
const
|
|
22
|
-
const credentials = hasCredentials ? {
|
|
23
|
-
accessKeyId,
|
|
24
|
-
secretAccessKey
|
|
25
|
-
} : void 0;
|
|
26
|
-
const client = new __aws_sdk_client_s3.S3Client({
|
|
15
|
+
const client = new _aws_sdk_client_s3.S3Client({
|
|
27
16
|
region,
|
|
28
|
-
credentials
|
|
17
|
+
credentials: accessKeyId && secretAccessKey ? {
|
|
18
|
+
accessKeyId,
|
|
19
|
+
secretAccessKey
|
|
20
|
+
} : void 0,
|
|
29
21
|
endpoint,
|
|
30
22
|
forcePathStyle
|
|
31
23
|
});
|
|
32
24
|
return new AmazonStorageClient(client, bucket, acl, cache);
|
|
33
25
|
}
|
|
34
|
-
constructor(client, bucket, acl =
|
|
26
|
+
constructor(client, bucket, acl = "authenticated-read", cache) {
|
|
35
27
|
this.client = client;
|
|
36
28
|
this.bucket = bucket;
|
|
37
29
|
this.acl = acl;
|
|
@@ -40,7 +32,7 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
40
32
|
createGetObjectCommand(file, overrides) {
|
|
41
33
|
const disposition = file.disposition ?? (file.name ? "attachment" : void 0);
|
|
42
34
|
const ResponseContentDisposition = disposition ? file.name ? `${disposition}; filename=${encodeURIComponent(file.name)}` : disposition : void 0;
|
|
43
|
-
return new
|
|
35
|
+
return new _aws_sdk_client_s3.GetObjectCommand({
|
|
44
36
|
Bucket: this.bucket,
|
|
45
37
|
Key: file.path,
|
|
46
38
|
ResponseContentDisposition,
|
|
@@ -50,10 +42,10 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
50
42
|
}
|
|
51
43
|
getVersionDownloadURL(file, versionId) {
|
|
52
44
|
const command = this.createGetObjectCommand(file, { VersionId: versionId });
|
|
53
|
-
return (0,
|
|
45
|
+
return (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: 86400 });
|
|
54
46
|
}
|
|
55
47
|
async getVersions(key) {
|
|
56
|
-
const command = new
|
|
48
|
+
const command = new _aws_sdk_client_s3.ListObjectVersionsCommand({
|
|
57
49
|
Bucket: this.bucket,
|
|
58
50
|
Prefix: key
|
|
59
51
|
});
|
|
@@ -63,42 +55,40 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
63
55
|
createdAt: version.LastModified || /* @__PURE__ */ new Date()
|
|
64
56
|
}));
|
|
65
57
|
}
|
|
66
|
-
async getDownloadURL(file, expiresIn =
|
|
58
|
+
async getDownloadURL(file, expiresIn = 3600) {
|
|
67
59
|
const cacheKey = `download-url:${file.path}`;
|
|
68
60
|
const cachedURL = await this.cache?.get(cacheKey);
|
|
69
61
|
if (cachedURL) return cachedURL;
|
|
70
62
|
const command = this.createGetObjectCommand(file);
|
|
71
|
-
const url = await (0,
|
|
63
|
+
const url = await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn });
|
|
72
64
|
const cacheExpiration = Math.max(expiresIn - 60, 0);
|
|
73
65
|
if (cacheExpiration) await this.cache?.set(cacheKey, url, cacheExpiration);
|
|
74
66
|
return url;
|
|
75
67
|
}
|
|
76
|
-
async getUploadURL(params, expiresIn =
|
|
77
|
-
const command = new
|
|
68
|
+
async getUploadURL(params, expiresIn = 3600) {
|
|
69
|
+
const command = new _aws_sdk_client_s3.PutObjectCommand({
|
|
78
70
|
Bucket: this.bucket,
|
|
79
71
|
Key: params.path,
|
|
80
72
|
ContentType: params.contentType,
|
|
81
73
|
ContentLength: params.contentLength
|
|
82
74
|
});
|
|
83
|
-
return (0,
|
|
75
|
+
return (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn });
|
|
84
76
|
}
|
|
85
77
|
async getUpload(params, expiresIn = 5) {
|
|
86
78
|
const { path } = params;
|
|
87
|
-
const { fields: values, url } = await (0,
|
|
79
|
+
const { fields: values, url } = await (0, _aws_sdk_s3_presigned_post.createPresignedPost)(this.client, {
|
|
88
80
|
Expires: expiresIn * 60,
|
|
89
81
|
Bucket: this.bucket,
|
|
90
82
|
Fields: { acl: this.acl },
|
|
91
83
|
Conditions: [],
|
|
92
84
|
Key: path
|
|
93
85
|
});
|
|
94
|
-
const keys = Object.keys(values);
|
|
95
|
-
const fields = keys.map((key) => ({
|
|
96
|
-
key,
|
|
97
|
-
value: values[key] || ""
|
|
98
|
-
}));
|
|
99
86
|
return {
|
|
100
87
|
url,
|
|
101
|
-
fields
|
|
88
|
+
fields: Object.keys(values).map((key) => ({
|
|
89
|
+
key,
|
|
90
|
+
value: values[key] || ""
|
|
91
|
+
}))
|
|
102
92
|
};
|
|
103
93
|
}
|
|
104
94
|
async upload(key, data, contentType) {
|
|
@@ -109,31 +99,36 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
109
99
|
Body,
|
|
110
100
|
ContentType: contentType
|
|
111
101
|
};
|
|
112
|
-
const command = new
|
|
102
|
+
const command = new _aws_sdk_client_s3.PutObjectCommand(params);
|
|
113
103
|
await this.client.send(command);
|
|
114
104
|
}
|
|
115
105
|
async delete(key) {
|
|
116
|
-
const command = new
|
|
106
|
+
const command = new _aws_sdk_client_s3.DeleteObjectCommand({
|
|
117
107
|
Bucket: this.bucket,
|
|
118
108
|
Key: key
|
|
119
109
|
});
|
|
120
110
|
await this.client.send(command);
|
|
121
111
|
}
|
|
122
112
|
};
|
|
123
|
-
let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList
|
|
124
|
-
AmazonCannedAccessControlList
|
|
125
|
-
AmazonCannedAccessControlList
|
|
126
|
-
AmazonCannedAccessControlList
|
|
127
|
-
AmazonCannedAccessControlList
|
|
128
|
-
AmazonCannedAccessControlList
|
|
129
|
-
AmazonCannedAccessControlList
|
|
130
|
-
AmazonCannedAccessControlList
|
|
131
|
-
AmazonCannedAccessControlList
|
|
132
|
-
return AmazonCannedAccessControlList
|
|
113
|
+
let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList) {
|
|
114
|
+
AmazonCannedAccessControlList["AuthenticatedRead"] = "authenticated-read";
|
|
115
|
+
AmazonCannedAccessControlList["Private"] = "private";
|
|
116
|
+
AmazonCannedAccessControlList["PublicRead"] = "public-read";
|
|
117
|
+
AmazonCannedAccessControlList["PublicReadWrite"] = "public-read-write";
|
|
118
|
+
AmazonCannedAccessControlList["AwsExecRead"] = "aws-exec-read";
|
|
119
|
+
AmazonCannedAccessControlList["BucketOwnerRead"] = "bucket-owner-read";
|
|
120
|
+
AmazonCannedAccessControlList["BucketOwnerFullControl"] = "bucket-owner-full-control";
|
|
121
|
+
AmazonCannedAccessControlList["LogDeliveryWrite"] = "log-delivery-write";
|
|
122
|
+
return AmazonCannedAccessControlList;
|
|
133
123
|
}({});
|
|
134
|
-
|
|
135
124
|
//#endregion
|
|
136
125
|
//#region src/s3Driver.ts
|
|
126
|
+
/**
|
|
127
|
+
* The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.
|
|
128
|
+
*
|
|
129
|
+
* Registered by whoever assembles the application, so neutral code can build a
|
|
130
|
+
* client from a URL without importing this file or the AWS SDK behind it.
|
|
131
|
+
*/
|
|
137
132
|
const s3Driver = {
|
|
138
133
|
scheme: "s3:",
|
|
139
134
|
create(url) {
|
|
@@ -146,15 +141,15 @@ const s3Driver = {
|
|
|
146
141
|
});
|
|
147
142
|
}
|
|
148
143
|
};
|
|
149
|
-
|
|
150
144
|
//#endregion
|
|
151
145
|
exports.AmazonCannedAccessControlList = AmazonCannedAccessControlList;
|
|
152
146
|
exports.AmazonStorageClient = AmazonStorageClient;
|
|
153
147
|
exports.s3Driver = s3Driver;
|
|
154
|
-
Object.defineProperty(exports,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
148
|
+
Object.defineProperty(exports, "s3Url", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function() {
|
|
151
|
+
return require_s3Url.s3Url_exports;
|
|
152
|
+
}
|
|
159
153
|
});
|
|
154
|
+
|
|
160
155
|
//# sourceMappingURL=aws.cjs.map
|
package/dist/aws.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.cjs","names":["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","s3Driver: StorageDriver"],"sources":["../src/StorageClient.ts","../src/AmazonStorageClient.ts","../src/s3Driver.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","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","/**\n * The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.\n *\n * Registered by whoever assembles the application, so neutral code can build a\n * client from a URL without importing this file or the AWS SDK behind it.\n */\n\nimport { AmazonStorageClient } from './AmazonStorageClient';\nimport type { StorageDriver } from './registry';\nimport { parse } from './s3Url';\n\nexport const s3Driver: StorageDriver = {\n\tscheme: 's3:',\n\tcreate(url) {\n\t\tconst { bucket, region, endpoint, forcePathStyle } = parse(url);\n\t\treturn AmazonStorageClient.create({\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\n\t},\n};\n"],"mappings":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M,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;;;;ACxLD,MAAaC,WAA0B;CACtC,QAAQ;CACR,OAAO,KAAK;EACX,MAAM,EAAE,QAAQ,QAAQ,UAAU,gBAAgB,GAAG,oBAAM,IAAI;AAC/D,SAAO,oBAAoB,OAAO;GACjC;GACA;GACA;GACA;EACA,EAAC;CACF;AACD"}
|
|
1
|
+
{"version":3,"file":"aws.cjs","names":["S3Client","GetObjectCommand","getSignedUrl","ListObjectVersionsCommand","PutObjectCommand","createPresignedPost","DeleteObjectCommand","parse"],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.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","/**\n * The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.\n *\n * Registered by whoever assembles the application, so neutral code can build a\n * client from a URL without importing this file or the AWS SDK behind it.\n */\n\nimport { AmazonStorageClient } from './AmazonStorageClient';\nimport type { StorageDriver } from './registry';\nimport { parse } from './s3Url';\n\nexport const s3Driver: StorageDriver = {\n\tscheme: 's3:',\n\tcreate(url) {\n\t\tconst { bucket, region, endpoint, forcePathStyle } = parse(url);\n\t\treturn AmazonStorageClient.create({\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\n\t},\n};\n"],"mappings":";;;;;;AAoBA,IAAa,sBAAb,MAAa,oBAA6C;CA+BvC;CACA;CACA;CACR;CAjCV,WAAS;CAET,OAAO,OACN,SACsB;EACtB,MAAM,EACL,QACA,QACA,aACA,KACA,UACA,iBACA,iBAAiB,OACjB,UACG;EAMJ,MAAM,SAAS,IAAIA,mBAAAA,SAAS;GAC3B;GACA,aAPsB,eAAe,kBAEnC;IAAE;IAAa;GAAgB,IAC/B,KAAA;GAKF;GACA;E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AA;CACA,8BAAA,gBAAA;CACA,8BAAA,qBAAA;CACA,8BAAA,iBAAA;CACA,8BAAA,qBAAA;CACA,8BAAA,4BAAA;CACA,8BAAA,sBAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;ACxLA,MAAa,WAA0B;CACtC,QAAQ;CACR,OAAO,KAAK;EACX,MAAM,EAAE,QAAQ,QAAQ,UAAU,mBAAmBC,cAAAA,MAAM,GAAG;EAC9D,OAAO,oBAAoB,OAAO;GACjC;GACA;GACA;GACA;EACD,CAAC;CACF;AACD"}
|
package/dist/aws.d.cts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as DocumentVersion, c as GetUploadResponse, l as StorageClient, o as File, s as GetUploadParams, t as StorageDriver, u as StorageProvider } from "./registry-ClEvHGpM.cjs";
|
|
2
|
+
import { S3Address, t as s3Url_d_exports } from "./s3Url.cjs";
|
|
3
3
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
4
4
|
import { Cache } from "@geekmidas/cache";
|
|
5
|
-
|
|
6
5
|
//#region src/AmazonStorageClient.d.ts
|
|
7
|
-
declare class AmazonStorageClient implements StorageClient {
|
|
6
|
+
export declare class AmazonStorageClient implements StorageClient {
|
|
8
7
|
private readonly client;
|
|
9
8
|
private readonly bucket;
|
|
10
9
|
private readonly acl;
|
|
@@ -21,7 +20,7 @@ declare class AmazonStorageClient implements StorageClient {
|
|
|
21
20
|
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
22
21
|
delete(key: string): Promise<void>;
|
|
23
22
|
}
|
|
24
|
-
declare enum AmazonCannedAccessControlList {
|
|
23
|
+
export declare enum AmazonCannedAccessControlList {
|
|
25
24
|
AuthenticatedRead = "authenticated-read",
|
|
26
25
|
Private = "private",
|
|
27
26
|
PublicRead = "public-read",
|
|
@@ -29,7 +28,7 @@ declare enum AmazonCannedAccessControlList {
|
|
|
29
28
|
AwsExecRead = "aws-exec-read",
|
|
30
29
|
BucketOwnerRead = "bucket-owner-read",
|
|
31
30
|
BucketOwnerFullControl = "bucket-owner-full-control",
|
|
32
|
-
LogDeliveryWrite = "log-delivery-write"
|
|
31
|
+
LogDeliveryWrite = "log-delivery-write"
|
|
33
32
|
}
|
|
34
33
|
interface AmazonStorageClientCreateOptions {
|
|
35
34
|
bucket: string;
|
|
@@ -43,9 +42,7 @@ interface AmazonStorageClientCreateOptions {
|
|
|
43
42
|
}
|
|
44
43
|
//#endregion
|
|
45
44
|
//#region src/s3Driver.d.ts
|
|
46
|
-
declare const s3Driver: StorageDriver;
|
|
47
|
-
//# sourceMappingURL=s3Driver.d.ts.map
|
|
48
|
-
|
|
45
|
+
export declare const s3Driver: StorageDriver;
|
|
49
46
|
//#endregion
|
|
50
|
-
export {
|
|
47
|
+
export { type DocumentVersion, type File, type GetUploadParams, type GetUploadResponse, type S3Address, type StorageClient, s3Url_d_exports as s3Url };
|
|
51
48
|
//# sourceMappingURL=aws.d.cts.map
|
package/dist/aws.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.cts","names":[],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.ts"],"
|
|
1
|
+
{"version":3,"file":"aws.d.cts","names":[],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.ts"],"mappings":";;;;;qBAoBa,+BAA+B;mBA+BzB;mBACA;mBACA;WACR,QAAQ;WAjCT,WAAQ,gBAAA;SAEV,OACN,SAAS,mCACP;EAyBH,YACkB,QAAQ,UACR,gBACA,MAAG,+BACX,QAAQ;UAGV;EAqBR,sBAAsB,MAAM,MAAM,oBAAoB;EAKhD,YAAY,cAAc,QAAQ;EAclC,eAAe,MAAM,MAAM,qBAAsB;EAmBjD,aACL,QAAQ,iBACR,qBACE;EAWG,UACL,QAAQ,iBACR,qBACE,QAAQ;EAwBL,OACL,aACA,eAAe,QACf,sBACE;EAeG,OAAO,cAAc;;oBAUhB;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGS;EACT;EACA;EACA,MAAM;EACN;EACA;EACA;EACA;EACA,QAAQ;;;;qBClMI,UAAU"}
|
package/dist/aws.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { DocumentVersion,
|
|
2
|
-
import { S3Address, s3Url_d_exports } from "./s3Url
|
|
1
|
+
import { a as DocumentVersion, c as GetUploadResponse, l as StorageClient, o as File, s as GetUploadParams, t as StorageDriver, u as StorageProvider } from "./registry-ClEvHGpM.mjs";
|
|
2
|
+
import { S3Address, t as s3Url_d_exports } from "./s3Url.mjs";
|
|
3
3
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
4
4
|
import { Cache } from "@geekmidas/cache";
|
|
5
|
-
|
|
6
5
|
//#region src/AmazonStorageClient.d.ts
|
|
7
|
-
declare class AmazonStorageClient implements StorageClient {
|
|
6
|
+
export declare class AmazonStorageClient implements StorageClient {
|
|
8
7
|
private readonly client;
|
|
9
8
|
private readonly bucket;
|
|
10
9
|
private readonly acl;
|
|
@@ -21,7 +20,7 @@ declare class AmazonStorageClient implements StorageClient {
|
|
|
21
20
|
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
22
21
|
delete(key: string): Promise<void>;
|
|
23
22
|
}
|
|
24
|
-
declare enum AmazonCannedAccessControlList {
|
|
23
|
+
export declare enum AmazonCannedAccessControlList {
|
|
25
24
|
AuthenticatedRead = "authenticated-read",
|
|
26
25
|
Private = "private",
|
|
27
26
|
PublicRead = "public-read",
|
|
@@ -29,7 +28,7 @@ declare enum AmazonCannedAccessControlList {
|
|
|
29
28
|
AwsExecRead = "aws-exec-read",
|
|
30
29
|
BucketOwnerRead = "bucket-owner-read",
|
|
31
30
|
BucketOwnerFullControl = "bucket-owner-full-control",
|
|
32
|
-
LogDeliveryWrite = "log-delivery-write"
|
|
31
|
+
LogDeliveryWrite = "log-delivery-write"
|
|
33
32
|
}
|
|
34
33
|
interface AmazonStorageClientCreateOptions {
|
|
35
34
|
bucket: string;
|
|
@@ -43,9 +42,7 @@ interface AmazonStorageClientCreateOptions {
|
|
|
43
42
|
}
|
|
44
43
|
//#endregion
|
|
45
44
|
//#region src/s3Driver.d.ts
|
|
46
|
-
declare const s3Driver: StorageDriver;
|
|
47
|
-
//# sourceMappingURL=s3Driver.d.ts.map
|
|
48
|
-
|
|
45
|
+
export declare const s3Driver: StorageDriver;
|
|
49
46
|
//#endregion
|
|
50
|
-
export {
|
|
47
|
+
export { type DocumentVersion, type File, type GetUploadParams, type GetUploadResponse, type S3Address, type StorageClient, s3Url_d_exports as s3Url };
|
|
51
48
|
//# sourceMappingURL=aws.d.mts.map
|
package/dist/aws.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.mts","names":[],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.ts"],"
|
|
1
|
+
{"version":3,"file":"aws.d.mts","names":[],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.ts"],"mappings":";;;;;qBAoBa,+BAA+B;mBA+BzB;mBACA;mBACA;WACR,QAAQ;WAjCT,WAAQ,gBAAA;SAEV,OACN,SAAS,mCACP;EAyBH,YACkB,QAAQ,UACR,gBACA,MAAG,+BACX,QAAQ;UAGV;EAqBR,sBAAsB,MAAM,MAAM,oBAAoB;EAKhD,YAAY,cAAc,QAAQ;EAclC,eAAe,MAAM,MAAM,qBAAsB;EAmBjD,aACL,QAAQ,iBACR,qBACE;EAWG,UACL,QAAQ,iBACR,qBACE,QAAQ;EAwBL,OACL,aACA,eAAe,QACf,sBACE;EAeG,OAAO,cAAc;;oBAUhB;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGS;EACT;EACA;EACA,MAAM;EACN;EACA;EACA;EACA;EACA,QAAQ;;;;qBClMI,UAAU"}
|
package/dist/aws.mjs
CHANGED
|
@@ -1,37 +1,28 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { parse, s3Url_exports } from "./s3Url-C8FGPNrG.mjs";
|
|
1
|
+
import { parse, t as s3Url_exports } from "./s3Url.mjs";
|
|
3
2
|
import { DeleteObjectCommand, GetObjectCommand, ListObjectVersionsCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
4
3
|
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
|
|
5
4
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
6
|
-
|
|
7
|
-
//#region src/StorageClient.ts
|
|
8
|
-
let StorageProvider = /* @__PURE__ */ function(StorageProvider$1) {
|
|
9
|
-
StorageProvider$1["AWSS3"] = "geekimdas.toolbox.storage.aws.s3";
|
|
10
|
-
StorageProvider$1["GCP"] = "geekimdas.toolbox.storage.gcp";
|
|
11
|
-
StorageProvider$1["AZURE"] = "geekimdas.toolbox.storage.azure";
|
|
12
|
-
return StorageProvider$1;
|
|
13
|
-
}({});
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
5
|
//#region src/AmazonStorageClient.ts
|
|
17
6
|
var AmazonStorageClient = class AmazonStorageClient {
|
|
18
|
-
|
|
7
|
+
client;
|
|
8
|
+
bucket;
|
|
9
|
+
acl;
|
|
10
|
+
cache;
|
|
11
|
+
provider = "geekimdas.toolbox.storage.aws.s3";
|
|
19
12
|
static create(options) {
|
|
20
13
|
const { bucket, region, accessKeyId, acl, endpoint, secretAccessKey, forcePathStyle = false, cache } = options;
|
|
21
|
-
const hasCredentials = accessKeyId && secretAccessKey;
|
|
22
|
-
const credentials = hasCredentials ? {
|
|
23
|
-
accessKeyId,
|
|
24
|
-
secretAccessKey
|
|
25
|
-
} : void 0;
|
|
26
14
|
const client = new S3Client({
|
|
27
15
|
region,
|
|
28
|
-
credentials
|
|
16
|
+
credentials: accessKeyId && secretAccessKey ? {
|
|
17
|
+
accessKeyId,
|
|
18
|
+
secretAccessKey
|
|
19
|
+
} : void 0,
|
|
29
20
|
endpoint,
|
|
30
21
|
forcePathStyle
|
|
31
22
|
});
|
|
32
23
|
return new AmazonStorageClient(client, bucket, acl, cache);
|
|
33
24
|
}
|
|
34
|
-
constructor(client, bucket, acl =
|
|
25
|
+
constructor(client, bucket, acl = "authenticated-read", cache) {
|
|
35
26
|
this.client = client;
|
|
36
27
|
this.bucket = bucket;
|
|
37
28
|
this.acl = acl;
|
|
@@ -50,7 +41,7 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
50
41
|
}
|
|
51
42
|
getVersionDownloadURL(file, versionId) {
|
|
52
43
|
const command = this.createGetObjectCommand(file, { VersionId: versionId });
|
|
53
|
-
return getSignedUrl(this.client, command, { expiresIn:
|
|
44
|
+
return getSignedUrl(this.client, command, { expiresIn: 86400 });
|
|
54
45
|
}
|
|
55
46
|
async getVersions(key) {
|
|
56
47
|
const command = new ListObjectVersionsCommand({
|
|
@@ -63,7 +54,7 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
63
54
|
createdAt: version.LastModified || /* @__PURE__ */ new Date()
|
|
64
55
|
}));
|
|
65
56
|
}
|
|
66
|
-
async getDownloadURL(file, expiresIn =
|
|
57
|
+
async getDownloadURL(file, expiresIn = 3600) {
|
|
67
58
|
const cacheKey = `download-url:${file.path}`;
|
|
68
59
|
const cachedURL = await this.cache?.get(cacheKey);
|
|
69
60
|
if (cachedURL) return cachedURL;
|
|
@@ -73,7 +64,7 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
73
64
|
if (cacheExpiration) await this.cache?.set(cacheKey, url, cacheExpiration);
|
|
74
65
|
return url;
|
|
75
66
|
}
|
|
76
|
-
async getUploadURL(params, expiresIn =
|
|
67
|
+
async getUploadURL(params, expiresIn = 3600) {
|
|
77
68
|
const command = new PutObjectCommand({
|
|
78
69
|
Bucket: this.bucket,
|
|
79
70
|
Key: params.path,
|
|
@@ -91,14 +82,12 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
91
82
|
Conditions: [],
|
|
92
83
|
Key: path
|
|
93
84
|
});
|
|
94
|
-
const keys = Object.keys(values);
|
|
95
|
-
const fields = keys.map((key) => ({
|
|
96
|
-
key,
|
|
97
|
-
value: values[key] || ""
|
|
98
|
-
}));
|
|
99
85
|
return {
|
|
100
86
|
url,
|
|
101
|
-
fields
|
|
87
|
+
fields: Object.keys(values).map((key) => ({
|
|
88
|
+
key,
|
|
89
|
+
value: values[key] || ""
|
|
90
|
+
}))
|
|
102
91
|
};
|
|
103
92
|
}
|
|
104
93
|
async upload(key, data, contentType) {
|
|
@@ -120,20 +109,25 @@ var AmazonStorageClient = class AmazonStorageClient {
|
|
|
120
109
|
await this.client.send(command);
|
|
121
110
|
}
|
|
122
111
|
};
|
|
123
|
-
let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList
|
|
124
|
-
AmazonCannedAccessControlList
|
|
125
|
-
AmazonCannedAccessControlList
|
|
126
|
-
AmazonCannedAccessControlList
|
|
127
|
-
AmazonCannedAccessControlList
|
|
128
|
-
AmazonCannedAccessControlList
|
|
129
|
-
AmazonCannedAccessControlList
|
|
130
|
-
AmazonCannedAccessControlList
|
|
131
|
-
AmazonCannedAccessControlList
|
|
132
|
-
return AmazonCannedAccessControlList
|
|
112
|
+
let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessControlList) {
|
|
113
|
+
AmazonCannedAccessControlList["AuthenticatedRead"] = "authenticated-read";
|
|
114
|
+
AmazonCannedAccessControlList["Private"] = "private";
|
|
115
|
+
AmazonCannedAccessControlList["PublicRead"] = "public-read";
|
|
116
|
+
AmazonCannedAccessControlList["PublicReadWrite"] = "public-read-write";
|
|
117
|
+
AmazonCannedAccessControlList["AwsExecRead"] = "aws-exec-read";
|
|
118
|
+
AmazonCannedAccessControlList["BucketOwnerRead"] = "bucket-owner-read";
|
|
119
|
+
AmazonCannedAccessControlList["BucketOwnerFullControl"] = "bucket-owner-full-control";
|
|
120
|
+
AmazonCannedAccessControlList["LogDeliveryWrite"] = "log-delivery-write";
|
|
121
|
+
return AmazonCannedAccessControlList;
|
|
133
122
|
}({});
|
|
134
|
-
|
|
135
123
|
//#endregion
|
|
136
124
|
//#region src/s3Driver.ts
|
|
125
|
+
/**
|
|
126
|
+
* The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.
|
|
127
|
+
*
|
|
128
|
+
* Registered by whoever assembles the application, so neutral code can build a
|
|
129
|
+
* client from a URL without importing this file or the AWS SDK behind it.
|
|
130
|
+
*/
|
|
137
131
|
const s3Driver = {
|
|
138
132
|
scheme: "s3:",
|
|
139
133
|
create(url) {
|
|
@@ -146,7 +140,7 @@ const s3Driver = {
|
|
|
146
140
|
});
|
|
147
141
|
}
|
|
148
142
|
};
|
|
149
|
-
|
|
150
143
|
//#endregion
|
|
151
144
|
export { AmazonCannedAccessControlList, AmazonStorageClient, s3Driver, s3Url_exports as s3Url };
|
|
145
|
+
|
|
152
146
|
//# sourceMappingURL=aws.mjs.map
|
package/dist/aws.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.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","s3Driver: StorageDriver"],"sources":["../src/StorageClient.ts","../src/AmazonStorageClient.ts","../src/s3Driver.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","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","/**\n * The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.\n *\n * Registered by whoever assembles the application, so neutral code can build a\n * client from a URL without importing this file or the AWS SDK behind it.\n */\n\nimport { AmazonStorageClient } from './AmazonStorageClient';\nimport type { StorageDriver } from './registry';\nimport { parse } from './s3Url';\n\nexport const s3Driver: StorageDriver = {\n\tscheme: 's3:',\n\tcreate(url) {\n\t\tconst { bucket, region, endpoint, forcePathStyle } = parse(url);\n\t\treturn AmazonStorageClient.create({\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\n\t},\n};\n"],"mappings":";;;;;;;AAMA,IAAY,8DAAL;AACN;AACA;AACA;;AACA;;;;ACUD,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,EAA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AO,KAAK,OAAO;EAChC,MAAM,SAAS,KAAK,IAAI,CAAC,SAAS;GAAE;GAAK,OAAO,OAAO,QAAQ;EAAI,GAAE;AAErE,SAAO;GAAE;GAAK;EAAQ;CACtB;CAED,MAAM,OACLD,KACAE,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,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;;;;ACxLD,MAAaI,WAA0B;CACtC,QAAQ;CACR,OAAO,KAAK;EACX,MAAM,EAAE,QAAQ,QAAQ,UAAU,gBAAgB,GAAG,MAAM,IAAI;AAC/D,SAAO,oBAAoB,OAAO;GACjC;GACA;GACA;GACA;EACA,EAAC;CACF;AACD"}
|
|
1
|
+
{"version":3,"file":"aws.mjs","names":[],"sources":["../src/AmazonStorageClient.ts","../src/s3Driver.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","/**\n * The S3 driver — `s3://` URLs to an {@link AmazonStorageClient}.\n *\n * Registered by whoever assembles the application, so neutral code can build a\n * client from a URL without importing this file or the AWS SDK behind it.\n */\n\nimport { AmazonStorageClient } from './AmazonStorageClient';\nimport type { StorageDriver } from './registry';\nimport { parse } from './s3Url';\n\nexport const s3Driver: StorageDriver = {\n\tscheme: 's3:',\n\tcreate(url) {\n\t\tconst { bucket, region, endpoint, forcePathStyle } = parse(url);\n\t\treturn AmazonStorageClient.create({\n\t\t\tbucket,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t\tforcePathStyle,\n\t\t});\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GACvC,QAAQ,KAAK;GACb,KAAK;EACN,CAAC;EAED,MAAM,KAAK,OAAO,KAAK,OAAO;CAC/B;AACD;AAEA,IAAY,gCAAL,yBAAA,+BAAA;CACN,8BAAA,uBAAA;CACA,8BAAA,aAAA;CACA,8BAAA,gBAAA;CACA,8BAAA,qBAAA;CACA,8BAAA,iBAAA;CACA,8BAAA,qBAAA;CACA,8BAAA,4BAAA;CACA,8BAAA,sBAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;ACxLA,MAAa,WAA0B;CACtC,QAAQ;CACR,OAAO,KAAK;EACX,MAAM,EAAE,QAAQ,QAAQ,UAAU,mBAAmB,MAAM,GAAG;EAC9D,OAAO,oBAAoB,OAAO;GACjC;GACA;GACA;GACA;EACD,CAAC;CACF;AACD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/errors.ts
|
|
3
2
|
/**
|
|
4
3
|
* Storage errors — shared by every implementation, not just S3.
|
|
@@ -74,36 +73,36 @@ var UnregisteredStorageScheme = class extends StorageUrlError {
|
|
|
74
73
|
this.registered = registered;
|
|
75
74
|
}
|
|
76
75
|
};
|
|
77
|
-
|
|
78
76
|
//#endregion
|
|
79
|
-
Object.defineProperty(exports,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
Object.defineProperty(exports, "MalformedStorageUrl", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return MalformedStorageUrl;
|
|
81
|
+
}
|
|
84
82
|
});
|
|
85
|
-
Object.defineProperty(exports,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
Object.defineProperty(exports, "MissingStorageBucket", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return MissingStorageBucket;
|
|
87
|
+
}
|
|
90
88
|
});
|
|
91
|
-
Object.defineProperty(exports,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
Object.defineProperty(exports, "StorageUrlError", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return StorageUrlError;
|
|
93
|
+
}
|
|
96
94
|
});
|
|
97
|
-
Object.defineProperty(exports,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
Object.defineProperty(exports, "UnexpectedStorageScheme", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return UnexpectedStorageScheme;
|
|
99
|
+
}
|
|
102
100
|
});
|
|
103
|
-
Object.defineProperty(exports,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
Object.defineProperty(exports, "UnregisteredStorageScheme", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return UnregisteredStorageScheme;
|
|
105
|
+
}
|
|
108
106
|
});
|
|
109
|
-
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=errors-Bexjg-j-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-Bexjg-j-.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Storage errors — shared by every implementation, not just S3.\n *\n * A `gs://` or Azure client hits the same three problems as the S3 one: the\n * string is not a URL, it is a URL for a different provider, or it addresses no\n * bucket. Each carries the provider-specific detail as a field, so the type is\n * common while the specifics stay accurate.\n *\n * Messages state the rule, which is constant, and never interpolate the value.\n * An interpolated message cannot be matched on, reads differently every time it\n * is thrown, and carries user input into every log line that touches it.\n */\n\n/** Base for anything wrong with a storage URL, so callers may catch broadly. */\nexport abstract class StorageUrlError extends Error {\n\t/** The URL that could not be used. */\n\treadonly url: string;\n\n\tconstructor(url: string, message: string) {\n\t\tsuper(message);\n\t\tthis.url = url;\n\t\tthis.name = new.target.name;\n\t}\n}\n\n/** The string is not a URL at all. */\nexport class MalformedStorageUrl extends StorageUrlError {\n\tconstructor(url: string) {\n\t\tsuper(url, 'Not a valid URL');\n\t}\n}\n\n/**\n * A URL, but for a different provider — a `gs://` URL reaching the S3 client,\n * or the reverse. The usual cause is a construct resolving against the wrong\n * target, which is worth distinguishing from a malformed string.\n */\nexport class UnexpectedStorageScheme extends StorageUrlError {\n\t/** The scheme this client handles, e.g. `'s3:'`. */\n\treadonly expected: string;\n\t/** The scheme the URL actually carried, e.g. `'gs:'`. */\n\treadonly actual: string;\n\n\tconstructor(url: string, expected: string, actual: string) {\n\t\tsuper(url, 'Storage URL is for a different provider');\n\t\tthis.expected = expected;\n\t\tthis.actual = actual;\n\t}\n}\n\n/**\n * A well-formed URL that addresses no bucket.\n *\n * \"Bucket\" is the term S3 and GCS share; Azure calls the same thing a\n * container. One error covers all three — the word in the message is the\n * common one rather than a new abstraction nobody uses.\n */\nexport class MissingStorageBucket extends StorageUrlError {\n\tconstructor(url: string) {\n\t\tsuper(url, 'Storage URL must address a bucket');\n\t}\n}\n\n/**\n * No driver is registered for the URL's scheme.\n *\n * Usually means the build pinned a driver for a different target, or an entry\n * point registered nothing at all — so the registered schemes are carried\n * alongside, since \"what *is* available\" is the actionable half.\n */\nexport class UnregisteredStorageScheme extends StorageUrlError {\n\t/** The scheme that had no driver, e.g. `'gs:'`. */\n\treadonly scheme: string;\n\t/** What is registered, so the caller can see what was pinned instead. */\n\treadonly registered: readonly string[];\n\n\tconstructor(url: string, scheme: string, registered: readonly string[]) {\n\t\tsuper(url, 'No storage driver is registered for this URL scheme');\n\t\tthis.scheme = scheme;\n\t\tthis.registered = registered;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAsB,kBAAtB,cAA8C,MAAM;;CAEnD;CAEA,YAAY,KAAa,SAAiB;EACzC,MAAM,OAAO;EACb,KAAK,MAAM;EACX,KAAK,OAAO,WAAW;CACxB;AACD;;AAGA,IAAa,sBAAb,cAAyC,gBAAgB;CACxD,YAAY,KAAa;EACxB,MAAM,KAAK,iBAAiB;CAC7B;AACD;;;;;;AAOA,IAAa,0BAAb,cAA6C,gBAAgB;;CAE5D;;CAEA;CAEA,YAAY,KAAa,UAAkB,QAAgB;EAC1D,MAAM,KAAK,yCAAyC;EACpD,KAAK,WAAW;EAChB,KAAK,SAAS;CACf;AACD;;;;;;;;AASA,IAAa,uBAAb,cAA0C,gBAAgB;CACzD,YAAY,KAAa;EACxB,MAAM,KAAK,mCAAmC;CAC/C;AACD;;;;;;;;AASA,IAAa,4BAAb,cAA+C,gBAAgB;;CAE9D;;CAEA;CAEA,YAAY,KAAa,QAAgB,YAA+B;EACvE,MAAM,KAAK,qDAAqD;EAChE,KAAK,SAAS;EACd,KAAK,aAAa;CACnB;AACD"}
|