@volcanicminds/backend 0.5.3 → 0.6.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/dist/index.js +41 -33
- package/dist/index.js.map +1 -1
- package/dist/lib/config/tracking.js +10 -0
- package/dist/lib/config/tracking.js.map +1 -0
- package/dist/lib/hooks/preHandler.js +39 -0
- package/dist/lib/hooks/preHandler.js.map +1 -0
- package/dist/lib/hooks/preSerialization.js +25 -0
- package/dist/lib/hooks/preSerialization.js.map +1 -1
- package/dist/lib/loader/tracking.js +68 -0
- package/dist/lib/loader/tracking.js.map +1 -0
- package/dist/lib/util/tracker.js +105 -0
- package/dist/lib/util/tracker.js.map +1 -0
- package/dist/package.json +2 -1
- package/index.ts +42 -33
- package/lib/config/tracking.ts +18 -0
- package/lib/hooks/preHandler.ts +5 -0
- package/lib/hooks/preSerialization.ts +3 -0
- package/lib/loader/tracking.ts +76 -0
- package/lib/util/tracker.ts +90 -0
- package/package.json +2 -1
- package/types/global.d.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ const loaderRoles = __importStar(require("./lib/loader/roles"));
|
|
|
49
49
|
const loaderRouter = __importStar(require("./lib/loader/router"));
|
|
50
50
|
const loaderHooks = __importStar(require("./lib/loader/hooks"));
|
|
51
51
|
const loaderSchemas = __importStar(require("./lib/loader/schemas"));
|
|
52
|
+
const loaderTracking = __importStar(require("./lib/loader/tracking"));
|
|
52
53
|
const loaderTranslation = __importStar(require("./lib/loader/translation"));
|
|
53
54
|
const fastify_1 = __importDefault(require("fastify"));
|
|
54
55
|
const jwt_1 = __importDefault(require("@fastify/jwt"));
|
|
@@ -159,7 +160,8 @@ const start = (decorators) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
159
160
|
mark.print(logger_1.default);
|
|
160
161
|
global.roles = loaderRoles.load();
|
|
161
162
|
global.t = loaderTranslation.load();
|
|
162
|
-
|
|
163
|
+
global.tracking = loaderTracking.load();
|
|
164
|
+
const opts = (0, yn_1.default)(process.env.LOG_FASTIFY, false) ? { logger: { development: logger_1.default } } : { logger: true };
|
|
163
165
|
const server = (0, fastify_1.default)();
|
|
164
166
|
const { HOST: host = '0.0.0.0', PORT: port = '2230', GRAPHQL } = process.env;
|
|
165
167
|
const { JWT_SECRET = '', JWT_EXPIRES_IN = '15d', JWT_REFRESH = 'true', JWT_REFRESH_SECRET = '', JWT_REFRESH_EXPIRES_IN = '180d' } = process.env;
|
|
@@ -191,105 +193,111 @@ const start = (decorators) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
191
193
|
return false;
|
|
192
194
|
},
|
|
193
195
|
isValidUser(data) {
|
|
194
|
-
throw new Error('Not implemented');
|
|
196
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
195
197
|
},
|
|
196
198
|
createUser(data) {
|
|
197
|
-
throw new Error('Not implemented');
|
|
199
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
198
200
|
},
|
|
199
201
|
resetExternalId(data) {
|
|
200
|
-
throw new Error('Not implemented');
|
|
202
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
201
203
|
},
|
|
202
204
|
updateUserById(id, user) {
|
|
203
|
-
throw new Error('Not implemented');
|
|
205
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
204
206
|
},
|
|
205
207
|
retrieveUserById(id) {
|
|
206
|
-
throw new Error('Not implemented');
|
|
208
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
207
209
|
},
|
|
208
210
|
retrieveUserByEmail(email) {
|
|
209
|
-
throw new Error('Not implemented');
|
|
211
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
210
212
|
},
|
|
211
213
|
retrieveUserByConfirmationToken(code) {
|
|
212
|
-
throw new Error('Not implemented');
|
|
214
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
213
215
|
},
|
|
214
216
|
retrieveUserByResetPasswordToken(code) {
|
|
215
|
-
throw new Error('Not implemented');
|
|
217
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
216
218
|
},
|
|
217
219
|
retrieveUserByUsername(username) {
|
|
218
|
-
throw new Error('Not implemented');
|
|
220
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
219
221
|
},
|
|
220
222
|
retrieveUserByExternalId(externalId) {
|
|
221
|
-
throw new Error('Not implemented');
|
|
223
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
222
224
|
},
|
|
223
225
|
retrieveUserByPassword(email, password) {
|
|
224
|
-
throw new Error('Not implemented');
|
|
226
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
225
227
|
},
|
|
226
228
|
changePassword(email, password, oldPassword) {
|
|
227
|
-
throw new Error('Not implemented');
|
|
229
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
228
230
|
},
|
|
229
231
|
forgotPassword(email) {
|
|
230
|
-
throw new Error('Not implemented');
|
|
232
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
231
233
|
},
|
|
232
234
|
userConfirmation(user) {
|
|
233
|
-
throw new Error('Not implemented');
|
|
235
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
234
236
|
},
|
|
235
237
|
resetPassword(user, password) {
|
|
236
|
-
throw new Error('Not implemented');
|
|
238
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
237
239
|
},
|
|
238
240
|
blockUserById(id, reason) {
|
|
239
|
-
throw new Error('Not implemented');
|
|
241
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
240
242
|
},
|
|
241
243
|
unblockUserById(data) {
|
|
242
|
-
throw new Error('Not implemented');
|
|
244
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
243
245
|
},
|
|
244
246
|
countQuery(data) {
|
|
245
|
-
throw new Error('Not implemented');
|
|
247
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
246
248
|
},
|
|
247
249
|
findQuery(data) {
|
|
248
|
-
throw new Error('Not implemented');
|
|
250
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
249
251
|
}
|
|
250
252
|
}, tokenManager: {
|
|
251
253
|
isImplemented() {
|
|
252
254
|
return false;
|
|
253
255
|
},
|
|
254
256
|
isValidToken(data) {
|
|
255
|
-
throw new Error('Not implemented');
|
|
257
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
256
258
|
},
|
|
257
259
|
createToken(data) {
|
|
258
|
-
throw new Error('Not implemented');
|
|
260
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
259
261
|
},
|
|
260
262
|
resetExternalId(id) {
|
|
261
|
-
throw new Error('Not implemented');
|
|
263
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
262
264
|
},
|
|
263
265
|
updateTokenById(id, token) {
|
|
264
|
-
throw new Error('Not implemented');
|
|
266
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
265
267
|
},
|
|
266
268
|
retrieveTokenById(id) {
|
|
267
|
-
throw new Error('Not implemented');
|
|
269
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
268
270
|
},
|
|
269
271
|
retrieveTokenByExternalId(id) {
|
|
270
|
-
throw new Error('Not implemented');
|
|
272
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
271
273
|
},
|
|
272
274
|
blockTokenById(id, reason) {
|
|
273
|
-
throw new Error('Not implemented');
|
|
275
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
274
276
|
},
|
|
275
277
|
unblockTokenById(id) {
|
|
276
|
-
throw new Error('Not implemented');
|
|
278
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
277
279
|
},
|
|
278
280
|
countQuery(data) {
|
|
279
|
-
throw new Error('Not implemented');
|
|
281
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
280
282
|
},
|
|
281
283
|
findQuery(data) {
|
|
282
|
-
throw new Error('Not implemented');
|
|
284
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
283
285
|
},
|
|
284
286
|
removeTokenById(id) {
|
|
285
|
-
throw new Error('Not implemented');
|
|
287
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
286
288
|
}
|
|
287
289
|
}, dataBaseManager: {
|
|
288
290
|
isImplemented() {
|
|
289
|
-
return
|
|
291
|
+
return false;
|
|
290
292
|
},
|
|
291
293
|
synchronizeSchemas() {
|
|
292
|
-
throw new Error('Not implemented');
|
|
294
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
295
|
+
},
|
|
296
|
+
retrieveBy(entityName, entityId) {
|
|
297
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
298
|
+
},
|
|
299
|
+
addChange(entityName, entityId, status, userId, contents, changeEntity) {
|
|
300
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).');
|
|
293
301
|
}
|
|
294
302
|
} }, decorators);
|
|
295
303
|
yield Promise.all(Object.keys(decorators || {}).map((key) => __awaiter(void 0, void 0, void 0, function* () {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,oDAA2B;AAC3B,gBAAM,CAAC,MAAM,EAAE,CAAA;AAEf,uDAA8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,oDAA2B;AAC3B,gBAAM,CAAC,MAAM,EAAE,CAAA;AAEf,uDAA8B;AAiWrB,aAjWF,YAAE,CAiWE;AAhWX,+DAAsC;AACtC,sDAAuC;AACvC,8CAAmD;AA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E,eAAe,EAAf,wBAAe,EAAE,CAAA;AACtD,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,EAAE,EAAE,EAAF,YAAE,EAAE,KAAK,EAAE,eAAe,EAAf,wBAAe,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../../lib/config/tracking.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE;QACN,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,QAAQ;QACtB,UAAU,EAAE,IAAI;KACjB;IACD,OAAO,EAAE,EAUR;CACF,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const tracking = __importStar(require("../util/tracker"));
|
|
36
|
+
module.exports = (req, reply) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
tracking.initialize(req, reply);
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=preHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preHandler.js","sourceRoot":"","sources":["../../../lib/hooks/preHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA2C;AAE3C,MAAM,CAAC,OAAO,GAAG,CAAO,GAAG,EAAE,KAAK,EAAE,EAAE;IACpC,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC,CAAA,CAAA"}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,10 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
36
|
};
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
const object_sizeof_1 = __importDefault(require("object-sizeof"));
|
|
39
|
+
const tracking = __importStar(require("../util/tracker"));
|
|
16
40
|
module.exports = (req, reply, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
41
|
if (log.t) {
|
|
18
42
|
req.payloadSize = (0, object_sizeof_1.default)(req.body) + (0, object_sizeof_1.default)(req.params) + (0, object_sizeof_1.default)(req.query);
|
|
19
43
|
reply.payloadSize = (0, object_sizeof_1.default)(payload);
|
|
20
44
|
}
|
|
45
|
+
tracking.track(req, reply, payload);
|
|
21
46
|
});
|
|
22
47
|
//# sourceMappingURL=preSerialization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preSerialization.js","sourceRoot":"","sources":["../../../lib/hooks/preSerialization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preSerialization.js","sourceRoot":"","sources":["../../../lib/hooks/preSerialization.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAkC;AAClC,0DAA2C;AAE3C,MAAM,CAAC,OAAO,GAAG,CAAO,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC7C,IAAI,GAAG,CAAC,CAAC,EAAE;QACT,GAAG,CAAC,WAAW,GAAG,IAAA,uBAAM,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAA,uBAAM,EAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAA,uBAAM,EAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC3E,KAAK,CAAC,WAAW,GAAG,IAAA,uBAAM,EAAC,OAAO,CAAC,CAAA;KACpC;IAED,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC,CAAA,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = void 0;
|
|
4
|
+
const path_1 = require("../util/path");
|
|
5
|
+
const glob = require('glob');
|
|
6
|
+
const METHODS = ['POST', 'PUT', 'DELETE'];
|
|
7
|
+
function load() {
|
|
8
|
+
const trackChangesList = {};
|
|
9
|
+
const patterns = (0, path_1.normalizePatterns)(['..', 'config', 'tracking.{ts,js}'], ['src', 'config', 'tracking.{ts,js}']);
|
|
10
|
+
patterns.forEach((pattern) => {
|
|
11
|
+
log.t && log.trace('Looking for ' + pattern);
|
|
12
|
+
glob.sync(pattern).forEach((f) => {
|
|
13
|
+
const configTracking = require(f);
|
|
14
|
+
const { config, changes } = configTracking || {};
|
|
15
|
+
const { enableAll = true, primaryKey = 'id', changeEntity = 'Change' } = config || {};
|
|
16
|
+
enableAll &&
|
|
17
|
+
changes.forEach((change) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const tc = Object.assign({ primaryKey: primaryKey, changeEntity: changeEntity }, change);
|
|
20
|
+
const code = getCodeBy(tc.method, tc.path);
|
|
21
|
+
if (code in trackChangesList) {
|
|
22
|
+
log.warn(`* Tracking changes on ${(_a = tc.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${tc.path} already loaded (override)`);
|
|
23
|
+
trackChangesList[code] = Object.assign(Object.assign({}, trackChangesList[code]), tc);
|
|
24
|
+
}
|
|
25
|
+
else if (isValid(tc)) {
|
|
26
|
+
trackChangesList[code] = tc;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
const keys = Object.keys(trackChangesList) || [];
|
|
32
|
+
log.d && log.debug(`Tracking changes loaded: ${(keys === null || keys === void 0 ? void 0 : keys.length) || 0}`);
|
|
33
|
+
return trackChangesList;
|
|
34
|
+
}
|
|
35
|
+
exports.load = load;
|
|
36
|
+
function getCodeBy(method, path) {
|
|
37
|
+
if (method == null || path == null) {
|
|
38
|
+
throw new Error('Tracking changes: impossible retrieve code by method and path');
|
|
39
|
+
}
|
|
40
|
+
return `${method.toUpperCase()}::${path}`;
|
|
41
|
+
}
|
|
42
|
+
function isValid(tc) {
|
|
43
|
+
const { method: m, path, enable = true, primaryKey, entity } = tc;
|
|
44
|
+
const method = m === null || m === void 0 ? void 0 : m.toUpperCase();
|
|
45
|
+
const label = `${method} ${path}`;
|
|
46
|
+
if (!enable) {
|
|
47
|
+
log.warn(`* Tracking changes on ${label} disabled`);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!METHODS.includes(method)) {
|
|
51
|
+
log.error(`* Tracking changes on ${label} available only on methods ${METHODS.join(', ')}`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (path == null || path.length === 0) {
|
|
55
|
+
log.error(`* Tracking changes on ${label} specify a valid path (ex /users)`);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (entity == null || entity.length === 0) {
|
|
59
|
+
log.error(`* Tracking changes on ${label} specify a valid entity (ex User)`);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (primaryKey == null || primaryKey.length === 0) {
|
|
63
|
+
log.error(`* Tracking changes on ${label} specify a valid primaryKey (ex id)`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=tracking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../../lib/loader/tracking.ts"],"names":[],"mappings":";;;AACA,uCAAgD;AAChD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;AAEzC,SAAgB,IAAI;IAClB,MAAM,gBAAgB,GAAqB,EAAE,CAAA;IAE7C,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAA;IAC/G,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,CAAA;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;YACvC,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YACjC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,cAA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AA;KACb;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.track = exports.initialize = void 0;
|
|
16
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
|
+
function initialize(req, reply) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (req.server['dataBaseManager'].isImplemented()) {
|
|
20
|
+
const tc = getTrackingConfigIfEnabled(req);
|
|
21
|
+
const allData = Object.assign(Object.assign({}, req.parameters()), req.data());
|
|
22
|
+
if (tc) {
|
|
23
|
+
try {
|
|
24
|
+
if (allData && tc.entity && tc.primaryKey && tc.primaryKey in allData) {
|
|
25
|
+
const key = allData[tc.primaryKey];
|
|
26
|
+
req.trackingData = yield req.server['dataBaseManager'].retrieveBy(tc.entity, key);
|
|
27
|
+
log.trace(`Tracking changes: found id ${req.trackingData ? req.trackingData[tc.primaryKey] : null}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
log.error(`Tracking changes: error on ${tc.code}`);
|
|
32
|
+
log.error(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.initialize = initialize;
|
|
39
|
+
function track(req, reply, payload) {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (req.server['dataBaseManager'].isImplemented()) {
|
|
43
|
+
const tc = getTrackingConfigIfEnabled(req);
|
|
44
|
+
if (tc) {
|
|
45
|
+
try {
|
|
46
|
+
const contents = [];
|
|
47
|
+
const { entity, changeEntity } = tc;
|
|
48
|
+
const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.getId();
|
|
49
|
+
const oldData = req.trackingData;
|
|
50
|
+
const status = ((_b = req.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'POST' ? 'create' : ((_c = req.method) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === 'DELETE' ? 'delete' : 'update';
|
|
51
|
+
const id = tc.primaryKey && payload && tc.primaryKey in payload
|
|
52
|
+
? payload[tc.primaryKey]
|
|
53
|
+
: tc.primaryKey && oldData && tc.primaryKey in oldData
|
|
54
|
+
? oldData[tc.primaryKey]
|
|
55
|
+
: undefined;
|
|
56
|
+
if (!id) {
|
|
57
|
+
log.error('Tracking changes: id / primary key not found');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let addChange = false;
|
|
61
|
+
if (status === 'delete') {
|
|
62
|
+
addChange = true;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
;
|
|
66
|
+
(((_d = tc.fields) === null || _d === void 0 ? void 0 : _d.includes) || []).forEach((field) => {
|
|
67
|
+
const oldValue = oldData != null && field in oldData ? oldData[field] : undefined;
|
|
68
|
+
const newValue = payload != null && field in payload ? payload[field] : undefined;
|
|
69
|
+
if (isFieldChanged(oldValue, newValue) && newValue !== undefined) {
|
|
70
|
+
contents.push({ key: field, old: oldValue, new: newValue });
|
|
71
|
+
addChange = true;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (addChange) {
|
|
76
|
+
log.trace(`Tracking changes: add ${changeEntity} for ${entity}, ${id}, ${userId}, ${status}`);
|
|
77
|
+
yield req.server['dataBaseManager'].addChange(entity, id, status, userId, contents, changeEntity);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
log.error(`Tracking changes: error on ${tc.code}`);
|
|
82
|
+
log.error(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.track = track;
|
|
89
|
+
function getTrackingConfigIfEnabled(req) {
|
|
90
|
+
var _a, _b, _c, _d;
|
|
91
|
+
try {
|
|
92
|
+
const code = `${(_a = req.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()}::${((_c = (_b = req.routeOptions) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.url) || ((_d = req.routeConfig) === null || _d === void 0 ? void 0 : _d.url) || req.url}`;
|
|
93
|
+
return code in global.tracking && global.tracking[code].enable ? Object.assign({ code }, global.tracking[code]) : null;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
log.error(error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isFieldChanged(oldValue, newValue) {
|
|
100
|
+
if (oldValue instanceof Date || newValue instanceof Date) {
|
|
101
|
+
return !(0, dayjs_1.default)(oldValue).isSame((0, dayjs_1.default)(newValue));
|
|
102
|
+
}
|
|
103
|
+
return oldValue != newValue;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../../lib/util/tracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AAGzB,SAAsB,UAAU,CAAC,G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,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,iBAAG,IAAI,IAAK,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAG,CAAC,CAAC,IAAI,CAAA;KAC3G;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;KACjB;AACH,CAAC;AAED,SAAS,cAAc,CAAC,QAAQ,EAAE,QAAQ;IACxC,IAAI,QAAQ,YAAY,IAAI,IAAI,QAAQ,YAAY,IAAI,EAAE;QACxD,OAAO,CAAC,IAAA,eAAK,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAA,eAAK,EAAC,QAAQ,CAAC,CAAC,CAAA;KAChD;IAED,OAAO,QAAQ,IAAI,QAAQ,CAAA;AAC7B,CAAC"}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcanicminds/backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"codename": "turin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "The volcanic (minds) backend",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@fastify/swagger": "^8.10.1",
|
|
61
61
|
"@fastify/swagger-ui": "^1.9.3",
|
|
62
62
|
"@types/node": "^20.7.0",
|
|
63
|
+
"dayjs": "^1.11.10",
|
|
63
64
|
"dotenv": "^16.3.1",
|
|
64
65
|
"fastify": "^4.23.2",
|
|
65
66
|
"glob": "^8.1.0",
|
package/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import * as loaderRoles from './lib/loader/roles'
|
|
|
12
12
|
import * as loaderRouter from './lib/loader/router'
|
|
13
13
|
import * as loaderHooks from './lib/loader/hooks'
|
|
14
14
|
import * as loaderSchemas from './lib/loader/schemas'
|
|
15
|
+
import * as loaderTracking from './lib/loader/tracking'
|
|
15
16
|
import * as loaderTranslation from './lib/loader/translation'
|
|
16
17
|
|
|
17
18
|
import fastify, { FastifyInstance } from 'fastify'
|
|
@@ -138,10 +139,12 @@ async function addFastifySwagger(server: FastifyInstance) {
|
|
|
138
139
|
const start = async (decorators) => {
|
|
139
140
|
const begin = new Date().getTime()
|
|
140
141
|
mark.print(logger)
|
|
142
|
+
|
|
141
143
|
global.roles = loaderRoles.load()
|
|
142
144
|
global.t = loaderTranslation.load()
|
|
145
|
+
global.tracking = loaderTracking.load()
|
|
143
146
|
|
|
144
|
-
const opts = yn(process.env.LOG_FASTIFY, false) ? { logger: logger } : {}
|
|
147
|
+
const opts = yn(process.env.LOG_FASTIFY, false) ? { logger: { development: logger } } : { logger: true }
|
|
145
148
|
const server: FastifyInstance = fastify()
|
|
146
149
|
|
|
147
150
|
const { HOST: host = '0.0.0.0', PORT: port = '2230', GRAPHQL } = process.env
|
|
@@ -190,61 +193,61 @@ const start = async (decorators) => {
|
|
|
190
193
|
return false
|
|
191
194
|
},
|
|
192
195
|
isValidUser(data: any) {
|
|
193
|
-
throw new Error('Not implemented')
|
|
196
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
194
197
|
},
|
|
195
198
|
createUser(data: any) {
|
|
196
|
-
throw new Error('Not implemented')
|
|
199
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
197
200
|
},
|
|
198
201
|
resetExternalId(data: any) {
|
|
199
|
-
throw new Error('Not implemented')
|
|
202
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
200
203
|
},
|
|
201
204
|
updateUserById(id: string, user: any) {
|
|
202
|
-
throw new Error('Not implemented')
|
|
205
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
203
206
|
},
|
|
204
207
|
retrieveUserById(id: string) {
|
|
205
|
-
throw new Error('Not implemented')
|
|
208
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
206
209
|
},
|
|
207
210
|
retrieveUserByEmail(email: string) {
|
|
208
|
-
throw new Error('Not implemented')
|
|
211
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
209
212
|
},
|
|
210
213
|
retrieveUserByConfirmationToken(code: string) {
|
|
211
|
-
throw new Error('Not implemented')
|
|
214
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
212
215
|
},
|
|
213
216
|
retrieveUserByResetPasswordToken(code: string) {
|
|
214
|
-
throw new Error('Not implemented')
|
|
217
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
215
218
|
},
|
|
216
219
|
retrieveUserByUsername(username: string) {
|
|
217
|
-
throw new Error('Not implemented')
|
|
220
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
218
221
|
},
|
|
219
222
|
retrieveUserByExternalId(externalId: string) {
|
|
220
|
-
throw new Error('Not implemented')
|
|
223
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
221
224
|
},
|
|
222
225
|
retrieveUserByPassword(email: string, password: string) {
|
|
223
|
-
throw new Error('Not implemented')
|
|
226
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
224
227
|
},
|
|
225
228
|
changePassword(email: string, password: string, oldPassword: string) {
|
|
226
|
-
throw new Error('Not implemented')
|
|
229
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
227
230
|
},
|
|
228
231
|
forgotPassword(email: string) {
|
|
229
|
-
throw new Error('Not implemented')
|
|
232
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
230
233
|
},
|
|
231
234
|
userConfirmation(user: any) {
|
|
232
|
-
throw new Error('Not implemented')
|
|
235
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
233
236
|
},
|
|
234
237
|
resetPassword(user: any, password: string) {
|
|
235
|
-
throw new Error('Not implemented')
|
|
238
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
236
239
|
},
|
|
237
240
|
blockUserById(id: string, reason: string) {
|
|
238
|
-
throw new Error('Not implemented')
|
|
241
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
239
242
|
},
|
|
240
243
|
unblockUserById(data: any) {
|
|
241
|
-
throw new Error('Not implemented')
|
|
244
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
242
245
|
},
|
|
243
246
|
countQuery(data: any) {
|
|
244
|
-
throw new Error('Not implemented')
|
|
247
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
245
248
|
},
|
|
246
249
|
findQuery(data: any) {
|
|
247
|
-
throw new Error('Not implemented')
|
|
250
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
248
251
|
}
|
|
249
252
|
} as UserManagement,
|
|
250
253
|
tokenManager: {
|
|
@@ -252,45 +255,51 @@ const start = async (decorators) => {
|
|
|
252
255
|
return false
|
|
253
256
|
},
|
|
254
257
|
isValidToken(data: any) {
|
|
255
|
-
throw new Error('Not implemented')
|
|
258
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
256
259
|
},
|
|
257
260
|
createToken(data: any) {
|
|
258
|
-
throw new Error('Not implemented')
|
|
261
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
259
262
|
},
|
|
260
263
|
resetExternalId(id: string) {
|
|
261
|
-
throw new Error('Not implemented')
|
|
264
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
262
265
|
},
|
|
263
266
|
updateTokenById(id: string, token: any) {
|
|
264
|
-
throw new Error('Not implemented')
|
|
267
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
265
268
|
},
|
|
266
269
|
retrieveTokenById(id: string) {
|
|
267
|
-
throw new Error('Not implemented')
|
|
270
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
268
271
|
},
|
|
269
272
|
retrieveTokenByExternalId(id: string) {
|
|
270
|
-
throw new Error('Not implemented')
|
|
273
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
271
274
|
},
|
|
272
275
|
blockTokenById(id: string, reason: string) {
|
|
273
|
-
throw new Error('Not implemented')
|
|
276
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
274
277
|
},
|
|
275
278
|
unblockTokenById(id: string) {
|
|
276
|
-
throw new Error('Not implemented')
|
|
279
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
277
280
|
},
|
|
278
281
|
countQuery(data: any) {
|
|
279
|
-
throw new Error('Not implemented')
|
|
282
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
280
283
|
},
|
|
281
284
|
findQuery(data: any) {
|
|
282
|
-
throw new Error('Not implemented')
|
|
285
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
283
286
|
},
|
|
284
287
|
removeTokenById(id: string) {
|
|
285
|
-
throw new Error('Not implemented')
|
|
288
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
286
289
|
}
|
|
287
290
|
} as TokenManagement,
|
|
288
291
|
dataBaseManager: {
|
|
289
292
|
isImplemented() {
|
|
290
|
-
return
|
|
293
|
+
return false
|
|
291
294
|
},
|
|
292
295
|
synchronizeSchemas() {
|
|
293
|
-
throw new Error('Not implemented')
|
|
296
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
297
|
+
},
|
|
298
|
+
retrieveBy(entityName, entityId) {
|
|
299
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
300
|
+
},
|
|
301
|
+
addChange(entityName, entityId, status, userId, contents, changeEntity) {
|
|
302
|
+
throw new Error('Not implemented. You need to define the specific decorator (manager).')
|
|
294
303
|
}
|
|
295
304
|
} as DataBaseManagement,
|
|
296
305
|
...decorators
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
config: {
|
|
3
|
+
enableAll: false, // optional, default true
|
|
4
|
+
changeEntity: 'Change', // optional, default 'Change'
|
|
5
|
+
primaryKey: 'id' // optional, default 'id'
|
|
6
|
+
},
|
|
7
|
+
changes: [
|
|
8
|
+
// {
|
|
9
|
+
// enable: true,
|
|
10
|
+
// method: 'POST',
|
|
11
|
+
// path: '/example',
|
|
12
|
+
// fields: { includes: ['fieldToTrack', 'fieldToTrack2'], excludes: [] },
|
|
13
|
+
// entity: 'Example', // valid Entity name
|
|
14
|
+
// changeEntity: 'Change', // optional, default config.changeEntity or 'Change'
|
|
15
|
+
// primaryKey: 'id' //optional, default config.primaryKey or 'id'
|
|
16
|
+
// }
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import sizeof from 'object-sizeof'
|
|
2
|
+
import * as tracking from '../util/tracker'
|
|
2
3
|
|
|
3
4
|
module.exports = async (req, reply, payload) => {
|
|
4
5
|
if (log.t) {
|
|
5
6
|
req.payloadSize = sizeof(req.body) + sizeof(req.params) + sizeof(req.query)
|
|
6
7
|
reply.payloadSize = sizeof(payload)
|
|
7
8
|
}
|
|
9
|
+
|
|
10
|
+
tracking.track(req, reply, payload)
|
|
8
11
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { TrackChanges, TrackChangesList } from '../../types/global'
|
|
2
|
+
import { normalizePatterns } from '../util/path'
|
|
3
|
+
const glob = require('glob')
|
|
4
|
+
|
|
5
|
+
const METHODS = ['POST', 'PUT', 'DELETE']
|
|
6
|
+
|
|
7
|
+
export function load() {
|
|
8
|
+
const trackChangesList: TrackChangesList = {}
|
|
9
|
+
|
|
10
|
+
const patterns = normalizePatterns(['..', 'config', 'tracking.{ts,js}'], ['src', 'config', 'tracking.{ts,js}'])
|
|
11
|
+
patterns.forEach((pattern) => {
|
|
12
|
+
log.t && log.trace('Looking for ' + pattern)
|
|
13
|
+
glob.sync(pattern).forEach((f: string) => {
|
|
14
|
+
const configTracking = require(f)
|
|
15
|
+
const { config, changes } = configTracking || {}
|
|
16
|
+
const { enableAll = true, primaryKey = 'id', changeEntity = 'Change' } = config || {}
|
|
17
|
+
|
|
18
|
+
enableAll &&
|
|
19
|
+
changes.forEach((change) => {
|
|
20
|
+
const tc: TrackChanges = { primaryKey: primaryKey, changeEntity: changeEntity, ...change } as TrackChanges
|
|
21
|
+
const code = getCodeBy(tc.method, tc.path)
|
|
22
|
+
|
|
23
|
+
if (code in trackChangesList) {
|
|
24
|
+
log.warn(`* Tracking changes on ${tc.method?.toUpperCase()} ${tc.path} already loaded (override)`)
|
|
25
|
+
trackChangesList[code] = { ...trackChangesList[code], ...tc }
|
|
26
|
+
} else if (isValid(tc)) {
|
|
27
|
+
trackChangesList[code] = tc
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const keys = Object.keys(trackChangesList) || []
|
|
34
|
+
log.d && log.debug(`Tracking changes loaded: ${keys?.length || 0}`)
|
|
35
|
+
return trackChangesList
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getCodeBy(method, path) {
|
|
39
|
+
if (method == null || path == null) {
|
|
40
|
+
throw new Error('Tracking changes: impossible retrieve code by method and path')
|
|
41
|
+
}
|
|
42
|
+
return `${method.toUpperCase()}::${path}` // ex POST::/users
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isValid(tc) {
|
|
46
|
+
const { method: m, path, enable = true, primaryKey, entity } = tc
|
|
47
|
+
const method = m?.toUpperCase()
|
|
48
|
+
const label = `${method} ${path}`
|
|
49
|
+
|
|
50
|
+
if (!enable) {
|
|
51
|
+
log.warn(`* Tracking changes on ${label} disabled`)
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!METHODS.includes(method)) {
|
|
56
|
+
log.error(`* Tracking changes on ${label} available only on methods ${METHODS.join(', ')}`)
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (path == null || path.length === 0) {
|
|
61
|
+
log.error(`* Tracking changes on ${label} specify a valid path (ex /users)`)
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (entity == null || entity.length === 0) {
|
|
66
|
+
log.error(`* Tracking changes on ${label} specify a valid entity (ex User)`)
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (primaryKey == null || primaryKey.length === 0) {
|
|
71
|
+
log.error(`* Tracking changes on ${label} specify a valid primaryKey (ex id)`)
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return true
|
|
76
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import dayjs from 'dayjs'
|
|
2
|
+
import { FastifyRequest, FastifyReply } from '../../types/global'
|
|
3
|
+
|
|
4
|
+
export async function initialize(req: FastifyRequest, reply: FastifyReply) {
|
|
5
|
+
if (req.server['dataBaseManager'].isImplemented()) {
|
|
6
|
+
const tc = getTrackingConfigIfEnabled(req)
|
|
7
|
+
const allData = { ...req.parameters(), ...req.data() }
|
|
8
|
+
|
|
9
|
+
if (tc) {
|
|
10
|
+
try {
|
|
11
|
+
if (allData && tc.entity && tc.primaryKey && tc.primaryKey in allData) {
|
|
12
|
+
const key = allData[tc.primaryKey]
|
|
13
|
+
req.trackingData = await req.server['dataBaseManager'].retrieveBy(tc.entity, key)
|
|
14
|
+
log.trace(`Tracking changes: found id ${req.trackingData ? req.trackingData[tc.primaryKey] : null}`)
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {
|
|
17
|
+
log.error(`Tracking changes: error on ${tc.code}`)
|
|
18
|
+
log.error(error)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function track(req: FastifyRequest, reply: FastifyReply, payload: any) {
|
|
25
|
+
if (req.server['dataBaseManager'].isImplemented()) {
|
|
26
|
+
const tc = getTrackingConfigIfEnabled(req)
|
|
27
|
+
if (tc) {
|
|
28
|
+
try {
|
|
29
|
+
const contents: any[] = []
|
|
30
|
+
const { entity, changeEntity } = tc
|
|
31
|
+
const userId = req.user?.getId()
|
|
32
|
+
const oldData = req.trackingData
|
|
33
|
+
|
|
34
|
+
const status =
|
|
35
|
+
req.method?.toUpperCase() === 'POST' ? 'create' : req.method?.toUpperCase() === 'DELETE' ? 'delete' : 'update'
|
|
36
|
+
|
|
37
|
+
const id =
|
|
38
|
+
tc.primaryKey && payload && tc.primaryKey in payload
|
|
39
|
+
? payload[tc.primaryKey]
|
|
40
|
+
: tc.primaryKey && oldData && tc.primaryKey in oldData
|
|
41
|
+
? oldData[tc.primaryKey]
|
|
42
|
+
: undefined
|
|
43
|
+
|
|
44
|
+
if (!id) {
|
|
45
|
+
log.error('Tracking changes: id / primary key not found')
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let addChange = false
|
|
50
|
+
if (status === 'delete') {
|
|
51
|
+
addChange = true
|
|
52
|
+
} else {
|
|
53
|
+
;(tc.fields?.includes || []).forEach((field) => {
|
|
54
|
+
const oldValue = oldData != null && field in oldData ? oldData[field] : undefined
|
|
55
|
+
const newValue = payload != null && field in payload ? payload[field] : undefined
|
|
56
|
+
if (isFieldChanged(oldValue, newValue) && newValue !== undefined) {
|
|
57
|
+
contents.push({ key: field, old: oldValue, new: newValue })
|
|
58
|
+
addChange = true
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (addChange) {
|
|
64
|
+
log.trace(`Tracking changes: add ${changeEntity} for ${entity}, ${id}, ${userId}, ${status}`)
|
|
65
|
+
await req.server['dataBaseManager'].addChange(entity, id, status, userId, contents, changeEntity)
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
log.error(`Tracking changes: error on ${tc.code}`)
|
|
69
|
+
log.error(error)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getTrackingConfigIfEnabled(req) {
|
|
76
|
+
try {
|
|
77
|
+
const code = `${req.method?.toUpperCase()}::${req.routeOptions?.config?.url || req.routeConfig?.url || req.url}`
|
|
78
|
+
return code in global.tracking && global.tracking[code].enable ? { code, ...global.tracking[code] } : null
|
|
79
|
+
} catch (error) {
|
|
80
|
+
log.error(error)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isFieldChanged(oldValue, newValue) {
|
|
85
|
+
if (oldValue instanceof Date || newValue instanceof Date) {
|
|
86
|
+
return !dayjs(oldValue).isSame(dayjs(newValue))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return oldValue != newValue
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcanicminds/backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"codename": "turin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "The volcanic (minds) backend",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@fastify/swagger": "^8.10.1",
|
|
61
61
|
"@fastify/swagger-ui": "^1.9.3",
|
|
62
62
|
"@types/node": "^20.7.0",
|
|
63
|
+
"dayjs": "^1.11.10",
|
|
63
64
|
"dotenv": "^16.3.1",
|
|
64
65
|
"fastify": "^4.23.2",
|
|
65
66
|
"glob": "^8.1.0",
|
package/types/global.d.ts
CHANGED
|
@@ -74,6 +74,20 @@ export interface ConfiguredRoute {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export interface TrackChanges {
|
|
78
|
+
enable: boolean
|
|
79
|
+
method: string
|
|
80
|
+
path: string
|
|
81
|
+
entity: string
|
|
82
|
+
changeEntity: string
|
|
83
|
+
fields?: { includes: string[] } | null
|
|
84
|
+
primaryKey?: string | null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface TrackChangesList {
|
|
88
|
+
[option: string]: TrackChanges
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
export interface UserManagement {
|
|
78
92
|
isImplemented(): boolean
|
|
79
93
|
isValidUser(data: any): boolean
|
|
@@ -115,6 +129,8 @@ export interface TokenManagement {
|
|
|
115
129
|
export interface DataBaseManagement {
|
|
116
130
|
isImplemented(): boolean
|
|
117
131
|
synchronizeSchemas(): any | null
|
|
132
|
+
retrieveBy(entityName, entityId): any | null
|
|
133
|
+
addChange(entityName, entityId, status, userId, contents, changeEntity): any | null
|
|
118
134
|
}
|
|
119
135
|
|
|
120
136
|
declare module 'fastify' {
|
|
@@ -127,6 +143,7 @@ declare module 'fastify' {
|
|
|
127
143
|
roles(): string[]
|
|
128
144
|
hasRole(role: Role): boolean
|
|
129
145
|
payloadSize?: number
|
|
146
|
+
trackingData?: any
|
|
130
147
|
}
|
|
131
148
|
export interface FastifyReply {
|
|
132
149
|
payloadSize?: number
|
|
@@ -142,6 +159,7 @@ export interface FastifyRequest extends FastifyRequest {
|
|
|
142
159
|
roles(): string[]
|
|
143
160
|
hasRole(role: Role): boolean
|
|
144
161
|
payloadSize?: number
|
|
162
|
+
trackingData?: any
|
|
145
163
|
}
|
|
146
164
|
|
|
147
165
|
export interface FastifyReply extends FastifyReply {
|
|
@@ -154,6 +172,7 @@ declare global {
|
|
|
154
172
|
var log: any
|
|
155
173
|
var server: any
|
|
156
174
|
var roles: Roles
|
|
175
|
+
var tracking: TrackChangesList
|
|
157
176
|
var connection: any
|
|
158
177
|
var entity: any
|
|
159
178
|
var repository: any
|