@strapi/provider-upload-aws-s3 0.0.0-next.ff946d2c25a3e577b47132a357cac2932eb8e635 → 0.0.0-next.ffc36acb308febe288f1a31b62cbbb75b286585c
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/LICENSE +18 -3
- package/README.md +66 -13
- package/dist/index.d.ts +28 -14
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +94 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils.d.ts +5 -15
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +68 -24
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +94 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +18 -14
package/LICENSE
CHANGED
|
@@ -2,7 +2,21 @@ Copyright (c) 2015-present Strapi Solutions SAS
|
|
|
2
2
|
|
|
3
3
|
Portions of the Strapi software are licensed as follows:
|
|
4
4
|
|
|
5
|
-
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined
|
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
|
|
6
|
+
|
|
7
|
+
Enterprise License
|
|
8
|
+
|
|
9
|
+
If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
|
|
10
|
+
https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
|
|
11
|
+
represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
|
|
12
|
+
agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
|
|
13
|
+
Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
|
|
14
|
+
|
|
15
|
+
BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
|
|
16
|
+
IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
|
|
17
|
+
HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
|
|
18
|
+
THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
|
|
19
|
+
IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
|
|
6
20
|
|
|
7
21
|
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
|
8
22
|
|
|
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
|
|
|
18
32
|
The above copyright notice and this permission notice shall be included in all
|
|
19
33
|
copies or substantial portions of the Software.
|
|
20
34
|
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
37
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -49,8 +49,10 @@ module.exports = ({ env }) => ({
|
|
|
49
49
|
baseUrl: env('CDN_URL'),
|
|
50
50
|
rootPath: env('CDN_ROOT_PATH'),
|
|
51
51
|
s3Options: {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
credentials: {
|
|
53
|
+
accessKeyId: env('AWS_ACCESS_KEY_ID'),
|
|
54
|
+
secretAccessKey: env('AWS_ACCESS_SECRET'),
|
|
55
|
+
},
|
|
54
56
|
region: env('AWS_REGION'),
|
|
55
57
|
params: {
|
|
56
58
|
ACL: env('AWS_ACL', 'public-read'),
|
|
@@ -70,11 +72,13 @@ module.exports = ({ env }) => ({
|
|
|
70
72
|
});
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
### Configuration for a private S3 bucket
|
|
75
|
+
### Configuration for a private S3 bucket and signed URLs
|
|
74
76
|
|
|
75
|
-
If your bucket is configured to be private, you will need to set the `ACL` option to `private` in the `params` object. This will ensure
|
|
77
|
+
If your bucket is configured to be private, you will need to set the `ACL` option to `private` in the `params` object. This will ensure file URLs are signed.
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
**Note:** If you are using a CDN, the URLs will not be signed.
|
|
80
|
+
|
|
81
|
+
You can also define the expiration time of the signed URL by setting the `signedUrlExpires` option in the `params` object. The default value is 15 minutes.
|
|
78
82
|
|
|
79
83
|
`./config/plugins.js`
|
|
80
84
|
|
|
@@ -85,12 +89,14 @@ module.exports = ({ env }) => ({
|
|
|
85
89
|
config: {
|
|
86
90
|
provider: 'aws-s3',
|
|
87
91
|
providerOptions: {
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
credentials: {
|
|
93
|
+
accessKeyId: env('AWS_ACCESS_KEY_ID'),
|
|
94
|
+
secretAccessKey: env('AWS_ACCESS_SECRET'),
|
|
95
|
+
},
|
|
90
96
|
region: env('AWS_REGION'),
|
|
91
97
|
params: {
|
|
92
98
|
ACL: 'private', // <== set ACL to private
|
|
93
|
-
signedUrlExpires: env('AWS_SIGNED_URL_EXPIRES',
|
|
99
|
+
signedUrlExpires: env('AWS_SIGNED_URL_EXPIRES', 15 * 60),
|
|
94
100
|
Bucket: env('AWS_BUCKET'),
|
|
95
101
|
},
|
|
96
102
|
},
|
|
@@ -107,7 +113,7 @@ module.exports = ({ env }) => ({
|
|
|
107
113
|
|
|
108
114
|
#### Configuration for S3 compatible services
|
|
109
115
|
|
|
110
|
-
This plugin may work with S3 compatible services by using the `endpoint
|
|
116
|
+
This plugin may work with S3 compatible services by using the `endpoint`. Scaleway example:
|
|
111
117
|
`./config/plugins.js`
|
|
112
118
|
|
|
113
119
|
```js
|
|
@@ -117,9 +123,12 @@ module.exports = ({ env }) => ({
|
|
|
117
123
|
config: {
|
|
118
124
|
provider: 'aws-s3',
|
|
119
125
|
providerOptions: {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
credentials: {
|
|
127
|
+
accessKeyId: env('SCALEWAY_ACCESS_KEY_ID'),
|
|
128
|
+
secretAccessKey: env('SCALEWAY_ACCESS_SECRET'),
|
|
129
|
+
},
|
|
130
|
+
region: env('SCALEWAY_REGION'), // e.g "fr-par"
|
|
131
|
+
endpoint: env('SCALEWAY_ENDPOINT'), // e.g. "https://s3.fr-par.scw.cloud"
|
|
123
132
|
params: {
|
|
124
133
|
Bucket: env('SCALEWAY_BUCKET'),
|
|
125
134
|
},
|
|
@@ -169,7 +178,7 @@ module.exports = [
|
|
|
169
178
|
];
|
|
170
179
|
```
|
|
171
180
|
|
|
172
|
-
If you use dots in your bucket name, the url of the
|
|
181
|
+
If you use dots in your bucket name (`forcePathStyle set to false`), the url of the resource is in directory style (`s3.yourRegion.amazonaws.com/your.bucket.name/image.jpg`) instead of `yourBucketName.s3.yourRegion.amazonaws.com/image.jpg` so in that case the img-src and media-src directives to add will be `s3.yourRegion.amazonaws.com` without the bucket name in the url.
|
|
173
182
|
|
|
174
183
|
## Bucket CORS Configuration
|
|
175
184
|
|
|
@@ -200,3 +209,47 @@ These are the minimum amount of permissions needed for this provider to work.
|
|
|
200
209
|
"s3:PutObjectAcl"
|
|
201
210
|
],
|
|
202
211
|
```
|
|
212
|
+
|
|
213
|
+
## Update to AWS SDK V3 and URL Format Change
|
|
214
|
+
|
|
215
|
+
In the recent update of the `@strapi/provider-upload-aws-s3` plugin, we have transitioned from AWS SDK V2 to AWS SDK V3. This significant update brings along a change in the format of the URLs used in Amazon S3 services.
|
|
216
|
+
|
|
217
|
+
### Understanding the New URL Format
|
|
218
|
+
|
|
219
|
+
AWS SDK V3 adopts the virtual-hosted–style URI format for S3 URLs. This format is recommended by AWS and is likely to become required in the near future, as the path-style URI is being deprecated. More details on this format can be found in the [AWS User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access).
|
|
220
|
+
|
|
221
|
+
### Why the Change?
|
|
222
|
+
|
|
223
|
+
The move to virtual-hosted–style URIs aligns with AWS's recommendation and future-proofing strategies. For an in-depth understanding of AWS's decision behind this transition, you can refer to their detailed post [here](https://aws.amazon.com/es/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/).
|
|
224
|
+
|
|
225
|
+
### Configuring Your Strapi Application
|
|
226
|
+
|
|
227
|
+
If you wish to continue using the plugin with Strapi 4.15.x versions or newer without changing your URL format, it's possible to specify your desired URL format directly in the plugin's configuration. Below is an example configuration highlighting the critical `baseUrl` property:
|
|
228
|
+
|
|
229
|
+
```javascript
|
|
230
|
+
upload: {
|
|
231
|
+
config: {
|
|
232
|
+
provider: 'aws-s3',
|
|
233
|
+
providerOptions: {
|
|
234
|
+
credentials: {
|
|
235
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
236
|
+
secretAccessKey: process.env.AWS_ACCESS_SECRET,
|
|
237
|
+
},
|
|
238
|
+
region: process.env.AWS_REGION,
|
|
239
|
+
baseUrl: `https://s3.${region}.amazonaws.com/${bucket}`, // This line sets the custom url format
|
|
240
|
+
params: {
|
|
241
|
+
ACL: process.env.AWS_ACL || 'public-read',
|
|
242
|
+
signedUrlExpires: process.env.AWS_SIGNED_URL_EXPIRES || 15 * 60,
|
|
243
|
+
Bucket: process.env.AWS_BUCKET,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
actionOptions: {
|
|
247
|
+
upload: {},
|
|
248
|
+
uploadStream: {},
|
|
249
|
+
delete: {},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This configuration ensures compatibility with the updated AWS SDK while providing flexibility in URL format selection, catering to various user needs.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type { ReadStream } from 'node:fs';
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import { DeleteObjectCommandOutput, CompleteMultipartUploadCommandOutput, AbortMultipartUploadCommandOutput, S3ClientConfig, ObjectCannedACL } from '@aws-sdk/client-s3';
|
|
5
|
+
import type { AwsCredentialIdentity } from '@aws-sdk/types';
|
|
6
|
+
export interface File {
|
|
6
7
|
name: string;
|
|
7
8
|
alternativeText?: string;
|
|
8
9
|
caption?: string;
|
|
@@ -13,6 +14,7 @@ interface File {
|
|
|
13
14
|
ext?: string;
|
|
14
15
|
mime: string;
|
|
15
16
|
size: number;
|
|
17
|
+
sizeInBytes: number;
|
|
16
18
|
url: string;
|
|
17
19
|
previewUrl?: string;
|
|
18
20
|
path?: string;
|
|
@@ -21,26 +23,38 @@ interface File {
|
|
|
21
23
|
stream?: ReadStream;
|
|
22
24
|
buffer?: Buffer;
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
export type UploadCommandOutput = (CompleteMultipartUploadCommandOutput | AbortMultipartUploadCommandOutput) & {
|
|
27
|
+
Location: string;
|
|
28
|
+
};
|
|
29
|
+
export interface AWSParams {
|
|
30
|
+
Bucket: string;
|
|
31
|
+
ACL?: ObjectCannedACL;
|
|
32
|
+
signedUrlExpires?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface DefaultOptions extends S3ClientConfig {
|
|
35
|
+
accessKeyId?: AwsCredentialIdentity['accessKeyId'];
|
|
36
|
+
secretAccessKey?: AwsCredentialIdentity['secretAccessKey'];
|
|
37
|
+
credentials?: AwsCredentialIdentity;
|
|
38
|
+
params?: AWSParams;
|
|
39
|
+
[k: string]: any;
|
|
40
|
+
}
|
|
41
|
+
export type InitOptions = (DefaultOptions | {
|
|
42
|
+
s3Options: DefaultOptions;
|
|
43
|
+
}) & {
|
|
25
44
|
baseUrl?: string;
|
|
26
45
|
rootPath?: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Bucket: string;
|
|
30
|
-
ACL?: string;
|
|
31
|
-
signedUrlExpires?: string;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
}
|
|
46
|
+
[k: string]: any;
|
|
47
|
+
};
|
|
35
48
|
declare const _default: {
|
|
36
49
|
init({ baseUrl, rootPath, s3Options, ...legacyS3Options }: InitOptions): {
|
|
37
50
|
isPrivate(): boolean;
|
|
38
|
-
getSignedUrl(file: File): Promise<{
|
|
51
|
+
getSignedUrl(file: File, customParams: any): Promise<{
|
|
39
52
|
url: string;
|
|
40
53
|
}>;
|
|
41
54
|
uploadStream(file: File, customParams?: {}): Promise<void>;
|
|
42
55
|
upload(file: File, customParams?: {}): Promise<void>;
|
|
43
|
-
delete(file: File, customParams?: {}): Promise<
|
|
56
|
+
delete(file: File, customParams?: {}): Promise<DeleteObjectCommandOutput>;
|
|
44
57
|
};
|
|
45
58
|
};
|
|
46
|
-
export
|
|
59
|
+
export default _default;
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,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,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAe,SAAQ,cAAc;IAEpD,WAAW,CAAC,EAAE,qBAAqB,CAAC,aAAa,CAAC,CAAC;IACnD,eAAe,CAAC,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IAE3D,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,cAAc,GAAG;IAAE,SAAS,EAAE,cAAc,CAAA;CAAE,CAAC,GAAG;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;;+DA0B2D,WAAW;;2BAwCzC,IAAI,gBAAgB,GAAG,GAAG,QAAQ;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;2BAsBxD,IAAI;qBAGV,IAAI;qBAGJ,IAAI,sBAAsB,QAAQ,yBAAyB,CAAC;;;AArE/E,wBA+EE"}
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require('aws-sdk/lib/maintenance_mode_message').suppress = true;
|
|
11
|
-
function hasUrlProtocol(url) {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fp = require('lodash/fp');
|
|
4
|
+
var clientS3 = require('@aws-sdk/client-s3');
|
|
5
|
+
var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
|
|
6
|
+
var libStorage = require('@aws-sdk/lib-storage');
|
|
7
|
+
var utils = require('./utils.js');
|
|
8
|
+
|
|
9
|
+
const assertUrlProtocol = (url)=>{
|
|
12
10
|
// Regex to test protocol like "http://", "https://"
|
|
13
11
|
return /^\w*:\/\//.test(url);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
};
|
|
13
|
+
const getConfig = ({ baseUrl, rootPath, s3Options, ...legacyS3Options })=>{
|
|
14
|
+
if (Object.keys(legacyS3Options).length > 0) {
|
|
15
|
+
process.emitWarning("S3 configuration options passed at root level of the plugin's providerOptions is deprecated and will be removed in a future release. Please wrap them inside the 's3Options:{}' property.");
|
|
16
|
+
}
|
|
17
|
+
const credentials = utils.extractCredentials({
|
|
18
|
+
s3Options,
|
|
19
|
+
...legacyS3Options
|
|
20
|
+
});
|
|
21
|
+
const config = {
|
|
22
|
+
...s3Options,
|
|
23
|
+
...legacyS3Options,
|
|
24
|
+
...credentials ? {
|
|
25
|
+
credentials
|
|
26
|
+
} : {}
|
|
27
|
+
};
|
|
28
|
+
config.params.ACL = fp.getOr(clientS3.ObjectCannedACL.public_read, [
|
|
29
|
+
'params',
|
|
30
|
+
'ACL'
|
|
31
|
+
], config);
|
|
32
|
+
return config;
|
|
33
|
+
};
|
|
34
|
+
var index = {
|
|
35
|
+
init ({ baseUrl, rootPath, s3Options, ...legacyS3Options }) {
|
|
36
|
+
// TODO V5 change config structure to avoid having to do this
|
|
37
|
+
const config = getConfig({
|
|
38
|
+
baseUrl,
|
|
39
|
+
rootPath,
|
|
40
|
+
s3Options,
|
|
41
|
+
...legacyS3Options
|
|
24
42
|
});
|
|
43
|
+
const s3Client = new clientS3.S3Client(config);
|
|
25
44
|
const filePrefix = rootPath ? `${rootPath.replace(/\/+$/, '')}/` : '';
|
|
26
|
-
const getFileKey = (file)
|
|
45
|
+
const getFileKey = (file)=>{
|
|
27
46
|
const path = file.path ? `${file.path}/` : '';
|
|
28
47
|
return `${filePrefix}${path}${file.hash}${file.ext}`;
|
|
29
48
|
};
|
|
30
|
-
const
|
|
31
|
-
const upload = (file, customParams = {}) => new Promise((resolve, reject) => {
|
|
49
|
+
const upload = async (file, customParams = {})=>{
|
|
32
50
|
const fileKey = getFileKey(file);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ContentType: file.mime,
|
|
43
|
-
...customParams,
|
|
44
|
-
};
|
|
45
|
-
const onUploaded = (err, data) => {
|
|
46
|
-
if (err) {
|
|
47
|
-
return reject(err);
|
|
48
|
-
}
|
|
49
|
-
// set the bucket file url
|
|
50
|
-
if (baseUrl) {
|
|
51
|
-
// Construct the url with the baseUrl
|
|
52
|
-
file.url = `${baseUrl}/${fileKey}`;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Add the protocol if it is missing
|
|
56
|
-
// Some providers like DigitalOcean Spaces return the url without the protocol
|
|
57
|
-
file.url = hasUrlProtocol(data.Location) ? data.Location : `https://${data.Location}`;
|
|
51
|
+
const uploadObj = new libStorage.Upload({
|
|
52
|
+
client: s3Client,
|
|
53
|
+
params: {
|
|
54
|
+
Bucket: config.params.Bucket,
|
|
55
|
+
Key: fileKey,
|
|
56
|
+
Body: file.stream || Buffer.from(file.buffer, 'binary'),
|
|
57
|
+
ACL: config.params.ACL,
|
|
58
|
+
ContentType: file.mime,
|
|
59
|
+
...customParams
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
});
|
|
62
|
+
const upload = await uploadObj.done();
|
|
63
|
+
if (assertUrlProtocol(upload.Location)) {
|
|
64
|
+
file.url = baseUrl ? `${baseUrl}/${fileKey}` : upload.Location;
|
|
65
|
+
} else {
|
|
66
|
+
// Default protocol to https protocol
|
|
67
|
+
file.url = `https://${upload.Location}`;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
63
70
|
return {
|
|
64
|
-
isPrivate() {
|
|
65
|
-
return ACL === 'private';
|
|
71
|
+
isPrivate () {
|
|
72
|
+
return config.params.ACL === 'private';
|
|
66
73
|
},
|
|
67
|
-
async getSignedUrl(file) {
|
|
74
|
+
async getSignedUrl (file, customParams) {
|
|
68
75
|
// Do not sign the url if it does not come from the same bucket.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
if (!utils.isUrlFromBucket(file.url, config.params.Bucket, baseUrl)) {
|
|
77
|
+
return {
|
|
78
|
+
url: file.url
|
|
79
|
+
};
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
81
|
+
const fileKey = getFileKey(file);
|
|
82
|
+
const url = await s3RequestPresigner.getSignedUrl(// @ts-expect-error - TODO fix client type
|
|
83
|
+
s3Client, new clientS3.GetObjectCommand({
|
|
84
|
+
Bucket: config.params.Bucket,
|
|
85
|
+
Key: fileKey,
|
|
86
|
+
...customParams
|
|
87
|
+
}), {
|
|
88
|
+
expiresIn: fp.getOr(15 * 60, [
|
|
89
|
+
'params',
|
|
90
|
+
'signedUrlExpires'
|
|
91
|
+
], config)
|
|
85
92
|
});
|
|
93
|
+
return {
|
|
94
|
+
url
|
|
95
|
+
};
|
|
86
96
|
},
|
|
87
|
-
uploadStream(file, customParams = {}) {
|
|
97
|
+
uploadStream (file, customParams = {}) {
|
|
88
98
|
return upload(file, customParams);
|
|
89
99
|
},
|
|
90
|
-
upload(file, customParams = {}) {
|
|
100
|
+
upload (file, customParams = {}) {
|
|
91
101
|
return upload(file, customParams);
|
|
92
102
|
},
|
|
93
|
-
delete(file, customParams = {}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Key: fileKey,
|
|
99
|
-
Bucket: config.params.Bucket,
|
|
100
|
-
...customParams,
|
|
101
|
-
}, (err) => {
|
|
102
|
-
if (err) {
|
|
103
|
-
return reject(err);
|
|
104
|
-
}
|
|
105
|
-
resolve();
|
|
106
|
-
});
|
|
103
|
+
delete (file, customParams = {}) {
|
|
104
|
+
const command = new clientS3.DeleteObjectCommand({
|
|
105
|
+
Bucket: config.params.Bucket,
|
|
106
|
+
Key: getFileKey(file),
|
|
107
|
+
...customParams
|
|
107
108
|
});
|
|
108
|
-
|
|
109
|
+
return s3Client.send(command);
|
|
110
|
+
}
|
|
109
111
|
};
|
|
110
|
-
}
|
|
112
|
+
}
|
|
111
113
|
};
|
|
112
|
-
|
|
114
|
+
|
|
115
|
+
module.exports = index;
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { ReadStream } from 'node:fs';\nimport { getOr } from 'lodash/fp';\nimport {\n S3Client,\n GetObjectCommand,\n DeleteObjectCommand,\n DeleteObjectCommandOutput,\n PutObjectCommandInput,\n CompleteMultipartUploadCommandOutput,\n AbortMultipartUploadCommandOutput,\n S3ClientConfig,\n ObjectCannedACL,\n} from '@aws-sdk/client-s3';\nimport type { AwsCredentialIdentity } from '@aws-sdk/types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport { Upload } from '@aws-sdk/lib-storage';\nimport { extractCredentials, isUrlFromBucket } from './utils';\n\nexport interface File {\n name: string;\n alternativeText?: string;\n caption?: string;\n width?: number;\n height?: number;\n formats?: Record<string, unknown>;\n hash: string;\n ext?: string;\n mime: string;\n size: number;\n sizeInBytes: number;\n url: string;\n previewUrl?: string;\n path?: string;\n provider?: string;\n provider_metadata?: Record<string, unknown>;\n stream?: ReadStream;\n buffer?: Buffer;\n}\n\nexport type UploadCommandOutput = (\n | CompleteMultipartUploadCommandOutput\n | AbortMultipartUploadCommandOutput\n) & {\n Location: string;\n};\n\nexport interface AWSParams {\n Bucket: string; // making it required\n ACL?: ObjectCannedACL;\n signedUrlExpires?: number;\n}\n\nexport interface DefaultOptions extends S3ClientConfig {\n // TODO Remove this in V5\n accessKeyId?: AwsCredentialIdentity['accessKeyId'];\n secretAccessKey?: AwsCredentialIdentity['secretAccessKey'];\n // Keep this for V5\n credentials?: AwsCredentialIdentity;\n params?: AWSParams;\n [k: string]: any;\n}\n\nexport type InitOptions = (DefaultOptions | { s3Options: DefaultOptions }) & {\n baseUrl?: string;\n rootPath?: string;\n [k: string]: any;\n};\n\nconst assertUrlProtocol = (url: string) => {\n // Regex to test protocol like \"http://\", \"https://\"\n return /^\\w*:\\/\\//.test(url);\n};\n\nconst getConfig = ({ baseUrl, rootPath, s3Options, ...legacyS3Options }: InitOptions) => {\n if (Object.keys(legacyS3Options).length > 0) {\n process.emitWarning(\n \"S3 configuration options passed at root level of the plugin's providerOptions is deprecated and will be removed in a future release. Please wrap them inside the 's3Options:{}' property.\"\n );\n }\n const credentials = extractCredentials({ s3Options, ...legacyS3Options });\n const config = {\n ...s3Options,\n ...legacyS3Options,\n ...(credentials ? { credentials } : {}),\n };\n\n config.params.ACL = getOr(ObjectCannedACL.public_read, ['params', 'ACL'], config);\n\n return config;\n};\n\nexport default {\n init({ baseUrl, rootPath, s3Options, ...legacyS3Options }: InitOptions) {\n // TODO V5 change config structure to avoid having to do this\n const config = getConfig({ baseUrl, rootPath, s3Options, ...legacyS3Options });\n const s3Client = new S3Client(config);\n const filePrefix = rootPath ? `${rootPath.replace(/\\/+$/, '')}/` : '';\n\n const getFileKey = (file: File) => {\n const path = file.path ? `${file.path}/` : '';\n return `${filePrefix}${path}${file.hash}${file.ext}`;\n };\n\n const upload = async (file: File, customParams: Partial<PutObjectCommandInput> = {}) => {\n const fileKey = getFileKey(file);\n const uploadObj = new Upload({\n client: s3Client,\n params: {\n Bucket: config.params.Bucket,\n Key: fileKey,\n Body: file.stream || Buffer.from(file.buffer as any, 'binary'),\n ACL: config.params.ACL,\n ContentType: file.mime,\n ...customParams,\n },\n });\n\n const upload = (await uploadObj.done()) as UploadCommandOutput;\n\n if (assertUrlProtocol(upload.Location)) {\n file.url = baseUrl ? `${baseUrl}/${fileKey}` : upload.Location;\n } else {\n // Default protocol to https protocol\n file.url = `https://${upload.Location}`;\n }\n };\n\n return {\n isPrivate() {\n return config.params.ACL === 'private';\n },\n\n async getSignedUrl(file: File, customParams: any): Promise<{ url: string }> {\n // Do not sign the url if it does not come from the same bucket.\n if (!isUrlFromBucket(file.url, config.params.Bucket, baseUrl)) {\n return { url: file.url };\n }\n const fileKey = getFileKey(file);\n\n const url = await getSignedUrl(\n // @ts-expect-error - TODO fix client type\n s3Client,\n new GetObjectCommand({\n Bucket: config.params.Bucket,\n Key: fileKey,\n ...customParams,\n }),\n {\n expiresIn: getOr(15 * 60, ['params', 'signedUrlExpires'], config),\n }\n );\n\n return { url };\n },\n uploadStream(file: File, customParams = {}) {\n return upload(file, customParams);\n },\n upload(file: File, customParams = {}) {\n return upload(file, customParams);\n },\n delete(file: File, customParams = {}): Promise<DeleteObjectCommandOutput> {\n const command = new DeleteObjectCommand({\n Bucket: config.params.Bucket,\n Key: getFileKey(file),\n ...customParams,\n });\n return s3Client.send(command);\n },\n };\n },\n};\n"],"names":["assertUrlProtocol","url","test","getConfig","baseUrl","rootPath","s3Options","legacyS3Options","Object","keys","length","process","emitWarning","credentials","extractCredentials","config","params","ACL","getOr","ObjectCannedACL","public_read","init","s3Client","S3Client","filePrefix","replace","getFileKey","file","path","hash","ext","upload","customParams","fileKey","uploadObj","Upload","client","Bucket","Key","Body","stream","Buffer","from","buffer","ContentType","mime","done","Location","isPrivate","getSignedUrl","isUrlFromBucket","GetObjectCommand","expiresIn","uploadStream","delete","command","DeleteObjectCommand","send"],"mappings":";;;;;;;;AAoEA,MAAMA,oBAAoB,CAACC,GAAAA,GAAAA;;IAEzB,OAAO,WAAA,CAAYC,IAAI,CAACD,GAAAA,CAAAA;AAC1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GAAU,IAAIC,4BAAoB,CAAA;oBACtCnB,MAAQtB,EAAAA,MAAAA,CAAOC,MAAM,CAACqB,MAAM;AAC5BC,oBAAAA,GAAAA,EAAKZ,UAAWC,CAAAA,IAAAA,CAAAA;AAChB,oBAAA,GAAGK;AACL,iBAAA,CAAA;gBACA,OAAOV,QAAAA,CAASmC,IAAI,CAACF,OAAAA,CAAAA;AACvB;AACF,SAAA;AACF;AACF,CAAE;;;;"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getOr } from 'lodash/fp';
|
|
2
|
+
import { S3Client, GetObjectCommand, DeleteObjectCommand, ObjectCannedACL } from '@aws-sdk/client-s3';
|
|
3
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
4
|
+
import { Upload } from '@aws-sdk/lib-storage';
|
|
5
|
+
import { isUrlFromBucket, extractCredentials } from './utils.mjs';
|
|
6
|
+
|
|
7
|
+
const assertUrlProtocol = (url)=>{
|
|
8
|
+
// Regex to test protocol like "http://", "https://"
|
|
9
|
+
return /^\w*:\/\//.test(url);
|
|
10
|
+
};
|
|
11
|
+
const getConfig = ({ baseUrl, rootPath, s3Options, ...legacyS3Options })=>{
|
|
12
|
+
if (Object.keys(legacyS3Options).length > 0) {
|
|
13
|
+
process.emitWarning("S3 configuration options passed at root level of the plugin's providerOptions is deprecated and will be removed in a future release. Please wrap them inside the 's3Options:{}' property.");
|
|
14
|
+
}
|
|
15
|
+
const credentials = extractCredentials({
|
|
16
|
+
s3Options,
|
|
17
|
+
...legacyS3Options
|
|
18
|
+
});
|
|
19
|
+
const config = {
|
|
20
|
+
...s3Options,
|
|
21
|
+
...legacyS3Options,
|
|
22
|
+
...credentials ? {
|
|
23
|
+
credentials
|
|
24
|
+
} : {}
|
|
25
|
+
};
|
|
26
|
+
config.params.ACL = getOr(ObjectCannedACL.public_read, [
|
|
27
|
+
'params',
|
|
28
|
+
'ACL'
|
|
29
|
+
], config);
|
|
30
|
+
return config;
|
|
31
|
+
};
|
|
32
|
+
var index = {
|
|
33
|
+
init ({ baseUrl, rootPath, s3Options, ...legacyS3Options }) {
|
|
34
|
+
// TODO V5 change config structure to avoid having to do this
|
|
35
|
+
const config = getConfig({
|
|
36
|
+
baseUrl,
|
|
37
|
+
rootPath,
|
|
38
|
+
s3Options,
|
|
39
|
+
...legacyS3Options
|
|
40
|
+
});
|
|
41
|
+
const s3Client = new S3Client(config);
|
|
42
|
+
const filePrefix = rootPath ? `${rootPath.replace(/\/+$/, '')}/` : '';
|
|
43
|
+
const getFileKey = (file)=>{
|
|
44
|
+
const path = file.path ? `${file.path}/` : '';
|
|
45
|
+
return `${filePrefix}${path}${file.hash}${file.ext}`;
|
|
46
|
+
};
|
|
47
|
+
const upload = async (file, customParams = {})=>{
|
|
48
|
+
const fileKey = getFileKey(file);
|
|
49
|
+
const uploadObj = new Upload({
|
|
50
|
+
client: s3Client,
|
|
51
|
+
params: {
|
|
52
|
+
Bucket: config.params.Bucket,
|
|
53
|
+
Key: fileKey,
|
|
54
|
+
Body: file.stream || Buffer.from(file.buffer, 'binary'),
|
|
55
|
+
ACL: config.params.ACL,
|
|
56
|
+
ContentType: file.mime,
|
|
57
|
+
...customParams
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const upload = await uploadObj.done();
|
|
61
|
+
if (assertUrlProtocol(upload.Location)) {
|
|
62
|
+
file.url = baseUrl ? `${baseUrl}/${fileKey}` : upload.Location;
|
|
63
|
+
} else {
|
|
64
|
+
// Default protocol to https protocol
|
|
65
|
+
file.url = `https://${upload.Location}`;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
isPrivate () {
|
|
70
|
+
return config.params.ACL === 'private';
|
|
71
|
+
},
|
|
72
|
+
async getSignedUrl (file, customParams) {
|
|
73
|
+
// Do not sign the url if it does not come from the same bucket.
|
|
74
|
+
if (!isUrlFromBucket(file.url, config.params.Bucket, baseUrl)) {
|
|
75
|
+
return {
|
|
76
|
+
url: file.url
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const fileKey = getFileKey(file);
|
|
80
|
+
const url = await getSignedUrl(// @ts-expect-error - TODO fix client type
|
|
81
|
+
s3Client, new GetObjectCommand({
|
|
82
|
+
Bucket: config.params.Bucket,
|
|
83
|
+
Key: fileKey,
|
|
84
|
+
...customParams
|
|
85
|
+
}), {
|
|
86
|
+
expiresIn: getOr(15 * 60, [
|
|
87
|
+
'params',
|
|
88
|
+
'signedUrlExpires'
|
|
89
|
+
], config)
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
url
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
uploadStream (file, customParams = {}) {
|
|
96
|
+
return upload(file, customParams);
|
|
97
|
+
},
|
|
98
|
+
upload (file, customParams = {}) {
|
|
99
|
+
return upload(file, customParams);
|
|
100
|
+
},
|
|
101
|
+
delete (file, customParams = {}) {
|
|
102
|
+
const command = new DeleteObjectCommand({
|
|
103
|
+
Bucket: config.params.Bucket,
|
|
104
|
+
Key: getFileKey(file),
|
|
105
|
+
...customParams
|
|
106
|
+
});
|
|
107
|
+
return s3Client.send(command);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { index as default };
|
|
114
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { ReadStream } from 'node:fs';\nimport { getOr } from 'lodash/fp';\nimport {\n S3Client,\n GetObjectCommand,\n DeleteObjectCommand,\n DeleteObjectCommandOutput,\n PutObjectCommandInput,\n CompleteMultipartUploadCommandOutput,\n AbortMultipartUploadCommandOutput,\n S3ClientConfig,\n ObjectCannedACL,\n} from '@aws-sdk/client-s3';\nimport type { AwsCredentialIdentity } from '@aws-sdk/types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport { Upload } from '@aws-sdk/lib-storage';\nimport { extractCredentials, isUrlFromBucket } from './utils';\n\nexport interface File {\n name: string;\n alternativeText?: string;\n caption?: string;\n width?: number;\n height?: number;\n formats?: Record<string, unknown>;\n hash: string;\n ext?: string;\n mime: string;\n size: number;\n sizeInBytes: number;\n url: string;\n previewUrl?: string;\n path?: string;\n provider?: string;\n provider_metadata?: Record<string, unknown>;\n stream?: ReadStream;\n buffer?: Buffer;\n}\n\nexport type UploadCommandOutput = (\n | CompleteMultipartUploadCommandOutput\n | AbortMultipartUploadCommandOutput\n) & {\n Location: string;\n};\n\nexport interface AWSParams {\n Bucket: string; // making it required\n ACL?: ObjectCannedACL;\n signedUrlExpires?: number;\n}\n\nexport interface DefaultOptions extends S3ClientConfig {\n // TODO Remove this in V5\n accessKeyId?: AwsCredentialIdentity['accessKeyId'];\n secretAccessKey?: AwsCredentialIdentity['secretAccessKey'];\n // Keep this for V5\n credentials?: AwsCredentialIdentity;\n params?: AWSParams;\n [k: string]: any;\n}\n\nexport type InitOptions = (DefaultOptions | { s3Options: DefaultOptions }) & {\n baseUrl?: string;\n rootPath?: string;\n [k: string]: any;\n};\n\nconst assertUrlProtocol = (url: string) => {\n // Regex to test protocol like \"http://\", \"https://\"\n return /^\\w*:\\/\\//.test(url);\n};\n\nconst getConfig = ({ baseUrl, rootPath, s3Options, ...legacyS3Options }: InitOptions) => {\n if (Object.keys(legacyS3Options).length > 0) {\n process.emitWarning(\n \"S3 configuration options passed at root level of the plugin's providerOptions is deprecated and will be removed in a future release. Please wrap them inside the 's3Options:{}' property.\"\n );\n }\n const credentials = extractCredentials({ s3Options, ...legacyS3Options });\n const config = {\n ...s3Options,\n ...legacyS3Options,\n ...(credentials ? { credentials } : {}),\n };\n\n config.params.ACL = getOr(ObjectCannedACL.public_read, ['params', 'ACL'], config);\n\n return config;\n};\n\nexport default {\n init({ baseUrl, rootPath, s3Options, ...legacyS3Options }: InitOptions) {\n // TODO V5 change config structure to avoid having to do this\n const config = getConfig({ baseUrl, rootPath, s3Options, ...legacyS3Options });\n const s3Client = new S3Client(config);\n const filePrefix = rootPath ? `${rootPath.replace(/\\/+$/, '')}/` : '';\n\n const getFileKey = (file: File) => {\n const path = file.path ? `${file.path}/` : '';\n return `${filePrefix}${path}${file.hash}${file.ext}`;\n };\n\n const upload = async (file: File, customParams: Partial<PutObjectCommandInput> = {}) => {\n const fileKey = getFileKey(file);\n const uploadObj = new Upload({\n client: s3Client,\n params: {\n Bucket: config.params.Bucket,\n Key: fileKey,\n Body: file.stream || Buffer.from(file.buffer as any, 'binary'),\n ACL: config.params.ACL,\n ContentType: file.mime,\n ...customParams,\n },\n });\n\n const upload = (await uploadObj.done()) as UploadCommandOutput;\n\n if (assertUrlProtocol(upload.Location)) {\n file.url = baseUrl ? `${baseUrl}/${fileKey}` : upload.Location;\n } else {\n // Default protocol to https protocol\n file.url = `https://${upload.Location}`;\n }\n };\n\n return {\n isPrivate() {\n return config.params.ACL === 'private';\n },\n\n async getSignedUrl(file: File, customParams: any): Promise<{ url: string }> {\n // Do not sign the url if it does not come from the same bucket.\n if (!isUrlFromBucket(file.url, config.params.Bucket, baseUrl)) {\n return { url: file.url };\n }\n const fileKey = getFileKey(file);\n\n const url = await getSignedUrl(\n // @ts-expect-error - TODO fix client type\n s3Client,\n new GetObjectCommand({\n Bucket: config.params.Bucket,\n Key: fileKey,\n ...customParams,\n }),\n {\n expiresIn: getOr(15 * 60, ['params', 'signedUrlExpires'], config),\n }\n );\n\n return { url };\n },\n uploadStream(file: File, customParams = {}) {\n return upload(file, customParams);\n },\n upload(file: File, customParams = {}) {\n return upload(file, customParams);\n },\n delete(file: File, customParams = {}): Promise<DeleteObjectCommandOutput> {\n const command = new DeleteObjectCommand({\n Bucket: config.params.Bucket,\n Key: getFileKey(file),\n ...customParams,\n });\n return s3Client.send(command);\n },\n };\n },\n};\n"],"names":["assertUrlProtocol","url","test","getConfig","baseUrl","rootPath","s3Options","legacyS3Options","Object","keys","length","process","emitWarning","credentials","extractCredentials","config","params","ACL","getOr","ObjectCannedACL","public_read","init","s3Client","S3Client","filePrefix","replace","getFileKey","file","path","hash","ext","upload","customParams","fileKey","uploadObj","Upload","client","Bucket","Key","Body","stream","Buffer","from","buffer","ContentType","mime","done","Location","isPrivate","getSignedUrl","isUrlFromBucket","GetObjectCommand","expiresIn","uploadStream","delete","command","DeleteObjectCommand","send"],"mappings":";;;;;;AAoEA,MAAMA,oBAAoB,CAACC,GAAAA,GAAAA;;IAEzB,OAAO,WAAA,CAAYC,IAAI,CAACD,GAAAA,CAAAA;AAC1B,CAAA;AAEA,MAAME,SAAAA,GAAY,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGC,eAA8B,EAAA,GAAA;AAClF,IAAA,IAAIC,OAAOC,IAAI,CAACF,eAAiBG,CAAAA,CAAAA,MAAM,GAAG,CAAG,EAAA;AAC3CC,QAAAA,OAAAA,CAAQC,WAAW,CACjB,2LAAA,CAAA;AAEJ;AACA,IAAA,MAAMC,cAAcC,kBAAmB,CAAA;AAAER,QAAAA,SAAAA;AAAW,QAAA,GAAGC;AAAgB,KAAA,CAAA;AACvE,IAAA,MAAMQ,MAAS,GAAA;AACb,QAAA,GAAGT,SAAS;AACZ,QAAA,GAAGC,eAAe;AAClB,QAAA,GAAIM,WAAc,GAAA;AAAEA,YAAAA;AAAY,SAAA,GAAI;AACtC,KAAA;AAEAE,IAAAA,MAAAA,CAAOC,MAAM,CAACC,GAAG,GAAGC,KAAMC,CAAAA,eAAAA,CAAgBC,WAAW,EAAE;AAAC,QAAA,QAAA;AAAU,QAAA;KAAM,EAAEL,MAAAA,CAAAA;IAE1E,OAAOA,MAAAA;AACT,CAAA;AAEA,YAAe;IACbM,IAAK,CAAA,CAAA,EAAEjB,OAAO,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGC,eAA8B,EAAA,EAAA;;AAEpE,QAAA,MAAMQ,SAASZ,SAAU,CAAA;AAAEC,YAAAA,OAAAA;AAAS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U,EAAEK,YAAe,GAAA,EAAE,EAAA;AACxC,gBAAA,OAAOD,OAAOJ,IAAMK,EAAAA,YAAAA,CAAAA;AACtB,aAAA;AACAD,YAAAA,MAAAA,CAAAA,CAAOJ,IAAU,EAAEK,YAAe,GAAA,EAAE,EAAA;AAClC,gBAAA,OAAOD,OAAOJ,IAAMK,EAAAA,YAAAA,CAAAA;AACtB,aAAA;AACAsB,YAAAA,MAAAA,CAAAA,CAAO3B,IAAU,EAAEK,YAAe,GAAA,EAAE,EAAA;gBAClC,MAAMuB,OAAAA,GAAU,IAAIC,mBAAoB,CAAA;oBACtCnB,MAAQtB,EAAAA,MAAAA,CAAOC,MAAM,CAACqB,MAAM;AAC5BC,oBAAAA,GAAAA,EAAKZ,UAAWC,CAAAA,IAAAA,CAAAA;AAChB,oBAAA,GAAGK;AACL,iBAAA,CAAA;gBACA,OAAOV,QAAAA,CAASmC,IAAI,CAACF,OAAAA,CAAAA;AACvB;AACF,SAAA;AACF;AACF,CAAE;;;;"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Parse the bucket name from a URL.
|
|
7
|
-
* See all URL formats in https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html
|
|
8
|
-
*
|
|
9
|
-
* @param {string} fileUrl - the URL to parse
|
|
10
|
-
* @returns {object} result
|
|
11
|
-
* @returns {string} result.bucket - the bucket name
|
|
12
|
-
* @returns {string} result.err - if any
|
|
13
|
-
*/
|
|
14
|
-
export declare function getBucketFromUrl(fileUrl: string): BucketInfo;
|
|
15
|
-
export {};
|
|
1
|
+
import type { AwsCredentialIdentity } from '@aws-sdk/types';
|
|
2
|
+
import type { InitOptions } from '.';
|
|
3
|
+
export declare function isUrlFromBucket(fileUrl: string, bucketName: string, baseUrl?: string): boolean;
|
|
4
|
+
export declare const extractCredentials: (options: InitOptions) => AwsCredentialIdentity | null;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AASrC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,SAAK,GAAG,OAAO,CAoB1F;AA4DD,eAAO,MAAM,kBAAkB,YAAa,WAAW,KAAG,qBAAqB,GAAG,IAQjF,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getBucketFromUrl = void 0;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
4
3
|
const ENDPOINT_PATTERN = /^(.+\.)?s3[.-]([a-z0-9-]+)\./;
|
|
4
|
+
function isUrlFromBucket(fileUrl, bucketName, baseUrl = '') {
|
|
5
|
+
const url = new URL(fileUrl);
|
|
6
|
+
// Check if the file URL is using a base URL (e.g. a CDN).
|
|
7
|
+
// In this case do not sign the URL.
|
|
8
|
+
if (baseUrl) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const { bucket } = getBucketFromAwsUrl(fileUrl);
|
|
12
|
+
if (bucket) {
|
|
13
|
+
return bucket === bucketName;
|
|
14
|
+
}
|
|
15
|
+
// File URL might be of an S3-compatible provider. (or an invalid URL)
|
|
16
|
+
// In this case, check if the bucket name appears in the URL host or path.
|
|
17
|
+
// e.g. https://minio.example.com/bucket-name/object-key
|
|
18
|
+
// e.g. https://bucket.nyc3.digitaloceanspaces.com/folder/img.png
|
|
19
|
+
return url.host.startsWith(`${bucketName}.`) || url.pathname.includes(`/${bucketName}/`);
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Parse the bucket name from a URL.
|
|
7
23
|
* See all URL formats in https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html
|
|
@@ -10,44 +26,72 @@ const ENDPOINT_PATTERN = /^(.+\.)?s3[.-]([a-z0-9-]+)\./;
|
|
|
10
26
|
* @returns {object} result
|
|
11
27
|
* @returns {string} result.bucket - the bucket name
|
|
12
28
|
* @returns {string} result.err - if any
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const uri = new URL(fileUrl);
|
|
29
|
+
*/ function getBucketFromAwsUrl(fileUrl) {
|
|
30
|
+
const url = new URL(fileUrl);
|
|
16
31
|
// S3://<bucket-name>/<key>
|
|
17
|
-
if (
|
|
18
|
-
const bucket =
|
|
32
|
+
if (url.protocol === 's3:') {
|
|
33
|
+
const bucket = url.host;
|
|
19
34
|
if (!bucket) {
|
|
20
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
err: `Invalid S3 url: no bucket: ${url}`
|
|
37
|
+
};
|
|
21
38
|
}
|
|
22
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
bucket
|
|
41
|
+
};
|
|
23
42
|
}
|
|
24
|
-
if (!
|
|
25
|
-
return {
|
|
43
|
+
if (!url.host) {
|
|
44
|
+
return {
|
|
45
|
+
err: `Invalid S3 url: no hostname: ${url}`
|
|
46
|
+
};
|
|
26
47
|
}
|
|
27
|
-
const matches =
|
|
48
|
+
const matches = url.host.match(ENDPOINT_PATTERN);
|
|
28
49
|
if (!matches) {
|
|
29
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
err: `Invalid S3 url: hostname does not appear to be a valid S3 endpoint: ${url}`
|
|
52
|
+
};
|
|
30
53
|
}
|
|
31
54
|
const prefix = matches[1];
|
|
32
55
|
// https://s3.amazonaws.com/<bucket-name>
|
|
33
56
|
if (!prefix) {
|
|
34
|
-
if (
|
|
35
|
-
return {
|
|
57
|
+
if (url.pathname === '/') {
|
|
58
|
+
return {
|
|
59
|
+
bucket: null
|
|
60
|
+
};
|
|
36
61
|
}
|
|
37
|
-
const index =
|
|
62
|
+
const index = url.pathname.indexOf('/', 1);
|
|
38
63
|
// https://s3.amazonaws.com/<bucket-name>
|
|
39
64
|
if (index === -1) {
|
|
40
|
-
return {
|
|
65
|
+
return {
|
|
66
|
+
bucket: url.pathname.substring(1)
|
|
67
|
+
};
|
|
41
68
|
}
|
|
42
69
|
// https://s3.amazonaws.com/<bucket-name>/
|
|
43
|
-
if (index ===
|
|
44
|
-
return {
|
|
70
|
+
if (index === url.pathname.length - 1) {
|
|
71
|
+
return {
|
|
72
|
+
bucket: url.pathname.substring(1, index)
|
|
73
|
+
};
|
|
45
74
|
}
|
|
46
75
|
// https://s3.amazonaws.com/<bucket-name>/key
|
|
47
|
-
return {
|
|
76
|
+
return {
|
|
77
|
+
bucket: url.pathname.substring(1, index)
|
|
78
|
+
};
|
|
48
79
|
}
|
|
49
80
|
// https://<bucket-name>.s3.amazonaws.com/
|
|
50
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
bucket: prefix.substring(0, prefix.length - 1)
|
|
83
|
+
};
|
|
51
84
|
}
|
|
52
|
-
|
|
53
|
-
|
|
85
|
+
const extractCredentials = (options)=>{
|
|
86
|
+
if (options.s3Options?.credentials) {
|
|
87
|
+
return {
|
|
88
|
+
accessKeyId: options.s3Options.credentials.accessKeyId,
|
|
89
|
+
secretAccessKey: options.s3Options.credentials.secretAccessKey
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.extractCredentials = extractCredentials;
|
|
96
|
+
exports.isUrlFromBucket = isUrlFromBucket;
|
|
97
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import type { AwsCredentialIdentity } from '@aws-sdk/types';\nimport type { InitOptions } from '.';\n\nconst ENDPOINT_PATTERN = /^(.+\\.)?s3[.-]([a-z0-9-]+)\\./;\n\ninterface BucketInfo {\n bucket?: string | null;\n err?: string;\n}\n\nexport function isUrlFromBucket(fileUrl: string, bucketName: string, baseUrl = ''): boolean {\n const url = new URL(fileUrl);\n\n // Check if the file URL is using a base URL (e.g. a CDN).\n // In this case do not sign the URL.\n if (baseUrl) {\n return false;\n }\n\n const { bucket } = getBucketFromAwsUrl(fileUrl);\n\n if (bucket) {\n return bucket === bucketName;\n }\n\n // File URL might be of an S3-compatible provider. (or an invalid URL)\n // In this case, check if the bucket name appears in the URL host or path.\n // e.g. https://minio.example.com/bucket-name/object-key\n // e.g. https://bucket.nyc3.digitaloceanspaces.com/folder/img.png\n return url.host.startsWith(`${bucketName}.`) || url.pathname.includes(`/${bucketName}/`);\n}\n\n/**\n * Parse the bucket name from a URL.\n * See all URL formats in https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html\n *\n * @param {string} fileUrl - the URL to parse\n * @returns {object} result\n * @returns {string} result.bucket - the bucket name\n * @returns {string} result.err - if any\n */\nfunction getBucketFromAwsUrl(fileUrl: string): BucketInfo {\n const url = new URL(fileUrl);\n\n // S3://<bucket-name>/<key>\n if (url.protocol === 's3:') {\n const bucket = url.host;\n\n if (!bucket) {\n return { err: `Invalid S3 url: no bucket: ${url}` };\n }\n return { bucket };\n }\n\n if (!url.host) {\n return { err: `Invalid S3 url: no hostname: ${url}` };\n }\n\n const matches = url.host.match(ENDPOINT_PATTERN);\n if (!matches) {\n return { err: `Invalid S3 url: hostname does not appear to be a valid S3 endpoint: ${url}` };\n }\n\n const prefix = matches[1];\n // https://s3.amazonaws.com/<bucket-name>\n if (!prefix) {\n if (url.pathname === '/') {\n return { bucket: null };\n }\n\n const index = url.pathname.indexOf('/', 1);\n\n // https://s3.amazonaws.com/<bucket-name>\n if (index === -1) {\n return { bucket: url.pathname.substring(1) };\n }\n\n // https://s3.amazonaws.com/<bucket-name>/\n if (index === url.pathname.length - 1) {\n return { bucket: url.pathname.substring(1, index) };\n }\n\n // https://s3.amazonaws.com/<bucket-name>/key\n return { bucket: url.pathname.substring(1, index) };\n }\n\n // https://<bucket-name>.s3.amazonaws.com/\n return { bucket: prefix.substring(0, prefix.length - 1) };\n}\n\nexport const extractCredentials = (options: InitOptions): AwsCredentialIdentity | null => {\n if (options.s3Options?.credentials) {\n return {\n accessKeyId: options.s3Options.credentials.accessKeyId,\n secretAccessKey: options.s3Options.credentials.secretAccessKey,\n };\n }\n return null;\n};\n"],"names":["ENDPOINT_PATTERN","isUrlFromBucket","fileUrl","bucketName","baseUrl","url","URL","bucket","getBucketFromAwsUrl","host","startsWith","pathname","includes","protocol","err","matches","match","prefix","index","indexOf","substring","length","extractCredentials","options","s3Options","credentials","accessKeyId","secretAccessKey"],"mappings":";;AAGA,MAAMA,gBAAmB,GAAA,8BAAA;AAOlB,SAASC,eAAgBC,CAAAA,OAAe,EAAEC,UAAkB,EAAEC,UAAU,EAAE,EAAA;IAC/E,MAAMC,GAAAA,GAAM,IAAIC,GAAIJ,CAAAA,OAAAA,CAAAA;;;AAIpB,IAAA,IAAIE,OAAS,EAAA;QACX,OAAO,KAAA;AACT;AAEA,IAAA,MAAM,EAAEG,MAAM,EAAE,GAAGC,mBAAoBN,CAAAA,OAAAA,CAAAA;AAEvC,IAAA,IAAIK,MAAQ,EAAA;AACV,QAAA,OAAOA,MAAWJ,KAAAA,UAAAA;AACpB;;;;;IAMA,OAAOE,GAAAA,CAAII,IAAI,CAACC,UAAU,CAAC,CAAC,EAAEP,WAAW,CAAC,CAAC,KAAKE,GAAIM,CAAAA,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC,EAAET,UAAW,CAAA,CAAC,CAAC,CAAA;AACzF;AAEA;;;;;;;;IASA,SAASK,oBAAoBN,OAAe,EAAA;IAC1C,MAAMG,GAAAA,GAAM,IAAIC,GAAIJ,CAAAA,OAAAA,CAAAA;;IAGpB,IAAIG,GA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AAA;AACpD;;QAGA,OAAO;AAAEX,YAAAA,MAAAA,EAAQF,GAAIM,CAAAA,QAAQ,CAACS,SAAS,CAAC,CAAGF,EAAAA,KAAAA;AAAO,SAAA;AACpD;;IAGA,OAAO;AAAEX,QAAAA,MAAAA,EAAQU,OAAOG,SAAS,CAAC,CAAGH,EAAAA,MAAAA,CAAOI,MAAM,GAAG,CAAA;AAAG,KAAA;AAC1D;AAEO,MAAMC,qBAAqB,CAACC,OAAAA,GAAAA;IACjC,IAAIA,OAAAA,CAAQC,SAAS,EAAEC,WAAa,EAAA;QAClC,OAAO;AACLC,YAAAA,WAAAA,EAAaH,OAAQC,CAAAA,SAAS,CAACC,WAAW,CAACC,WAAW;AACtDC,YAAAA,eAAAA,EAAiBJ,OAAQC,CAAAA,SAAS,CAACC,WAAW,CAACE;AACjD,SAAA;AACF;IACA,OAAO,IAAA;AACT;;;;;"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const ENDPOINT_PATTERN = /^(.+\.)?s3[.-]([a-z0-9-]+)\./;
|
|
2
|
+
function isUrlFromBucket(fileUrl, bucketName, baseUrl = '') {
|
|
3
|
+
const url = new URL(fileUrl);
|
|
4
|
+
// Check if the file URL is using a base URL (e.g. a CDN).
|
|
5
|
+
// In this case do not sign the URL.
|
|
6
|
+
if (baseUrl) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const { bucket } = getBucketFromAwsUrl(fileUrl);
|
|
10
|
+
if (bucket) {
|
|
11
|
+
return bucket === bucketName;
|
|
12
|
+
}
|
|
13
|
+
// File URL might be of an S3-compatible provider. (or an invalid URL)
|
|
14
|
+
// In this case, check if the bucket name appears in the URL host or path.
|
|
15
|
+
// e.g. https://minio.example.com/bucket-name/object-key
|
|
16
|
+
// e.g. https://bucket.nyc3.digitaloceanspaces.com/folder/img.png
|
|
17
|
+
return url.host.startsWith(`${bucketName}.`) || url.pathname.includes(`/${bucketName}/`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse the bucket name from a URL.
|
|
21
|
+
* See all URL formats in https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html
|
|
22
|
+
*
|
|
23
|
+
* @param {string} fileUrl - the URL to parse
|
|
24
|
+
* @returns {object} result
|
|
25
|
+
* @returns {string} result.bucket - the bucket name
|
|
26
|
+
* @returns {string} result.err - if any
|
|
27
|
+
*/ function getBucketFromAwsUrl(fileUrl) {
|
|
28
|
+
const url = new URL(fileUrl);
|
|
29
|
+
// S3://<bucket-name>/<key>
|
|
30
|
+
if (url.protocol === 's3:') {
|
|
31
|
+
const bucket = url.host;
|
|
32
|
+
if (!bucket) {
|
|
33
|
+
return {
|
|
34
|
+
err: `Invalid S3 url: no bucket: ${url}`
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
bucket
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!url.host) {
|
|
42
|
+
return {
|
|
43
|
+
err: `Invalid S3 url: no hostname: ${url}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const matches = url.host.match(ENDPOINT_PATTERN);
|
|
47
|
+
if (!matches) {
|
|
48
|
+
return {
|
|
49
|
+
err: `Invalid S3 url: hostname does not appear to be a valid S3 endpoint: ${url}`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const prefix = matches[1];
|
|
53
|
+
// https://s3.amazonaws.com/<bucket-name>
|
|
54
|
+
if (!prefix) {
|
|
55
|
+
if (url.pathname === '/') {
|
|
56
|
+
return {
|
|
57
|
+
bucket: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const index = url.pathname.indexOf('/', 1);
|
|
61
|
+
// https://s3.amazonaws.com/<bucket-name>
|
|
62
|
+
if (index === -1) {
|
|
63
|
+
return {
|
|
64
|
+
bucket: url.pathname.substring(1)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// https://s3.amazonaws.com/<bucket-name>/
|
|
68
|
+
if (index === url.pathname.length - 1) {
|
|
69
|
+
return {
|
|
70
|
+
bucket: url.pathname.substring(1, index)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// https://s3.amazonaws.com/<bucket-name>/key
|
|
74
|
+
return {
|
|
75
|
+
bucket: url.pathname.substring(1, index)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// https://<bucket-name>.s3.amazonaws.com/
|
|
79
|
+
return {
|
|
80
|
+
bucket: prefix.substring(0, prefix.length - 1)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const extractCredentials = (options)=>{
|
|
84
|
+
if (options.s3Options?.credentials) {
|
|
85
|
+
return {
|
|
86
|
+
accessKeyId: options.s3Options.credentials.accessKeyId,
|
|
87
|
+
secretAccessKey: options.s3Options.credentials.secretAccessKey
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { extractCredentials, isUrlFromBucket };
|
|
94
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { AwsCredentialIdentity } from '@aws-sdk/types';\nimport type { InitOptions } from '.';\n\nconst ENDPOINT_PATTERN = /^(.+\\.)?s3[.-]([a-z0-9-]+)\\./;\n\ninterface BucketInfo {\n bucket?: string | null;\n err?: string;\n}\n\nexport function isUrlFromBucket(fileUrl: string, bucketName: string, baseUrl = ''): boolean {\n const url = new URL(fileUrl);\n\n // Check if the file URL is using a base URL (e.g. a CDN).\n // In this case do not sign the URL.\n if (baseUrl) {\n return false;\n }\n\n const { bucket } = getBucketFromAwsUrl(fileUrl);\n\n if (bucket) {\n return bucket === bucketName;\n }\n\n // File URL might be of an S3-compatible provider. (or an invalid URL)\n // In this case, check if the bucket name appears in the URL host or path.\n // e.g. https://minio.example.com/bucket-name/object-key\n // e.g. https://bucket.nyc3.digitaloceanspaces.com/folder/img.png\n return url.host.startsWith(`${bucketName}.`) || url.pathname.includes(`/${bucketName}/`);\n}\n\n/**\n * Parse the bucket name from a URL.\n * See all URL formats in https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html\n *\n * @param {string} fileUrl - the URL to parse\n * @returns {object} result\n * @returns {string} result.bucket - the bucket name\n * @returns {string} result.err - if any\n */\nfunction getBucketFromAwsUrl(fileUrl: string): BucketInfo {\n const url = new URL(fileUrl);\n\n // S3://<bucket-name>/<key>\n if (url.protocol === 's3:') {\n const bucket = url.host;\n\n if (!bucket) {\n return { err: `Invalid S3 url: no bucket: ${url}` };\n }\n return { bucket };\n }\n\n if (!url.host) {\n return { err: `Invalid S3 url: no hostname: ${url}` };\n }\n\n const matches = url.host.match(ENDPOINT_PATTERN);\n if (!matches) {\n return { err: `Invalid S3 url: hostname does not appear to be a valid S3 endpoint: ${url}` };\n }\n\n const prefix = matches[1];\n // https://s3.amazonaws.com/<bucket-name>\n if (!prefix) {\n if (url.pathname === '/') {\n return { bucket: null };\n }\n\n const index = url.pathname.indexOf('/', 1);\n\n // https://s3.amazonaws.com/<bucket-name>\n if (index === -1) {\n return { bucket: url.pathname.substring(1) };\n }\n\n // https://s3.amazonaws.com/<bucket-name>/\n if (index === url.pathname.length - 1) {\n return { bucket: url.pathname.substring(1, index) };\n }\n\n // https://s3.amazonaws.com/<bucket-name>/key\n return { bucket: url.pathname.substring(1, index) };\n }\n\n // https://<bucket-name>.s3.amazonaws.com/\n return { bucket: prefix.substring(0, prefix.length - 1) };\n}\n\nexport const extractCredentials = (options: InitOptions): AwsCredentialIdentity | null => {\n if (options.s3Options?.credentials) {\n return {\n accessKeyId: options.s3Options.credentials.accessKeyId,\n secretAccessKey: options.s3Options.credentials.secretAccessKey,\n };\n }\n return null;\n};\n"],"names":["ENDPOINT_PATTERN","isUrlFromBucket","fileUrl","bucketName","baseUrl","url","URL","bucket","getBucketFromAwsUrl","host","startsWith","pathname","includes","protocol","err","matches","match","prefix","index","indexOf","substring","length","extractCredentials","options","s3Options","credentials","accessKeyId","secretAccessKey"],"mappings":"AAGA,MAAMA,gBAAmB,GAAA,8BAAA;AAOlB,SAASC,eAAgBC,CAAAA,OAAe,EAAEC,UAAkB,EAAEC,UAAU,EAAE,EAAA;IAC/E,MAAMC,GAAAA,GAAM,IAAIC,GAAIJ,CAAAA,OAAAA,CAAAA;;;AAIpB,IAAA,IAAIE,OAAS,EAAA;QACX,OAAO,KAAA;AACT;AAEA,IAAA,MAAM,EAAEG,MAAM,EAAE,GAAGC,mBAAoBN,CAAAA,OAAAA,CAAAA;AAEvC,IAAA,IAAIK,MAAQ,EAAA;AACV,QAAA,OAAOA,MAAWJ,KAAAA,UAAAA;AACpB;;;;;IAMA,OAAOE,GAAAA,CAAII,IAAI,CAACC,UAAU,CAAC,CAAC,EAAEP,WAAW,CAAC,CAAC,KAAKE,GAAIM,CAAAA,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC,EAAET,UAAW,CAAA,CAAC,CAAC,CAAA;AACzF;AAEA;;;;;;;;IASA,SAASK,oBAAoBN,OAAe,EAAA;IAC1C,MAAMG,GAAAA,GAAM,IAAIC,GAAIJ,CAAAA,OAAAA,CAAAA;;IAGpB,IAAIG,GAAAA,CAAIQ,QAAQ,KAAK,KAAO,EAAA;QAC1B,MAAMN,MAAAA,GAASF,IAAII,IAAI;AAEvB,QAAA,IAAI,CAACF,MAAQ,EAAA;YACX,OAAO;AAAEO,gBAAAA,GAAAA,EAAK,CAAC,2BAA2B,EAAET,GAAAA,CAAI;AAAE,aAAA;AACpD;QACA,OAAO;AAAEE,YAAAA;AAAO,SAAA;AAClB;IAEA,IAAI,CAACF,GAAII,CAAAA,IAAI,EAAE;QACb,OAAO;AAAEK,YAAAA,GAAAA,EAAK,CAAC,6BAA6B,EAAET,GAAAA,CAAI;AAAE,SAAA;AACtD;AAEA,IAAA,MAAMU,OAAUV,GAAAA,GAAAA,CAAII,IAAI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W;AACtDC,YAAAA,eAAAA,EAAiBJ,OAAQC,CAAAA,SAAS,CAACC,WAAW,CAACE;AACjD,SAAA;AACF;IACA,OAAO,IAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/provider-upload-aws-s3",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.ffc36acb308febe288f1a31b62cbbb75b286585c",
|
|
4
4
|
"description": "AWS S3 provider for strapi upload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"upload",
|
|
@@ -30,32 +30,36 @@
|
|
|
30
30
|
}
|
|
31
31
|
],
|
|
32
32
|
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.mjs",
|
|
34
|
+
"source": "./src/index.ts",
|
|
33
35
|
"types": "./dist/index.d.ts",
|
|
34
36
|
"files": [
|
|
35
|
-
"
|
|
37
|
+
"dist/"
|
|
36
38
|
],
|
|
37
39
|
"scripts": {
|
|
38
|
-
"build": "run -T
|
|
39
|
-
"build:
|
|
40
|
-
"
|
|
40
|
+
"build": "run -T npm-run-all clean --parallel build:code build:types",
|
|
41
|
+
"build:code": "run -T rollup -c",
|
|
42
|
+
"build:types": "run -T tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
41
43
|
"clean": "run -T rimraf ./dist",
|
|
42
|
-
"
|
|
44
|
+
"lint": "run -T eslint .",
|
|
43
45
|
"test:unit": "run -T jest",
|
|
44
46
|
"test:unit:watch": "run -T jest --watch",
|
|
45
|
-
"
|
|
47
|
+
"watch": "run -T rollup -c -w"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"aws-sdk": "
|
|
50
|
+
"@aws-sdk/client-s3": "3.600.0",
|
|
51
|
+
"@aws-sdk/lib-storage": "3.433.0",
|
|
52
|
+
"@aws-sdk/s3-request-presigner": "3.433.0",
|
|
53
|
+
"@aws-sdk/types": "3.433.0",
|
|
49
54
|
"lodash": "4.17.21"
|
|
50
55
|
},
|
|
51
56
|
"devDependencies": {
|
|
52
|
-
"@types/jest": "29.2
|
|
53
|
-
"eslint-config-custom": "0.0.0-next.
|
|
54
|
-
"tsconfig": "0.0.0-next.
|
|
57
|
+
"@types/jest": "29.5.2",
|
|
58
|
+
"eslint-config-custom": "0.0.0-next.ffc36acb308febe288f1a31b62cbbb75b286585c",
|
|
59
|
+
"tsconfig": "0.0.0-next.ffc36acb308febe288f1a31b62cbbb75b286585c"
|
|
55
60
|
},
|
|
56
61
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
62
|
+
"node": ">=18.0.0 <=22.x.x",
|
|
58
63
|
"npm": ">=6.0.0"
|
|
59
|
-
}
|
|
60
|
-
"gitHead": "ff946d2c25a3e577b47132a357cac2932eb8e635"
|
|
64
|
+
}
|
|
61
65
|
}
|