monastery 1.37.1 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -2,6 +2,27 @@
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
+ ## [1.38.0](https://github.com/boycce/monastery/compare/1.37.3...1.38.0) (2022-06-17)
6
+
7
+
8
+ ### Features
9
+
10
+ * added options.metadata ([cb4ca43](https://github.com/boycce/monastery/commit/cb4ca43a395c1f90a5e37b8cc95472053e2b3b36))
11
+
12
+ ### [1.37.3](https://github.com/boycce/monastery/compare/1.37.2...1.37.3) (2022-06-17)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * test ([dad21ad](https://github.com/boycce/monastery/commit/dad21ad9c014a45ccc50a4755daa12941d6b7465))
18
+
19
+ ### [1.37.2](https://github.com/boycce/monastery/compare/1.37.1...1.37.2) (2022-06-13)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * changed the default awsAcl from public-read to private ([ba383b5](https://github.com/boycce/monastery/commit/ba383b5f363dafe3b893e08de1a124b7ce96df44))
25
+
5
26
  ### [1.37.1](https://github.com/boycce/monastery/compare/1.37.0...1.37.1) (2022-06-13)
6
27
 
7
28
 
@@ -18,7 +18,10 @@ To use the default image plugin shipped with monastery, you need to use the opti
18
18
  formats: ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff'], // default (use 'any' to allow all extensions)
19
19
  getSignedUrl: false, // default (get a S3 signed url after `model.find()`, can be defined per request)
20
20
  path: (uid, basename, ext, file) => `/full/${uid}.${ext}`, // default
21
- params: {}, // upload params (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
21
+ metadata: {},
22
+ // Any s3 upload param, which takes precedence over the params above
23
+ // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
24
+ params: {},
22
25
  }
23
26
  })
