@dynamatix/gb-schemas 0.21.10 → 0.21.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "0.21.10",
3
+ "version": "0.21.12",
4
4
  "description": "All the schemas for gatehouse bank back-end",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import crypto from 'crypto';
2
2
  import dotenv from 'dotenv';
3
+ import mongoose from 'mongoose';
3
4
  import path from 'path';
4
5
  import { fileURLToPath } from 'url';
5
6
 
@@ -28,8 +29,12 @@ export const encryptObject = (obj, collectionName) => {
28
29
  let encryptedObj = {};
29
30
 
30
31
  for (const key in obj) {
31
- if (key === "_id" || mongoose.isValidObjectId(obj[key])) {
32
- encryptedObj[key] = obj[key]; // Don't encrypt _id
32
+ if (
33
+ key === "_id" ||
34
+ (Array.isArray(obj[key]) && obj[key].every(item => mongoose.isValidObjectId(item))) ||
35
+ mongoose.isValidObjectId(obj[key])
36
+ ) {
37
+ encryptedObj[key] = obj[key]; // Don't encrypt ObjectId references
33
38
  } else {
34
39
  const iv = crypto.randomBytes(IV_LENGTH); // Generate IV
35
40
  const cipher = crypto.createCipheriv("aes-256-gcm", SECRET_KEY, iv);