@dynamatix/gb-schemas 0.23.5 → 0.23.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/applicants/applicant.model.js +0 -2
- package/applications/application-audit.model.js +1 -3
- package/applications/application-checklist-Item.model.js +1 -2
- package/applications/application-document.model.js +1 -2
- package/applications/application-fieldconfig.model.js +1 -2
- package/applications/application-legal.model.js +1 -2
- package/applications/application-mortgage.model.js +1 -2
- package/applications/application-note.model.js +1 -2
- package/applications/application-offer.model.js +1 -3
- package/applications/application-onboarding.model.js +1 -3
- package/applications/application-rationale.model.js +1 -2
- package/applications/application-risk-narrative.model.js +0 -2
- package/applications/application.model.js +1 -2
- package/applications/broker.model.js +1 -2
- package/applications/document.model.js +1 -2
- package/applications/productfeatures.model.js +1 -2
- package/applications/solicitor.model.js +1 -2
- package/package.json +2 -1
- package/product-catalogues/product-catalogue.model.js +1 -2
- package/product-catalogues/product-definitions.model.js +1 -2
- package/product-catalogues/product-variant.model.js +1 -2
- package/properties/property.model.js +1 -2
- package/shared/alert.model.js +1 -2
- package/shared/checklist.model.js +1 -2
- package/shared/lookup-group.model.js +1 -2
- package/shared/lookup.model.js +1 -2
- package/shared/task-document.model.js +0 -3
- package/shared/task.model.js +1 -2
- package/underwriters/underwriters.model.js +1 -2
- package/users/permission.model.js +1 -2
- package/users/role-group.model.js +1 -2
- package/users/role.model.js +1 -2
- package/users/tasks.model.js +1 -2
- package/users/user.model.js +1 -2
- package/utils/encryption.js +0 -106
- package/utils/encryption.middleware.js +0 -146
|
@@ -9,7 +9,6 @@ import applicantCommitmentSchema from "./applicant-commitment.model.js";
|
|
|
9
9
|
import applicantDirectDebitSchema from "./applicant-direct-debit.model.js";
|
|
10
10
|
import creditProfileSchema from "./applicant-credit-profile.model.js";
|
|
11
11
|
import incomeSchema from "./applicant-income.model.js";
|
|
12
|
-
import mongooseEncryption from "../utils/encryption.middleware.js";
|
|
13
12
|
|
|
14
13
|
const applicantSchema = new mongoose.Schema({
|
|
15
14
|
applicantId: { type: String, required: true },
|
|
@@ -160,6 +159,5 @@ applicantSchema.virtual('vulnerabilityType').get(function () {
|
|
|
160
159
|
return this.VulnerabilityTypeLid?.name ?? null;
|
|
161
160
|
});
|
|
162
161
|
|
|
163
|
-
applicantSchema.plugin(mongooseEncryption);
|
|
164
162
|
const ApplicantModel = mongoose.model("Applicant", applicantSchema);
|
|
165
163
|
export default ApplicantModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const applicationAuditSchema = new mongoose.Schema({
|
|
5
5
|
auditId: {
|
|
@@ -41,7 +41,5 @@ const applicationAuditSchema = new mongoose.Schema({
|
|
|
41
41
|
}
|
|
42
42
|
},{ timestamps: true });
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
applicationAuditSchema.plugin(mongooseEncryption);
|
|
46
44
|
const ApplicationAuditModel = mongoose.model('ApplicationAudit', applicationAuditSchema);
|
|
47
45
|
export default ApplicationAuditModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const checkListItemSchema = new mongoose.Schema({
|
|
5
5
|
additionalOfferConditions: { type: String, default: "" },
|
|
@@ -44,6 +44,5 @@ const checkListItemSchema = new mongoose.Schema({
|
|
|
44
44
|
valuationSurveyorDetails: { type: String, default: "" }
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
checkListItemSchema.plugin(mongooseEncryption);
|
|
48
47
|
const ApplicationCheckListModel = mongoose.model("ApplicationCheckList", checkListItemSchema);
|
|
49
48
|
export default ApplicationCheckListModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const documentSchema = new mongoose.Schema({
|
|
5
5
|
applicationId: {
|
|
@@ -34,6 +34,5 @@ const documentSchema = new mongoose.Schema({
|
|
|
34
34
|
timestamps: true
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
documentSchema.plugin(mongooseEncryption);
|
|
38
37
|
const ApplicationDocumentModel = mongoose.model("ApplicationDocument", documentSchema);
|
|
39
38
|
export default ApplicationDocumentModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const fieldConfigSchema = new mongoose.Schema({
|
|
5
5
|
fieldName: { type: String, required: true, unique: true },
|
|
@@ -7,6 +7,5 @@ const fieldConfigSchema = new mongoose.Schema({
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
fieldConfigSchema.plugin(mongooseEncryption);
|
|
11
10
|
const ApplicationFieldConfigModel = mongoose.model('FieldConfig', fieldConfigSchema);
|
|
12
11
|
export default ApplicationFieldConfigModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const legalSchema = new mongoose.Schema({
|
|
5
5
|
assignedSolicitor: { type: String, default: "" },
|
|
@@ -7,6 +7,5 @@ const legalSchema = new mongoose.Schema({
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
legalSchema.plugin(mongooseEncryption);
|
|
11
10
|
const LegalModel = mongoose.model("Legal", legalSchema);
|
|
12
11
|
export default LegalModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const mortgageSchema = new mongoose.Schema({
|
|
5
5
|
depositComeFrom: { type: String, required: true },
|
|
@@ -29,5 +29,4 @@ const mortgageSchema = new mongoose.Schema({
|
|
|
29
29
|
vendorsName: { type: String, default: "" }
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
mortgageSchema.plugin(mongooseEncryption);
|
|
33
32
|
export default mortgageSchema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const noteSchema = new mongoose.Schema({
|
|
5
5
|
applicationId: { type: mongoose.Schema.Types.ObjectId, ref: "Application", required: true },
|
|
@@ -73,6 +73,5 @@ const noteSchema = new mongoose.Schema({
|
|
|
73
73
|
},
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
noteSchema.plugin(mongooseEncryption);
|
|
77
76
|
const ApplictionNoteModel = mongoose.model("ApplictionNote", noteSchema);
|
|
78
77
|
export default ApplictionNoteModel;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const offerSchema = new mongoose.Schema({
|
|
5
5
|
date: { type: String } // The date associated with the offer
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
offerSchema.plugin(mongooseEncryption);
|
|
10
8
|
const OfferModel = mongoose.model("Offer", offerSchema);
|
|
11
9
|
export default OfferModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const onboardingSchema = new mongoose.Schema({
|
|
5
5
|
errors: { type: String, default: "" },
|
|
@@ -8,7 +8,5 @@ const onboardingSchema = new mongoose.Schema({
|
|
|
8
8
|
warnings: { type: String, default: "" }
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
onboardingSchema.plugin(mongooseEncryption);
|
|
13
11
|
const ApplicationOnboardingModel = mongoose.model("ApplicationOnboarding", onboardingSchema);
|
|
14
12
|
export default ApplicationOnboardingModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const rationaleSchema = new mongoose.Schema({
|
|
5
5
|
applicationId: { type: mongoose.Schema.Types.ObjectId, ref: "Application", required: true },
|
|
@@ -37,6 +37,5 @@ const rationaleSchema = new mongoose.Schema({
|
|
|
37
37
|
propertyStatusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup" },
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
rationaleSchema.plugin(mongooseEncryption);
|
|
41
40
|
const ApplicationRationaleModel = mongoose.model("ApplicationRationale", rationaleSchema);
|
|
42
41
|
export default ApplicationRationaleModel;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
-
import mongooseEncryption from '../utils/encryption.middleware.js';
|
|
3
2
|
|
|
4
3
|
const applicantionRiskNarrativeSchema = new mongoose.Schema({
|
|
5
4
|
call1RequestedOn: { type: String },
|
|
@@ -11,7 +10,6 @@ const applicantionRiskNarrativeSchema = new mongoose.Schema({
|
|
|
11
10
|
statusLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null },
|
|
12
11
|
});
|
|
13
12
|
|
|
14
|
-
applicantionRiskNarrativeSchema.plugin(mongooseEncryption);
|
|
15
13
|
const ApplicationRiskNarrativeModel = mongoose.model('ApplicationRiskNarrative', applicantionRiskNarrativeSchema);
|
|
16
14
|
export default ApplicationRiskNarrativeModel;
|
|
17
15
|
|
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
|
|
2
2
|
import directDebitSchema from "./application-direct-debit.model.js";
|
|
3
3
|
import creditProfileSchema from "./application-credit-profile.model.js";
|
|
4
4
|
import mortgageSchema from "./application-mortgage.model.js";
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
|
|
7
7
|
const applicationSchema = new mongoose.Schema(
|
|
8
8
|
{
|
|
@@ -147,6 +147,5 @@ applicationSchema.virtual('solicitorPhone').get(function () {
|
|
|
147
147
|
return this.solicitorId ? this.solicitorId?.telephone : null;
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
applicationSchema.plugin(mongooseEncryption);
|
|
151
150
|
const ApplicationModel = mongoose.model("Application", applicationSchema);
|
|
152
151
|
export default ApplicationModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const brokerSchema = new mongoose.Schema({
|
|
5
5
|
brokerId: { type: String },
|
|
@@ -22,6 +22,5 @@ const brokerSchema = new mongoose.Schema({
|
|
|
22
22
|
{ timestamps: true });
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
brokerSchema.plugin(mongooseEncryption);
|
|
26
25
|
const BrokerModel = mongoose.model("Broker", brokerSchema);
|
|
27
26
|
export default BrokerModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const documentSchema = new mongoose.Schema({
|
|
5
5
|
applicationId: {
|
|
@@ -34,6 +34,5 @@ const documentSchema = new mongoose.Schema({
|
|
|
34
34
|
timestamps: true
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
documentSchema.plugin(mongooseEncryption);
|
|
38
37
|
const DocumentModel = mongoose.model("Document", documentSchema);
|
|
39
38
|
export default DocumentModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const feeSchema = new mongoose.Schema({
|
|
5
5
|
feeType: { type: String, required: true },
|
|
@@ -97,6 +97,5 @@ const productFeaturesSchema = new mongoose.Schema({
|
|
|
97
97
|
calculations: calculationsSchema
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
productFeaturesSchema.plugin(mongooseEncryption);
|
|
101
100
|
const ProductFeaturesModel = mongoose.model("ProductFeature", productFeaturesSchema);
|
|
102
101
|
export default ProductFeaturesModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const Schema = mongoose.Schema;
|
|
5
5
|
|
|
@@ -32,6 +32,5 @@ const solicitorSchema = new Schema({
|
|
|
32
32
|
telephone: { type: String,},
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
solicitorSchema.plugin(mongooseEncryption);
|
|
36
35
|
const SolicitorModel = mongoose.model("Solicitor", solicitorSchema);
|
|
37
36
|
export default SolicitorModel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamatix/gb-schemas",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.7",
|
|
4
4
|
"description": "All the schemas for gatehouse bank back-end",
|
|
5
5
|
"main": "lookup.service.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/DynamatixAnalyticsPvtLtd/gb-schemas#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"mongodb": "^6.14.2",
|
|
21
22
|
"mongoose": "^8.9.5"
|
|
22
23
|
},
|
|
23
24
|
"exports": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const productCatalogueSchema = new mongoose.Schema({
|
|
5
5
|
productCatalogueId: { type: String, required: true },
|
|
@@ -17,6 +17,5 @@ const productCatalogueSchema = new mongoose.Schema({
|
|
|
17
17
|
timestamps: true
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
productCatalogueSchema.plugin(mongooseEncryption);
|
|
21
20
|
const ProductCatalogueModel = mongoose.model('ProductCatalogue', productCatalogueSchema);
|
|
22
21
|
export default ProductCatalogueModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const ruleSchema = new mongoose.Schema({
|
|
5
5
|
ruleId: { type: String, required: true },
|
|
@@ -26,6 +26,5 @@ const productDefinitionsSchema = new mongoose.Schema({
|
|
|
26
26
|
timestamps: true
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
productDefinitionsSchema.plugin(mongooseEncryption);
|
|
30
29
|
const ProductDefinitionsModel = mongoose.model('ProductDefinitions', productDefinitionsSchema);
|
|
31
30
|
export default ProductDefinitionsModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const productVariantSchema = new mongoose.Schema({
|
|
5
5
|
productCatalogueId: { ref: "ProductCatalogue", type: mongoose.Schema.Types.ObjectId, required: true },
|
|
@@ -12,6 +12,5 @@ const productVariantSchema = new mongoose.Schema({
|
|
|
12
12
|
timestamps: true
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
productVariantSchema.plugin(mongooseEncryption);
|
|
16
15
|
const ProductVariantModel = mongoose.model('ProductVariant', productVariantSchema);
|
|
17
16
|
export default ProductVariantModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const dataStreetSchema = new mongoose.Schema({
|
|
5
5
|
floorArea: { type: String, default: '' },
|
|
@@ -110,6 +110,5 @@ propertySchema.virtual('tenure').get(function () {
|
|
|
110
110
|
return this.propertyTypeLid ? this.propertyTypeLid.name : null;
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
propertySchema.plugin(mongooseEncryption);
|
|
114
113
|
const PropertyModel = mongoose.model("Property", propertySchema);
|
|
115
114
|
export default PropertyModel;
|
package/shared/alert.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const alertSchema = new mongoose.Schema({
|
|
5
5
|
alertTypeLid: {
|
|
@@ -23,7 +23,6 @@ const alertSchema = new mongoose.Schema({
|
|
|
23
23
|
isActive: { type: String, default: true },
|
|
24
24
|
}, { timestamps: true });
|
|
25
25
|
|
|
26
|
-
alertSchema.plugin(mongooseEncryption);
|
|
27
26
|
const AlertModel = mongoose.model("Alert", alertSchema);
|
|
28
27
|
|
|
29
28
|
export default AlertModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const checklistSchema = new mongoose.Schema({
|
|
5
5
|
checkTypeLid: {
|
|
@@ -31,7 +31,6 @@ const checklistSchema = new mongoose.Schema({
|
|
|
31
31
|
|
|
32
32
|
checklistSchema.index({ checkDescription: 'text', source: 'text' });
|
|
33
33
|
|
|
34
|
-
checklistSchema.plugin(mongooseEncryption);
|
|
35
34
|
const CheckListModel = mongoose.model("CheckList", checklistSchema);
|
|
36
35
|
|
|
37
36
|
export default CheckListModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const lookupGroupSchema = new mongoose.Schema({
|
|
5
5
|
name: {
|
|
@@ -14,6 +14,5 @@ const lookupGroupSchema = new mongoose.Schema({
|
|
|
14
14
|
],
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
lookupGroupSchema.plugin(mongooseEncryption);
|
|
18
17
|
const LookupGroupModel = mongoose.model('LookupGroup', lookupGroupSchema);
|
|
19
18
|
export default LookupGroupModel;
|
package/shared/lookup.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const lookupSchema = new mongoose.Schema({
|
|
5
5
|
name: {
|
|
@@ -19,6 +19,5 @@ const lookupSchema = new mongoose.Schema({
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
lookupSchema.plugin(mongooseEncryption);
|
|
23
22
|
const LookupModel = mongoose.model('Lookup', lookupSchema);
|
|
24
23
|
export default LookupModel;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
-
import mongooseEncryption from '../utils/encryption.middleware.js';
|
|
3
2
|
|
|
4
3
|
// Define the schema for TaskDocumentType
|
|
5
4
|
const taskDocumentTypeSchema = new mongoose.Schema({
|
|
@@ -22,8 +21,6 @@ const taskDocumentTypeSchema = new mongoose.Schema({
|
|
|
22
21
|
},
|
|
23
22
|
});
|
|
24
23
|
|
|
25
|
-
// Create the Mongoose model
|
|
26
|
-
taskDocumentTypeSchema.plugin(mongooseEncryption);
|
|
27
24
|
const TaskDocumentTypeModel = mongoose.model('TaskDocumentType', taskDocumentTypeSchema);
|
|
28
25
|
|
|
29
26
|
export default TaskDocumentTypeModel;
|
package/shared/task.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const { Schema } = mongoose;
|
|
5
5
|
|
|
@@ -17,6 +17,5 @@ const taskSchema = new Schema({
|
|
|
17
17
|
actionsOnSuccess: { type: [actionSchema], default: [] },
|
|
18
18
|
}, { timestamps: true });
|
|
19
19
|
|
|
20
|
-
taskSchema.plugin(mongooseEncryption);
|
|
21
20
|
const TaskModel = mongoose.model("Task", taskSchema);
|
|
22
21
|
export default TaskModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const underwritersSchema = new mongoose.Schema({
|
|
@@ -17,6 +17,5 @@ const underwritersSchema = new mongoose.Schema({
|
|
|
17
17
|
timestamps: true
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
underwritersSchema.plugin(mongooseEncryption);
|
|
21
20
|
const UnderwritersModel = mongoose.model('Underwriter', underwritersSchema);
|
|
22
21
|
export default UnderwritersModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const permissionSchema = new mongoose.Schema({
|
|
5
5
|
name: { type: String, required: true },
|
|
@@ -9,7 +9,6 @@ const permissionSchema = new mongoose.Schema({
|
|
|
9
9
|
timestamps: true
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
permissionSchema.plugin(mongooseEncryption);
|
|
13
12
|
const PermissionModel = mongoose.model('Permission', permissionSchema);
|
|
14
13
|
|
|
15
14
|
export default PermissionModel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const RoleGroupSchema = new mongoose.Schema({
|
|
5
5
|
groupId: { type: String, required: true },
|
|
@@ -13,6 +13,5 @@ const RoleGroupSchema = new mongoose.Schema({
|
|
|
13
13
|
timestamps: true
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
RoleGroupSchema.plugin(mongooseEncryption);
|
|
17
16
|
const RoleGroupModel = mongoose.model('RoleGroup', RoleGroupSchema);
|
|
18
17
|
export default RoleGroupModel;
|
package/users/role.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const RoleSchema = new mongoose.Schema({
|
|
5
5
|
roleId: { type: String, required: true },
|
|
@@ -12,7 +12,6 @@ const RoleSchema = new mongoose.Schema({
|
|
|
12
12
|
timestamps: true
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
RoleSchema.plugin(mongooseEncryption);
|
|
16
15
|
const RoleModel = mongoose.model('Role', RoleSchema);
|
|
17
16
|
|
|
18
17
|
export default RoleModel;
|
package/users/tasks.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const TasksSchema = new mongoose.Schema({
|
|
5
5
|
taskTypeLid: { type: mongoose.Schema.Types.ObjectId, ref: "Lookup", default: null }, // LookupGroup: TaskType ["Document", "Information"]
|
|
@@ -14,7 +14,6 @@ const TasksSchema = new mongoose.Schema({
|
|
|
14
14
|
timestamps: true
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
TasksSchema.plugin(mongooseEncryption);
|
|
18
17
|
const TasksModel = mongoose.model("Tasks", TasksSchema);
|
|
19
18
|
|
|
20
19
|
export default TasksModel;
|
package/users/user.model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
|
|
4
4
|
const ClaimSchema = new mongoose.Schema({
|
|
5
5
|
key: { type: String, required: true },
|
|
@@ -30,7 +30,6 @@ const userSchema = new mongoose.Schema({
|
|
|
30
30
|
timestamps: true
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
userSchema.plugin(mongooseEncryption);
|
|
34
33
|
const UserModel = mongoose.model('User', userSchema);
|
|
35
34
|
|
|
36
35
|
export default UserModel;
|
package/utils/encryption.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
import mongoose from 'mongoose';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
|
|
7
|
-
// Get current directory
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
// Load environment variables
|
|
12
|
-
dotenv.config({
|
|
13
|
-
path: path.resolve(__dirname, '../../../../.env'),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// Encryption settings
|
|
17
|
-
const SECRET_KEY = Buffer.from(process.env.ENCRYPTION_KEY, 'hex'); // 32 bytes for AES-256
|
|
18
|
-
const IV_LENGTH = 16; // AES-GCM IV length
|
|
19
|
-
const EXCLUDED_COLLECTIONS = process.env.EXCLUDED_COLLECTIONS?.split(',') || []; // Collections excluded from encryption
|
|
20
|
-
|
|
21
|
-
// Function to check if a value is an ObjectId or array of ObjectIds
|
|
22
|
-
const isObjectIdOrArray = (value) => {
|
|
23
|
-
if (Array.isArray(value)) {
|
|
24
|
-
return value.every((item) => mongoose.isValidObjectId(item));
|
|
25
|
-
}
|
|
26
|
-
return mongoose.isValidObjectId(value);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// **Deterministic IV Generation (for consistent encryption)**
|
|
30
|
-
const deriveIV = (value) => {
|
|
31
|
-
const hash = crypto.createHash('sha256').update(value.toString()).digest();
|
|
32
|
-
return hash.slice(0, IV_LENGTH); // First 16 bytes as IV
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// **Encrypt a Single Value Deterministically**
|
|
36
|
-
const encryptValue = (value) => {
|
|
37
|
-
if(!value) {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
const iv = deriveIV(value); // Same IV for same value (allows searching)
|
|
41
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', SECRET_KEY, iv);
|
|
42
|
-
|
|
43
|
-
let encrypted = cipher.update(JSON.stringify(value), 'utf8', 'hex');
|
|
44
|
-
encrypted += cipher.final('hex');
|
|
45
|
-
|
|
46
|
-
const authTag = cipher.getAuthTag().toString('hex'); // Authentication tag
|
|
47
|
-
|
|
48
|
-
return `${iv.toString('hex')}:${authTag}:${encrypted}`;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// **Encrypt an Object (excluding ObjectId references & _id)**
|
|
52
|
-
export const encryptObject = (obj, collectionName) => {
|
|
53
|
-
if (EXCLUDED_COLLECTIONS.includes(collectionName) || !obj || typeof obj !== 'object') {
|
|
54
|
-
return obj;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let encryptedObj = {};
|
|
58
|
-
for (const key in obj) {
|
|
59
|
-
if (key === '_id' || isObjectIdOrArray(obj[key])) {
|
|
60
|
-
encryptedObj[key] = obj[key]; // Keep _id and ObjectId references unchanged
|
|
61
|
-
} else {
|
|
62
|
-
try {
|
|
63
|
-
encryptedObj[key] = encryptValue(obj[key]);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error(`Encryption error for key "${key}":`, error);
|
|
66
|
-
encryptedObj[key] = obj[key]; // Fallback to original value
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return encryptedObj;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// **Decrypt an Object (excluding ObjectId references & _id)**
|
|
75
|
-
export const decryptObject = (obj, collectionName) => {
|
|
76
|
-
if (EXCLUDED_COLLECTIONS.includes(collectionName) || !obj || typeof obj !== 'object') {
|
|
77
|
-
return obj;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let decryptedObj = {};
|
|
81
|
-
for (const key in obj) {
|
|
82
|
-
if (key === '_id' || isObjectIdOrArray(obj[key])) {
|
|
83
|
-
decryptedObj[key] = obj[key]; // Keep _id and ObjectId references unchanged
|
|
84
|
-
} else {
|
|
85
|
-
try {
|
|
86
|
-
if(Array.isArray(obj[key]) || !obj[key]) {
|
|
87
|
-
decryptedObj[key] = obj[key];
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const [ivHex, authTagHex, encryptedData] = obj[key].split(':');
|
|
91
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
92
|
-
const authTag = Buffer.from(authTagHex, 'hex');
|
|
93
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', SECRET_KEY, iv);
|
|
94
|
-
decipher.setAuthTag(authTag);
|
|
95
|
-
let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
|
|
96
|
-
decrypted += decipher.final('utf8');
|
|
97
|
-
decryptedObj[key] = JSON.parse(decrypted);
|
|
98
|
-
} catch (error) {
|
|
99
|
-
console.error(`Decryption error for key "${key}":`, error);
|
|
100
|
-
decryptedObj[key] = obj[key]; // Fallback to original value
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return decryptedObj;
|
|
106
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
import { decryptObject, encryptObject } from '@dynamatix/gb-schemas/utils';
|
|
3
|
-
|
|
4
|
-
dotenv.config();
|
|
5
|
-
|
|
6
|
-
// Read excluded collections from .env
|
|
7
|
-
const EXCLUDED_COLLECTIONS = process.env.EXCLUDED_COLLECTIONS?.split(",") || [];
|
|
8
|
-
|
|
9
|
-
export default function mongooseEncryption(schema, options) {
|
|
10
|
-
console.log("========MONGOOSE ENCRYPTION IS IN PROGRESS");
|
|
11
|
-
|
|
12
|
-
const collectionName = options?.collection || schema.options.collection;
|
|
13
|
-
|
|
14
|
-
// Skip encryption for excluded collections
|
|
15
|
-
if (EXCLUDED_COLLECTIONS.includes(collectionName)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Encrypt query parameters before execution
|
|
20
|
-
schema.pre(['find', 'findOne', 'findById'], function (next) {
|
|
21
|
-
this.getQuery(); // Ensure the query is processed
|
|
22
|
-
const encryptedQuery = encryptObject(this.getQuery(), collectionName);
|
|
23
|
-
this.setQuery(encryptedQuery);
|
|
24
|
-
next();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// Encrypt before saving (e.g., insert, update)
|
|
29
|
-
schema.pre(['save','create'], function (next) {
|
|
30
|
-
// Encrypt the document before saving to the database
|
|
31
|
-
this.set(encryptObject(this.toObject(), collectionName)); // Encrypt the document
|
|
32
|
-
next();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Encrypt before update operations (single or multiple documents)
|
|
36
|
-
schema.pre("update", function (result) {
|
|
37
|
-
if (Array.isArray(result)) {
|
|
38
|
-
result.forEach(doc => doc.set(decryptObject(doc.toObject(), collectionName)));
|
|
39
|
-
} else {
|
|
40
|
-
result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Encrypt after updateOne operations
|
|
45
|
-
schema.pre(["updateOne","findOneAndUpdate"], function (result) {
|
|
46
|
-
if (result && result.toObject) {
|
|
47
|
-
result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Encrypt before bulkWrite operations
|
|
52
|
-
schema.pre("bulkWrite", function (next, operations) {
|
|
53
|
-
operations.forEach(operation => {
|
|
54
|
-
if (operation.insertOne && operation.insertOne.document) {
|
|
55
|
-
operation.insertOne.document = encryptObject(operation.insertOne.document, collectionName);
|
|
56
|
-
} else if (operation.updateOne && operation.updateOne.update) {
|
|
57
|
-
operation.updateOne.update = encryptObject(operation.updateOne.update, collectionName);
|
|
58
|
-
} else if (operation.updateMany && operation.updateMany.update) {
|
|
59
|
-
operation.updateMany.update = encryptObject(operation.updateMany.update, collectionName);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
next();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const decryptDocument = (doc, collectionName) => {
|
|
66
|
-
if (!doc || doc.$locals.hasDecrypted) return doc; // ✅ Skip if already decrypted
|
|
67
|
-
|
|
68
|
-
// ✅ Convert document to object before decrypting
|
|
69
|
-
const decrypted = decryptObject(doc.toObject(), collectionName);
|
|
70
|
-
|
|
71
|
-
// ✅ Preserve and decrypt populated fields
|
|
72
|
-
Object.keys(doc.toObject()).forEach((key) => {
|
|
73
|
-
if (doc.populated && doc.populated(key)) {
|
|
74
|
-
if (Array.isArray(doc[key])) {
|
|
75
|
-
decrypted[key] = doc[key]
|
|
76
|
-
// ✅ Decrypt each populated document in an array
|
|
77
|
-
// decrypted[key] = doc[key].map((subDoc) =>
|
|
78
|
-
// subDoc.toObject ? decryptObject(subDoc.toObject(), "LookupModel") : subDoc
|
|
79
|
-
// );
|
|
80
|
-
} else {
|
|
81
|
-
// ✅ Decrypt a single populated document
|
|
82
|
-
decrypted[key] = doc[key]?.toObject
|
|
83
|
-
? decryptObject(doc[key].toObject(), "LookupModel")
|
|
84
|
-
: doc[key];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// ✅ Set the flag to prevent duplicate decryption
|
|
90
|
-
doc.$locals.hasDecrypted = true;
|
|
91
|
-
|
|
92
|
-
return Object.assign(doc, decrypted); // ✅ Update the document safely
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// ✅ Middleware for find()
|
|
96
|
-
schema.post(['find'], function (docs, next) {
|
|
97
|
-
if (!docs || !Array.isArray(docs)) return next(); // ✅ Skip if no document found
|
|
98
|
-
|
|
99
|
-
docs.forEach((doc, index) => {
|
|
100
|
-
docs[index] = decryptDocument(doc, this.collection.name);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
next();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// ✅ Middleware for findOne() and findById()
|
|
107
|
-
schema.post(['findOne', 'findById'], function (doc, next) {
|
|
108
|
-
if (!doc) return next(); // ✅ Skip if no document found
|
|
109
|
-
|
|
110
|
-
doc = decryptDocument(doc, this.collection.name);
|
|
111
|
-
|
|
112
|
-
next();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// Decrypt after update operations (single or multiple documents)
|
|
117
|
-
schema.post(["update","create","save"], function (result) {
|
|
118
|
-
if (Array.isArray(result)) {
|
|
119
|
-
result.forEach(doc => doc.set(decryptObject(doc.toObject(), collectionName)));
|
|
120
|
-
} else {
|
|
121
|
-
result.set(decryptObject(result.toObject(), collectionName)); // Decrypt single document
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Decrypt after updateOne operations
|
|
126
|
-
schema.post("updateOne", function (result) {
|
|
127
|
-
if (result && result.toObject) {
|
|
128
|
-
result.set(decryptObject(result.toObject(), collectionName)); // Decrypt single document
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// Decrypt after findOneAndUpdate operations
|
|
134
|
-
schema.post(["findOneAndUpdate","findOneAndDelete","deleteOne","remove"], function (doc) {
|
|
135
|
-
if (doc) {
|
|
136
|
-
doc.set(decryptObject(doc.toObject(), collectionName)); // Decrypt single document
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Decrypt after deleteMany operations
|
|
141
|
-
schema.post("deleteMany", function (result) {
|
|
142
|
-
if (Array.isArray(result)) {
|
|
143
|
-
result.forEach(doc => doc.set(decryptObject(doc.toObject(), collectionName))); // Decrypt document fields
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|