24
27
  ```
package/docs/readme.md CHANGED
@@ -93,7 +93,7 @@ Coming soon...
93
93
  - ~~Whitelisting a parent will remove any previously blacklisted children~~
94
94
  - ~~Blacklist/project works the same across find/insert/update/validate~~
95
95
  - Automatic embedded document ids/createdAt/updatedAt fields
96
- - Remove ACL default 'public read'
96
+ - ~~Change ACL default 'public read' to 'private'~~
97
97
  - ~~Public db.arrayWithSchema method~~
98
98
  - Global after/before hooks
99
99
  - docs: Make the implicit ID query conversion more apparent
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": "1.37.1",
5
+ "version": "1.38.0",
6
6
  "license": "MIT",
7
7
  "repository": "github:boycce/monastery",
8
8
  "homepage": "https://boycce.github.io/monastery/",
@@ -25,7 +25,7 @@ let plugin = module.exports = {
25
25
  }
26
26
 
27
27
  // Settings
28
- this.awsAcl = options.awsAcl || 'public-read'
28
+ this.awsAcl = options.awsAcl || 'private' // default
29
29
  this.awsBucket = options.awsBucket
30
30
  this.awsAccessKeyId = options.awsAccessKeyId
31
31
  this.awsSecretAccessKey = options.awsSecretAccessKey
@@ -34,6 +34,7 @@ let plugin = module.exports = {
34
34
  this.formats = options.formats || ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff']
35
35
  this.getSignedUrl = options.getSignedUrl
36
36
  this.manager = manager
37
+ this.metadata = options.metadata ? util.deepCopy(options.metadata) : undefined,
37
38
  this.params = options.params ? util.deepCopy(options.params) : {},
38
39
  this.path = options.path || function (uid, basename, ext, file) { return `full/${uid}.${ext}` }
39
40
 
@@ -147,8 +148,8 @@ let plugin = module.exports = {
147
148
  date: plugin.manager.useMilliseconds? Date.now() : Math.floor(Date.now() / 1000),
148
149
  filename: file.name,
149
150
  filesize: file.size,
151
+ metadata: filesArr.imageField.metadata || plugin.metadata,
150
152
  path: path(uid, file.name, file.ext, file),
151
- // sizes: ['large', 'medium', 'small'],
152
153
  uid: uid,
153
154
  }
154
155
  let s3Options = {
@@ -158,6 +159,7 @@ let plugin = module.exports = {
158
159
  Body: file.data,
159
160
  Bucket: image.bucket,
160
161
  Key: image.path,
162
+ Metadata: image.metadata,
161
163
  ...(filesArr.imageField.params || plugin.params),
162
164
  }
163
165
  plugin.manager.info(
@@ -347,11 +349,12 @@ let plugin = module.exports = {
347
349
  if (useCount[key] > 0) continue
348
350
  let pre = preExistingImages.find(o => o.image.uid == key)
349
351
  unused.push(
350
- // original key can have a different extension
352
+ // original key can have a different extension, but always expect generated assets
353
+ // to be in jpg
351
354
  { Key: pre.image.path },
352
355
  { Key: `small/${key}.jpg` },
353
356
  { Key: `medium/${key}.jpg` },
354
- { Key: `large/${key}.jpg` }
357
+ { Key: `large/${key}.jpg` },
355
358
  )
356
359
  plugin.manager.info(
357
360
  `Removing '${pre.image.filename}' from '${pre.image.bucket}/${pre.image.path}'`
@@ -504,6 +507,7 @@ let plugin = module.exports = {
504
507
  fullPath: path2,
505
508
  fullPathRegex: new RegExp('^' + path2.replace(/\.[0-9]+/g, '.[0-9]+').replace(/\./g, '\\.') + '$'),
506
509
  getSignedUrl: field.getSignedUrl,
510
+ metadata: field.metadata ? util.deepCopy(field.metadata) : undefined,
507
511
  path: field.path,
508
512
  params: field.params ? util.deepCopy(field.params) : undefined,
509
513
  })
@@ -513,6 +517,7 @@ let plugin = module.exports = {
513
517
  date: { type: 'number' },
514
518
  filename: { type: 'string' },
515
519
  filesize: { type: 'number' },
520
+ metadata: { type: 'any' },
516
521
  path: { type: 'string' },
517
522
  schema: { image: true, nullObject: true, isImageObject: true },
518
523
  uid: { type: 'string' },
@@ -75,6 +75,7 @@ module.exports = function(monastery, opendb) {
75
75
  date: { type: 'number', isNumber: true },
76
76
  filename: { type: 'string', isString: true },
77
77
  filesize: { type: 'number', isNumber: true },
78
+ metadata: { type: 'any', isAny: true },
78
79
  path: { type: 'string', isString: true },
79
80
  schema: {
80
81
  type: 'object', isObject: true, image: true, nullObject: true, default: undefined,
@@ -641,10 +642,11 @@ module.exports = function(monastery, opendb) {
641
642
  app.use(upload({ limits: { fileSize: 1000 * 480, files: 10 }}))
642
643
 
643
644
  // Basic tests
644
- expect(plugin.awsAcl).toEqual('public-read')
645
+ expect(plugin.awsAcl).toEqual('private')
645
646
  expect(plugin.filesize).toEqual(undefined)
646
647
  expect(plugin.formats).toEqual(['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff'])
647
648
  expect(plugin.getSignedUrl).toEqual(undefined)
649
+ expect(plugin.metadata).toEqual(undefined)
648
650
  expect(plugin.path).toEqual(expect.any(Function))
649
651
  expect(plugin.params).toEqual({})
650
652
 
@@ -688,7 +690,7 @@ module.exports = function(monastery, opendb) {
688
690
  // S3 options
689
691
  expect(response[1]).toEqual([
690
692
  [{
691
- ACL: 'public-read',
693
+ ACL: 'private',
692
694
  Body: expect.any(Object),
693
695
  Bucket: 'fake',
694
696
  Key: expect.stringMatching(/^full\/.*png$/),
@@ -853,7 +855,7 @@ module.exports = function(monastery, opendb) {
853
855
  db.close()
854
856
  })
855
857
 
856
- test('images options awsAcl, awsBucket, params, path', async () => {
858
+ test('images options awsAcl, awsBucket, metadata, params, path', async () => {
857
859
  let db = (await opendb(null, {
858
860
  timestamps: false,
859
861
  serverSelectionTimeoutMS: 2000,
@@ -862,6 +864,7 @@ module.exports = function(monastery, opendb) {
862
864
  awsBucket: 'fake',
863
865
  awsAccessKeyId: 'fake',
864
866
  awsSecretAccessKey: 'fake',
867
+ metadata: { small: '*x200' , medium: '*x800', large: '*x1600' },
865
868
  params: { ContentLanguage: 'DE'},
866
869
  path: (uid, basename, ext, file) => `images/${basename}`,
867
870
  }
@@ -874,6 +877,7 @@ module.exports = function(monastery, opendb) {
874
877
  type: 'image',
875
878
  awsAcl: 'public-read-write',
876
879
  awsBucket: 'fake2',
880
+ metadata: { small: '*x100' , medium: '*x400', large: '*x800' },
877
881
  params: { ContentLanguage: 'NZ'},
878
882
  path: (uid, basename, ext, file) => `images2/${basename}`,
879
883
  },
@@ -904,6 +908,7 @@ module.exports = function(monastery, opendb) {
904
908
  date: expect.any(Number),
905
909
  filename: 'logo.png',
906
910
  filesize: expect.any(Number),
911
+ metadata: { small: '*x200' , medium: '*x800', large: '*x1600' },
907
912
  path: 'images/logo.png',
908
913
  uid: expect.any(String),
909
914
  },
@@ -912,6 +917,7 @@ module.exports = function(monastery, opendb) {
912
917
  date: expect.any(Number),
913
918
  filename: 'logo2.png',
914
919
  filesize: expect.any(Number),
920
+ metadata: { small: '*x100' , medium: '*x400', large: '*x800' },
915
921
  path: 'images2/logo2.png',
916
922
  uid: expect.any(String),
917
923
  },
@@ -924,6 +930,7 @@ module.exports = function(monastery, opendb) {
924
930
  Bucket: 'fake',
925
931
  ContentLanguage: 'DE',
926
932
  Key: 'images/logo.png',
933
+ Metadata: { small: '*x200' , medium: '*x800', large: '*x1600' },
927
934
  }],
928
935
  [{
929
936
  ACL: 'public-read-write',
@@ -931,6 +938,7 @@ module.exports = function(monastery, opendb) {
931
938
  Bucket: 'fake2',
932
939
  ContentLanguage: 'NZ',
933
940
  Key: 'images2/logo2.png',
941
+ Metadata: { small: '*x100' , medium: '*x400', large: '*x800' },
934
942
  }],
935
943
  ])
936
944
  res.send()