blixify-server 0.1.75 → 0.1.78
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.
|
@@ -14,10 +14,15 @@ export declare class MongoWrapper {
|
|
|
14
14
|
config: SecurityConfig;
|
|
15
15
|
lib: WrapperLib;
|
|
16
16
|
tableId: string;
|
|
17
|
+
logId: string;
|
|
17
18
|
debug: any;
|
|
18
19
|
modelChecker: (obj: any) => boolean;
|
|
19
|
-
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
|
|
20
|
+
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, logId?: string, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
|
|
20
21
|
parseModel: (data: any) => any;
|
|
22
|
+
handleLogging: (mongoId: any, type: "create" | "update" | "delete", req: any, value?: {
|
|
23
|
+
new?: any;
|
|
24
|
+
old?: any;
|
|
25
|
+
}) => Promise<void>;
|
|
21
26
|
initBatchCreate: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<{
|
|
22
27
|
success: string[];
|
|
23
28
|
} | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAUA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAmGD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,S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,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAsCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBAoQlC;IAEF,IAAI,YA+EF;CACH"}
|
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MongoWrapper = void 0;
|
|
16
16
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
17
|
+
const uuid_1 = require("uuid");
|
|
17
18
|
const QueryModel_1 = require("../model/QueryModel");
|
|
18
19
|
const utils_1 = require("./utils");
|
|
19
20
|
const handleParseQueryFilter = (queryList, prefix) => {
|
|
@@ -123,7 +124,7 @@ const handleParseQueryFilter = (queryList, prefix) => {
|
|
|
123
124
|
*
|
|
124
125
|
*/
|
|
125
126
|
class MongoWrapper {
|
|
126
|
-
constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, debug) {
|
|
127
|
+
constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, logId, debug) {
|
|
127
128
|
this.mongoDB = "";
|
|
128
129
|
this.collection = "";
|
|
129
130
|
this.isProd = false;
|
|
@@ -137,6 +138,7 @@ class MongoWrapper {
|
|
|
137
138
|
},
|
|
138
139
|
};
|
|
139
140
|
this.tableId = "";
|
|
141
|
+
this.logId = "";
|
|
140
142
|
// eslint-disable-next-line
|
|
141
143
|
this.modelChecker = (obj) => {
|
|
142
144
|
return false;
|
|
@@ -146,6 +148,44 @@ class MongoWrapper {
|
|
|
146
148
|
data["baseUpdatedAt"] = (0, moment_timezone_1.default)().toDate();
|
|
147
149
|
return data;
|
|
148
150
|
};
|
|
151
|
+
this.handleLogging = (mongoId, type, req, value) => __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
if (!this.logId)
|
|
153
|
+
return;
|
|
154
|
+
try {
|
|
155
|
+
const userId = req.body["bm_userId"];
|
|
156
|
+
const userRole = req.body["bm_userRole"];
|
|
157
|
+
const organisationId = req.body["bm_userOrg"];
|
|
158
|
+
const changeValueList = [];
|
|
159
|
+
const dataDoc = type === "create" ? req.body.data : value === null || value === void 0 ? void 0 : value.new;
|
|
160
|
+
Object.keys(dataDoc).map((eachKey) => {
|
|
161
|
+
var _a;
|
|
162
|
+
const eachChangeValue = {
|
|
163
|
+
newValue: dataDoc[eachKey],
|
|
164
|
+
columnId: eachKey,
|
|
165
|
+
};
|
|
166
|
+
if (type === "update")
|
|
167
|
+
eachChangeValue["oldValue"] = (_a = value === null || value === void 0 ? void 0 : value.old) === null || _a === void 0 ? void 0 : _a[eachKey];
|
|
168
|
+
if (eachKey !== "_id" && !eachKey.startsWith("base"))
|
|
169
|
+
changeValueList.push(eachChangeValue);
|
|
170
|
+
});
|
|
171
|
+
const logItem = {
|
|
172
|
+
_id: (0, uuid_1.v4)(),
|
|
173
|
+
type,
|
|
174
|
+
itemId: mongoId,
|
|
175
|
+
collectionId: this.collection,
|
|
176
|
+
createdAt: (0, moment_timezone_1.default)().toDate(),
|
|
177
|
+
values: changeValueList,
|
|
178
|
+
userId,
|
|
179
|
+
userRole,
|
|
180
|
+
organisationId,
|
|
181
|
+
};
|
|
182
|
+
const mongoLogCollection = this.mongoDB
|
|
183
|
+
.db(this.tableId)
|
|
184
|
+
.collection(this.logId);
|
|
185
|
+
yield mongoLogCollection.insertOne(logItem);
|
|
186
|
+
}
|
|
187
|
+
catch (err) { }
|
|
188
|
+
});
|
|
149
189
|
this.initBatchCreate = (req, res, workflow) => __awaiter(this, void 0, void 0, function* () {
|
|
150
190
|
var _a;
|
|
151
191
|
try {
|
|
@@ -239,7 +279,9 @@ class MongoWrapper {
|
|
|
239
279
|
}
|
|
240
280
|
if (workflow)
|
|
241
281
|
yield workflow(req.body.data);
|
|
242
|
-
yield mongoCollection.insertOne(req.body.data);
|
|
282
|
+
const mongoResult = yield mongoCollection.insertOne(req.body.data);
|
|
283
|
+
const mongoId = mongoResult.insertedId.toString();
|
|
284
|
+
this.handleLogging(mongoId, "create", req);
|
|
243
285
|
const resBody = { success: true };
|
|
244
286
|
if ((_c = req.body) === null || _c === void 0 ? void 0 : _c.stopRes)
|
|
245
287
|
return resBody;
|
|
@@ -377,7 +419,7 @@ class MongoWrapper {
|
|
|
377
419
|
validOpsConfig = false;
|
|
378
420
|
}
|
|
379
421
|
const { workflowUpdateFields } = (0, utils_1.compareUpdatedFields)(eachData, req.body.data);
|
|
380
|
-
workflowUpdateFieldsList.push(workflowUpdateFields);
|
|
422
|
+
workflowUpdateFieldsList.push(Object.assign(Object.assign({}, workflowUpdateFields), { _id: eachData === null || eachData === void 0 ? void 0 : eachData._id }));
|
|
381
423
|
}));
|
|
382
424
|
if (!validBaseConfig || !validOpsConfig) {
|
|
383
425
|
res.status(400).json({ err: "Invalid Security Configuration" });
|
|
@@ -442,7 +484,7 @@ class MongoWrapper {
|
|
|
442
484
|
const { updatedFields } = (0, utils_1.compareUpdatedFields)(mongoData, req.body.data);
|
|
443
485
|
const resBody = { success: true };
|
|
444
486
|
if (workflow)
|
|
445
|
-
yield workflow(updatedFields);
|
|
487
|
+
yield workflow(Object.assign(Object.assign({}, updatedFields), { _id: valid }));
|
|
446
488
|
const data = this.parseModel(updatedFields);
|
|
447
489
|
if (req.body.sensitive) {
|
|
448
490
|
if ((0, moment_timezone_1.default)(req.body.data.baseUpdatedAt).isAfter((0, moment_timezone_1.default)(mongoData.baseUpdatedAt))) {
|
|
@@ -469,6 +511,14 @@ class MongoWrapper {
|
|
|
469
511
|
return resBody;
|
|
470
512
|
res.send(resBody);
|
|
471
513
|
}
|
|
514
|
+
const oldData = {};
|
|
515
|
+
Object.keys(data).map((eachUpdateKey) => {
|
|
516
|
+
oldData[eachUpdateKey] = mongoData[eachUpdateKey];
|
|
517
|
+
});
|
|
518
|
+
this.handleLogging(valid, "update", req, {
|
|
519
|
+
old: oldData,
|
|
520
|
+
new: data,
|
|
521
|
+
});
|
|
472
522
|
}
|
|
473
523
|
else {
|
|
474
524
|
res.status(400).json({ err: "Invalid Model Structure" });
|
|
@@ -627,6 +677,7 @@ class MongoWrapper {
|
|
|
627
677
|
yield mongoCollection.findOneAndDelete({
|
|
628
678
|
_id: valid,
|
|
629
679
|
});
|
|
680
|
+
this.handleLogging(mongoData._id, "delete", req, { new: mongoData });
|
|
630
681
|
const resBody = { success: true };
|
|
631
682
|
if ((_o = req.body) === null || _o === void 0 ? void 0 : _o.stopRes)
|
|
632
683
|
return resBody;
|
|
@@ -943,6 +994,7 @@ class MongoWrapper {
|
|
|
943
994
|
this.lib = lib;
|
|
944
995
|
const tableSuffix = this.isProd ? "prod" : "dev";
|
|
945
996
|
this.tableId = tableId ? `${tableId}-${tableSuffix}` : tableSuffix;
|
|
997
|
+
this.logId = logId !== null && logId !== void 0 ? logId : "";
|
|
946
998
|
this.debug = debug;
|
|
947
999
|
}
|
|
948
1000
|
}
|
package/dist/apis/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ const compareUpdatedFields = (prevData, currentData) => {
|
|
|
9
9
|
updatedFields[key] = prevData[key];
|
|
10
10
|
});
|
|
11
11
|
Object.keys(currentData).forEach((key) => {
|
|
12
|
-
if (currentData[key] !== prevData[key]) {
|
|
12
|
+
if (JSON.stringify(currentData[key]) !== JSON.stringify(prevData[key])) {
|
|
13
13
|
updatedFields[key] = currentData[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type DataType = "string" | "email" | "person" | "contact" | "date" | "number" | "boolean" | "image" | "file" | "multipleImage" | "multipleFile" | "reference" | "object" | "address" | "multipleList" | "list" | "listReference" | "listObject" | "markdown" | "textArea";
|
|
2
|
+
export interface ChangeValue {
|
|
3
|
+
newValue: any;
|
|
4
|
+
oldValue?: any;
|
|
5
|
+
columnId: string;
|
|
6
|
+
columnType?: DataType;
|
|
7
|
+
}
|
|
8
|
+
export interface Log {
|
|
9
|
+
_id: string;
|
|
10
|
+
type: "create" | "update" | "delete";
|
|
11
|
+
itemId: string;
|
|
12
|
+
collectionId: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
values: ChangeValue[];
|
|
15
|
+
userId?: string;
|
|
16
|
+
userRole?: string;
|
|
17
|
+
organisationId?: string;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=Log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Log.d.ts","sourceRoot":"","sources":["../../src/model/Log.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GACT,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,SAAS,GACT,MAAM,GACN,QAAQ,GACR,SAAS,GACT,OAAO,GACP,MAAM,GACN,eAAe,GACf,cAAc,GACd,WAAW,GACX,QAAQ,GACR,SAAS,GACT,cAAc,GACd,MAAM,GACN,eAAe,GACf,YAAY,GACZ,UAAU,GACV,UAAU,CAAC;AAEf,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,QAAQ,CAAC;CACvB;AACD,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|