monastery 2.2.5 → 2.2.7
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 +4 -0
- package/docs/image-plugin.md +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/plugins/images/index.js +8 -6
- package/test/plugin-images.js +15 -26
package/changelog.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
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
|
+
### [2.2.7](https://github.com/boycce/monastery/compare/2.2.6...2.2.7) (2024-05-01)
|
|
6
|
+
|
|
7
|
+
### [2.2.6](https://github.com/boycce/monastery/compare/2.2.5...2.2.6) (2024-04-30)
|
|
8
|
+
|
|
5
9
|
### [2.2.5](https://github.com/boycce/monastery/compare/2.2.4...2.2.5) (2024-04-30)
|
|
6
10
|
|
|
7
11
|
### [2.2.4](https://github.com/boycce/monastery/compare/2.2.3...2.2.4) (2024-04-30)
|
package/docs/image-plugin.md
CHANGED
|
@@ -12,7 +12,7 @@ To use the default image plugin shipped with monastery, you need to use the opti
|
|
|
12
12
|
imagePlugin: {
|
|
13
13
|
awsAcl: 'public-read', // default
|
|
14
14
|
awsBucket: 'your-bucket-name',
|
|
15
|
-
awsRegion: undefined, //
|
|
15
|
+
awsRegion: undefined, // e.g. 'ap-southeast-2'
|
|
16
16
|
awsAccessKeyId: 'your-key-here',
|
|
17
17
|
awsSecretAccessKey: 'your-key-here',
|
|
18
18
|
filesize: undefined, // default (max filesize in bytes)
|
package/lib/index.js
CHANGED
|
@@ -64,6 +64,7 @@ module.exports = function(uri, opts, fn) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Initiate any plugins
|
|
67
|
+
manager._getSignedUrl = manager.imagePluginFile._getSignedUrl
|
|
67
68
|
if (manager.imagePlugin) {
|
|
68
69
|
manager.imagePluginFile.setup(manager, util.isObject(manager.imagePlugin)? manager.imagePlugin : {})
|
|
69
70
|
}
|
|
@@ -91,7 +92,6 @@ let models = async function(pathname, opts) {
|
|
|
91
92
|
* @this Manager
|
|
92
93
|
*/
|
|
93
94
|
let out = {}
|
|
94
|
-
opts = true
|
|
95
95
|
if (opts === true) {
|
|
96
96
|
opts = { waitForIndexes: true } // legacy support
|
|
97
97
|
console.warn('Depreciating: please use `{ waitForIndexes: true }` instead of `true` in db.models(pathname, `true`)')
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "monastery",
|
|
3
3
|
"description": "⛪ A straight forward MongoDB ODM built around Monk",
|
|
4
4
|
"author": "Ricky Boyce",
|
|
5
|
-
"version": "2.2.
|
|
5
|
+
"version": "2.2.7",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/plugins/images/index.js
CHANGED
|
@@ -38,16 +38,16 @@ let plugin = module.exports = {
|
|
|
38
38
|
this.path = options.path || function (uid, basename, ext, file) { return `full/${uid}.${ext}` }
|
|
39
39
|
|
|
40
40
|
if (!options.awsBucket || !options.awsAccessKeyId || !options.awsSecretAccessKey) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
throw new Error('Monastery imagePlugin: awsRegion, awsBucket, awsAccessKeyId, or awsSecretAccessKey is not defined')
|
|
42
|
+
}
|
|
43
|
+
if (!options.awsRegion) {
|
|
44
|
+
throw new Error('Monastery imagePlugin: v3 requires awsRegion to be defined for signing urls, e.g. "ap-southeast-2"')
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// Create s3 'service' instance (defer require since it takes 120ms to load)
|
|
47
48
|
// v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
|
|
48
49
|
// v3: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/
|
|
49
50
|
// v3 examples: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html
|
|
50
|
-
manager._getSignedUrl = this._getSignedUrl
|
|
51
51
|
this.getS3Client = () => {
|
|
52
52
|
const { S3 } = require('@aws-sdk/client-s3')
|
|
53
53
|
return this._s3Client || (this._s3Client = new S3({
|
|
@@ -598,8 +598,10 @@ let plugin = module.exports = {
|
|
|
598
598
|
* @see v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
|
|
599
599
|
* @see v3: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#s3-presigned-url
|
|
600
600
|
*/
|
|
601
|
-
if (!plugin.
|
|
602
|
-
throw
|
|
601
|
+
if (!plugin.getS3Client) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
'To use db._getSignedUrl(), the imagePlugin manager option must be defined, e.g. `monastery(..., { imagePlugin })`'
|
|
604
|
+
)
|
|
603
605
|
}
|
|
604
606
|
const { GetObjectCommand } = require('@aws-sdk/client-s3')
|
|
605
607
|
const params = { Bucket: bucket || plugin.awsBucket, Key: path }
|
package/test/plugin-images.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
let util = require('../lib/util.js')
|
|
2
|
+
const imagePluginFakeOpts = { awsBucket: 'fake', awsRegion: 'fake', awsAccessKeyId: 'fake', awsSecretAccessKey: 'fake' }
|
|
2
3
|
|
|
3
4
|
module.exports = function(monastery, opendb) {
|
|
4
5
|
|
|
@@ -58,7 +59,7 @@ module.exports = function(monastery, opendb) {
|
|
|
58
59
|
let db = (await opendb(null, {
|
|
59
60
|
timestamps: false,
|
|
60
61
|
serverSelectionTimeoutMS: 2000,
|
|
61
|
-
imagePlugin:
|
|
62
|
+
imagePlugin: imagePluginFakeOpts
|
|
62
63
|
})).db
|
|
63
64
|
|
|
64
65
|
let user = db.model('user', { fields: {
|
|
@@ -68,7 +69,7 @@ module.exports = function(monastery, opendb) {
|
|
|
68
69
|
}})
|
|
69
70
|
|
|
70
71
|
// Initialisation success
|
|
71
|
-
expect(db.imagePlugin).toEqual(
|
|
72
|
+
expect(db.imagePlugin).toEqual(imagePluginFakeOpts)
|
|
72
73
|
|
|
73
74
|
let expected = {
|
|
74
75
|
bucket: { type: 'string', isString: true },
|
|
@@ -96,7 +97,7 @@ module.exports = function(monastery, opendb) {
|
|
|
96
97
|
let db = (await opendb(null, {
|
|
97
98
|
timestamps: false,
|
|
98
99
|
serverSelectionTimeoutMS: 2000,
|
|
99
|
-
imagePlugin:
|
|
100
|
+
imagePlugin: imagePluginFakeOpts
|
|
100
101
|
})).db
|
|
101
102
|
let plugin = db.imagePluginFile
|
|
102
103
|
db.model('user', { fields: {
|
|
@@ -147,7 +148,7 @@ module.exports = function(monastery, opendb) {
|
|
|
147
148
|
let db = (await opendb(null, {
|
|
148
149
|
timestamps: false,
|
|
149
150
|
serverSelectionTimeoutMS: 2000,
|
|
150
|
-
imagePlugin:
|
|
151
|
+
imagePlugin: imagePluginFakeOpts
|
|
151
152
|
})).db
|
|
152
153
|
|
|
153
154
|
let user = db.model('user', { fields: {
|
|
@@ -255,7 +256,7 @@ module.exports = function(monastery, opendb) {
|
|
|
255
256
|
let db = (await opendb(null, {
|
|
256
257
|
timestamps: false,
|
|
257
258
|
serverSelectionTimeoutMS: 2000,
|
|
258
|
-
imagePlugin:
|
|
259
|
+
imagePlugin: imagePluginFakeOpts
|
|
259
260
|
})).db
|
|
260
261
|
|
|
261
262
|
let user = db.model('user', { fields: {
|
|
@@ -341,7 +342,7 @@ module.exports = function(monastery, opendb) {
|
|
|
341
342
|
let db = (await opendb(null, {
|
|
342
343
|
timestamps: false,
|
|
343
344
|
serverSelectionTimeoutMS: 2000,
|
|
344
|
-
imagePlugin:
|
|
345
|
+
imagePlugin: imagePluginFakeOpts
|
|
345
346
|
})).db
|
|
346
347
|
|
|
347
348
|
let user = db.model('user', { fields: {
|
|
@@ -392,7 +393,7 @@ module.exports = function(monastery, opendb) {
|
|
|
392
393
|
let db = (await opendb(null, {
|
|
393
394
|
timestamps: false,
|
|
394
395
|
serverSelectionTimeoutMS: 2000,
|
|
395
|
-
imagePlugin:
|
|
396
|
+
imagePlugin: imagePluginFakeOpts
|
|
396
397
|
})).db
|
|
397
398
|
|
|
398
399
|
db.model('user', { fields: {
|
|
@@ -470,7 +471,7 @@ module.exports = function(monastery, opendb) {
|
|
|
470
471
|
let db = (await opendb(null, {
|
|
471
472
|
timestamps: false,
|
|
472
473
|
serverSelectionTimeoutMS: 2000,
|
|
473
|
-
imagePlugin:
|
|
474
|
+
imagePlugin: imagePluginFakeOpts
|
|
474
475
|
})).db
|
|
475
476
|
|
|
476
477
|
let user = db.model('user', { fields: {
|
|
@@ -524,7 +525,7 @@ module.exports = function(monastery, opendb) {
|
|
|
524
525
|
let db = (await opendb(null, {
|
|
525
526
|
timestamps: false,
|
|
526
527
|
serverSelectionTimeoutMS: 2000,
|
|
527
|
-
imagePlugin:
|
|
528
|
+
imagePlugin: imagePluginFakeOpts
|
|
528
529
|
})).db
|
|
529
530
|
|
|
530
531
|
let user = db.model('user', { fields: {
|
|
@@ -621,11 +622,7 @@ module.exports = function(monastery, opendb) {
|
|
|
621
622
|
let db = (await opendb(null, {
|
|
622
623
|
timestamps: false,
|
|
623
624
|
serverSelectionTimeoutMS: 2000,
|
|
624
|
-
imagePlugin:
|
|
625
|
-
awsBucket: 'fake',
|
|
626
|
-
awsAccessKeyId: 'fake',
|
|
627
|
-
awsSecretAccessKey: 'fake',
|
|
628
|
-
}
|
|
625
|
+
imagePlugin: imagePluginFakeOpts
|
|
629
626
|
})).db
|
|
630
627
|
|
|
631
628
|
let user = db.model('user', {
|
|
@@ -717,9 +714,7 @@ module.exports = function(monastery, opendb) {
|
|
|
717
714
|
timestamps: false,
|
|
718
715
|
serverSelectionTimeoutMS: 2000,
|
|
719
716
|
imagePlugin: {
|
|
720
|
-
|
|
721
|
-
awsAccessKeyId: 'fake',
|
|
722
|
-
awsSecretAccessKey: 'fake',
|
|
717
|
+
...imagePluginFakeOpts,
|
|
723
718
|
formats: ['jpg', 'jpeg', 'png', 'ico'],
|
|
724
719
|
filesize: 1000 * 270,
|
|
725
720
|
}
|
|
@@ -800,9 +795,7 @@ module.exports = function(monastery, opendb) {
|
|
|
800
795
|
timestamps: false,
|
|
801
796
|
serverSelectionTimeoutMS: 2000,
|
|
802
797
|
imagePlugin: {
|
|
803
|
-
|
|
804
|
-
awsAccessKeyId: 'fake',
|
|
805
|
-
awsSecretAccessKey: 'fake',
|
|
798
|
+
...imagePluginFakeOpts,
|
|
806
799
|
awsRegion: 's3-ap-southeast-2',
|
|
807
800
|
getSignedUrl: true,
|
|
808
801
|
},
|
|
@@ -861,10 +854,8 @@ module.exports = function(monastery, opendb) {
|
|
|
861
854
|
timestamps: false,
|
|
862
855
|
serverSelectionTimeoutMS: 2000,
|
|
863
856
|
imagePlugin: {
|
|
857
|
+
...imagePluginFakeOpts,
|
|
864
858
|
awsAcl: 'private',
|
|
865
|
-
awsBucket: 'fake',
|
|
866
|
-
awsAccessKeyId: 'fake',
|
|
867
|
-
awsSecretAccessKey: 'fake',
|
|
868
859
|
metadata: { small: '*x300' , medium: '*x800', large: '*x1200' },
|
|
869
860
|
params: { ContentLanguage: 'DE'},
|
|
870
861
|
path: (uid, basename, ext, file) => `images/${basename}`,
|
|
@@ -966,9 +957,7 @@ module.exports = function(monastery, opendb) {
|
|
|
966
957
|
timestamps: false,
|
|
967
958
|
serverSelectionTimeoutMS: 2000,
|
|
968
959
|
imagePlugin: {
|
|
969
|
-
|
|
970
|
-
awsAccessKeyId: 'fake',
|
|
971
|
-
awsSecretAccessKey: 'fake',
|
|
960
|
+
...imagePluginFakeOpts,
|
|
972
961
|
bucketDir: 'old',
|
|
973
962
|
}
|
|
974
963
|
})).db
|