monastery 3.0.13 → 3.0.14
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/changelog.md +2 -0
- package/docs/manager/index.md +1 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/plugins/images/index.js +12 -11
- package/test/plugin-images.js +2 -2
package/changelog.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [3.0.14](https://github.com/boycce/monastery/compare/3.0.13...3.0.14) (2024-05-01)
|
|
6
|
+
|
|
5
7
|
### [3.0.13](https://github.com/boycce/monastery/compare/3.0.12...3.0.13) (2024-05-01)
|
|
6
8
|
|
|
7
9
|
### [3.0.12](https://github.com/boycce/monastery/compare/3.0.11...3.0.12) (2024-05-01)
|
package/docs/manager/index.md
CHANGED
|
@@ -60,6 +60,7 @@ db.onError((err) => {
|
|
|
60
60
|
- `manager.models()`: [see models](./models.html)
|
|
61
61
|
- `manager.onError(Function)`: Catches connection errors
|
|
62
62
|
- `manager.onOpen(Function)`: Triggers on successful connection
|
|
63
|
+
- `manager.getSignedUrl(path, expires, bucket)`: You can sign AWS S3 paths using this image plugin helper
|
|
63
64
|
|
|
64
65
|
### Dates
|
|
65
66
|
|
package/lib/index.js
CHANGED
|
@@ -282,7 +282,7 @@ Manager.prototype.parseData = function(obj) {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
Manager.prototype.model = Model
|
|
285
|
-
Manager.prototype._getSignedUrl = imagePluginFile.
|
|
285
|
+
Manager.prototype.getSignedUrl = Manager.prototype._getSignedUrl = imagePluginFile.getSignedUrl
|
|
286
286
|
|
|
287
287
|
inherits(Manager, EventEmitter)
|
|
288
288
|
module.exports = Manager
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "monastery",
|
|
3
3
|
"description": "⛪ A simple, straightforward MongoDB ODM",
|
|
4
4
|
"author": "Ricky Boyce",
|
|
5
|
-
"version": "3.0.
|
|
5
|
+
"version": "3.0.14",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/plugins/images/index.js
CHANGED
|
@@ -31,7 +31,7 @@ let plugin = module.exports = {
|
|
|
31
31
|
this.bucketDir = options.bucketDir || 'full' // depreciated > 1.36.2
|
|
32
32
|
this.filesize = options.filesize
|
|
33
33
|
this.formats = options.formats || ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff']
|
|
34
|
-
this.
|
|
34
|
+
this.getSignedUrlOption = options.getSignedUrl
|
|
35
35
|
this.manager = manager
|
|
36
36
|
this.metadata = options.metadata ? util.deepCopy(options.metadata) : undefined,
|
|
37
37
|
this.params = options.params ? util.deepCopy(options.params) : {},
|
|
@@ -41,17 +41,18 @@ let plugin = module.exports = {
|
|
|
41
41
|
throw new Error('Monastery imagePlugin: awsRegion, awsBucket, awsAccessKeyId, or awsSecretAccessKey is not defined')
|
|
42
42
|
}
|
|
43
43
|
if (!options.awsRegion) {
|
|
44
|
-
throw new Error('Monastery imagePlugin: v3 requires awsRegion to be defined for signing urls, e.g.
|
|
44
|
+
throw new Error('Monastery imagePlugin: v3 requires awsRegion to be defined for signing urls, e.g. \'ap-southeast-2\'')
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Create s3 'service' instance (defer require since it takes 120ms to load)
|
|
48
48
|
// v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
|
|
49
49
|
// v3: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/
|
|
50
50
|
// v3 examples: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html
|
|
51
|
-
this.getS3Client = () => {
|
|
51
|
+
this.getS3Client = (useRegion) => {
|
|
52
52
|
const { S3 } = require('@aws-sdk/client-s3')
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const key = useRegion ? '_s3ClientRegional' : '_s3Client'
|
|
54
|
+
return this[key] || (this[key] = new S3({
|
|
55
|
+
region: useRegion ? this.awsRegion : undefined,
|
|
55
56
|
credentials: {
|
|
56
57
|
accessKeyId: this.awsAccessKeyId,
|
|
57
58
|
secretAccessKey: this.awsSecretAccessKey,
|
|
@@ -230,11 +231,11 @@ let plugin = module.exports = {
|
|
|
230
231
|
for (let doc of util.toArray(data)) {
|
|
231
232
|
for (let imageField of this.imageFields) {
|
|
232
233
|
if (options.getSignedUrls
|
|
233
|
-
|| (util.isDefined(imageField.getSignedUrl) ? imageField.getSignedUrl : plugin.
|
|
234
|
+
|| (util.isDefined(imageField.getSignedUrl) ? imageField.getSignedUrl : plugin.getSignedUrlOption)) {
|
|
234
235
|
let images = plugin._findImagesInData(doc, imageField, 0, '').filter(o => o.image)
|
|
235
236
|
// todo: we could do this in parallel
|
|
236
237
|
for (let image of images) {
|
|
237
|
-
image.image.signedUrl = await plugin.
|
|
238
|
+
image.image.signedUrl = await plugin.getSignedUrl(image.image.path, 3600, imageField.awsBucket)
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
241
|
}
|
|
@@ -589,24 +590,24 @@ let plugin = module.exports = {
|
|
|
589
590
|
return list
|
|
590
591
|
},
|
|
591
592
|
|
|
592
|
-
|
|
593
|
+
getSignedUrl: async (path, expires=3600, bucket) => {
|
|
593
594
|
/**
|
|
594
595
|
* @param {string} path - aws file path
|
|
595
596
|
* @param {number} <expires> - seconds
|
|
596
|
-
* @param {
|
|
597
|
+
* @param {string} <bucket>
|
|
597
598
|
* @return {promise} signedUrl
|
|
598
599
|
* @see v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
|
|
599
600
|
* @see v3: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#s3-presigned-url
|
|
600
601
|
*/
|
|
601
602
|
if (!plugin.getS3Client) {
|
|
602
603
|
throw new Error(
|
|
603
|
-
'To use db.
|
|
604
|
+
'To use db.getSignedUrl(), the imagePlugin manager option must be defined, e.g. `monastery(..., { imagePlugin })`'
|
|
604
605
|
)
|
|
605
606
|
}
|
|
606
607
|
const { GetObjectCommand } = require('@aws-sdk/client-s3')
|
|
607
608
|
const params = { Bucket: bucket || plugin.awsBucket, Key: path }
|
|
608
609
|
const command = new GetObjectCommand(params)
|
|
609
|
-
let signedUrl = await getSignedUrl(plugin.getS3Client(), command, { expiresIn: expires })
|
|
610
|
+
let signedUrl = await getSignedUrl(plugin.getS3Client(true), command, { expiresIn: expires })
|
|
610
611
|
// console.log(signedUrl)
|
|
611
612
|
return signedUrl
|
|
612
613
|
},
|
package/test/plugin-images.js
CHANGED
|
@@ -573,7 +573,7 @@ test('images option defaults', async () => {
|
|
|
573
573
|
expect(imagePluginFile.awsAcl).toEqual('public-read')
|
|
574
574
|
expect(imagePluginFile.filesize).toEqual(undefined)
|
|
575
575
|
expect(imagePluginFile.formats).toEqual(['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff'])
|
|
576
|
-
expect(imagePluginFile.
|
|
576
|
+
expect(imagePluginFile.getSignedUrlOption).toEqual(undefined)
|
|
577
577
|
expect(imagePluginFile.metadata).toEqual(undefined)
|
|
578
578
|
expect(imagePluginFile.path).toEqual(expect.any(Function))
|
|
579
579
|
expect(imagePluginFile.params).toEqual({})
|
|
@@ -722,7 +722,7 @@ test('images option getSignedUrls', async () => {
|
|
|
722
722
|
timestamps: false,
|
|
723
723
|
imagePlugin: {
|
|
724
724
|
...imagePluginFakeOpts,
|
|
725
|
-
awsRegion: '
|
|
725
|
+
awsRegion: 'ap-southeast-2',
|
|
726
726
|
getSignedUrl: true,
|
|
727
727
|
},
|
|
728
728
|
})
|