@volcanicminds/backend 0.5.3 → 0.6.1

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 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,10 @@ 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
- const opts = (0, yn_1.default)(process.env.LOG_FASTIFY, false) ? { logger: logger_1.default } : {};
163
+ const { tracking, trackingConfig } = loaderTracking.load();
164
+ global.tracking = tracking;
165
+ global.trackingConfig = trackingConfig;
166
+ const opts = (0, yn_1.default)(process.env.LOG_FASTIFY, false) ? { logger: { development: logger_1.default } } : { logger: true };
163
167
  const server = (0, fastify_1.default)();
164
168
  const { HOST: host = '0.0.0.0', PORT: port = '2230', GRAPHQL } = process.env;
165
169
  const { JWT_SECRET = '', JWT_EXPIRES_IN = '15d', JWT_REFRESH = 'true', JWT_REFRESH_SECRET = '', JWT_REFRESH_EXPIRES_IN = '180d' } = process.env;
@@ -191,105 +195,111 @@ const start = (decorators) => __awaiter(void 0, void 0, void 0, function* () {
191
195
  return false;
192
196
  },
193
197
  isValidUser(data) {
194
- throw new Error('Not implemented');
198
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
195
199
  },
196
200
  createUser(data) {
197
- throw new Error('Not implemented');
201
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
198
202
  },
199
203
  resetExternalId(data) {
200
- throw new Error('Not implemented');
204
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
201
205
  },
202
206
  updateUserById(id, user) {
203
- throw new Error('Not implemented');
207
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
204
208
  },
205
209
  retrieveUserById(id) {
206
- throw new Error('Not implemented');
210
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
207
211
  },
208
212
  retrieveUserByEmail(email) {
209
- throw new Error('Not implemented');
213
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
210
214
  },
211
215
  retrieveUserByConfirmationToken(code) {
212
- throw new Error('Not implemented');
216
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
213
217
  },
214
218
  retrieveUserByResetPasswordToken(code) {
215
- throw new Error('Not implemented');
219
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
216
220
  },
217
221
  retrieveUserByUsername(username) {
218
- throw new Error('Not implemented');
222
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
219
223
  },
220
224
  retrieveUserByExternalId(externalId) {
221
- throw new Error('Not implemented');
225
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
222
226
  },
223
227
  retrieveUserByPassword(email, password) {
224
- throw new Error('Not implemented');
228
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
225
229
  },
226
230
  changePassword(email, password, oldPassword) {
227
- throw new Error('Not implemented');
231
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
228
232
  },
229
233
  forgotPassword(email) {
230
- throw new Error('Not implemented');
234
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
231
235
  },
232
236
  userConfirmation(user) {
233
- throw new Error('Not implemented');
237
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
234
238
  },
235
239
  resetPassword(user, password) {
236
- throw new Error('Not implemented');
240
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
237
241
  },
238
242
  blockUserById(id, reason) {
239
- throw new Error('Not implemented');
243
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
240
244
  },
241
245
  unblockUserById(data) {
242
- throw new Error('Not implemented');
246
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
243
247
  },
244
248
  countQuery(data) {
245
- throw new Error('Not implemented');
249
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
246
250
  },
247
251
  findQuery(data) {
248
- throw new Error('Not implemented');
252
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
249
253
  }
250
254
  }, tokenManager: {
251
255
  isImplemented() {
252
256
  return false;
253
257
  },
254
258
  isValidToken(data) {
255
- throw new Error('Not implemented');
259
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
256
260
  },
257
261
  createToken(data) {
258
- throw new Error('Not implemented');
262
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
259
263
  },
260
264
  resetExternalId(id) {
261
- throw new Error('Not implemented');
265
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
262
266
  },
263
267
  updateTokenById(id, token) {
264
- throw new Error('Not implemented');
268
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
265
269
  },
266
270
  retrieveTokenById(id) {
267
- throw new Error('Not implemented');
271
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
268
272
  },
269
273
  retrieveTokenByExternalId(id) {
270
- throw new Error('Not implemented');
274
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
271
275
  },
272
276
  blockTokenById(id, reason) {
273
- throw new Error('Not implemented');
277
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
274
278
  },
275
279
  unblockTokenById(id) {
276
- throw new Error('Not implemented');
280
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
277
281
  },
278
282
  countQuery(data) {
279
- throw new Error('Not implemented');
283
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
280
284
  },
281
285
  findQuery(data) {
282
- throw new Error('Not implemented');
286
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
283
287
  },
284
288
  removeTokenById(id) {
285
- throw new Error('Not implemented');
289
+ throw new Error('Not implemented. You need to define the specific decorator (manager).');
286
290
  }
287
291
  }, dataBaseManager: {
288
292
  isImplemented() {
289
- return true;
293
+ return false;
290
294
  },
291
295
  synchronizeSchemas() {
292
- 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).');
293
303
  }
294
304
  } }, decorators);
295
305
  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;AAwVrB,aAxVF,YAAE,CAwVE;AAvVX,+DAAsC;AACtC,sDAAuC;AACvC,8CAAmD;AAqV/B,gGArVX,wBAAe,OAqVW;AApVnC,oEAAqD;AACrD,gEAAiD;AACjD,kEAAmD;AACnD,gEAAiD;AACjD,oEAAqD;AACrD,4EAA6D;AAE7D,sDAAkD;AAClD,uDAAuC;AACvC,+DAAsC;AACtC,qEAA2C;AAE3C,yDAAgC;AAChC,6DAAoC;AACpC,iEAAwC;AACxC,qEAA2C;AAE3C,2CAA6C;AAC7C,oEAAkF;AAClF,kDAAmE;AACnE,uEAA8C;AAC9C,uEAA6C;AAG7C,MAAM,CAAC,GAAG,GAAG,gBAAM,CAAA;AAEnB,SAAe,YAAY,CAAC,MAAuB;;QACjD,GAAG,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;QAC1C,MAAM,MAAM,GAAG,IAAI,qBAAY,CAAY;YACzC,QAAQ,EAAR,mBAAQ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AAE,IAAI;KACX,CAAC;SACD,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAChB,MAAM,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAA;QACpD,GAAG,CAAC,IAAI,CAAC,uBAAuB,OAAO,MAAM,CAAC,CAAA;QAC9C,GAAG,CAAC,IAAI,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAA;QAEzC,MAAM,WAAW,GAAG,IAAA,YAAE,EAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAClD,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC,sBAAsB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,gBAAgB,EAAE,CAAC,CAAA;IAC/G,CAAC,CAAC,CAAA;IAEJ,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AA6BY,sBAAK;AAClB,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,EAAF,YAAE,EAAE,KAAK,EAAE,eAAe,EAAf,wBAAe,EAAE,CAAA;AAC/C,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,EAAE,EAAF,YAAE,EAAE,KAAK,EAAE,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,10 @@
1
+ "use strict";
2
+ module.exports = {
3
+ config: {
4
+ enableAll: false,
5
+ changeEntity: 'Change',
6
+ primaryKey: 'id'
7
+ },
8
+ changes: []
9
+ };
10
+ //# sourceMappingURL=tracking.js.map
@@ -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":";;;;;;;;;;;;;;AAAA,kEAAkC;AAElC,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;AACH,CAAC,CAAA,CAAA"}
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,70 @@
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
+ let trackConfig = {};
10
+ const patterns = (0, path_1.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) => {
14
+ const configTracking = require(f);
15
+ const { config, changes } = configTracking || {};
16
+ const { enableAll = true, primaryKey = 'id', changeEntity = 'Change' } = config || {};
17
+ trackConfig = Object.assign(Object.assign({}, trackConfig), config);
18
+ enableAll &&
19
+ changes.forEach((change) => {
20
+ var _a;
21
+ const tc = Object.assign({ primaryKey: primaryKey, changeEntity: changeEntity }, change);
22
+ const code = getCodeBy(tc.method, tc.path);
23
+ if (code in trackChangesList) {
24
+ log.warn(`* Tracking changes on ${(_a = tc.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${tc.path} already loaded (override)`);
25
+ trackChangesList[code] = Object.assign(Object.assign({}, trackChangesList[code]), tc);
26
+ }
27
+ else if (isValid(tc)) {
28
+ trackChangesList[code] = tc;
29
+ }
30
+ });
31
+ });
32
+ });
33
+ const keys = Object.keys(trackChangesList) || [];
34
+ log.d && log.debug(`Tracking changes loaded: ${(keys === null || keys === void 0 ? void 0 : keys.length) || 0}`);
35
+ return { tracking: trackChangesList, trackingConfig: trackConfig };
36
+ }
37
+ exports.load = load;
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}`;
43
+ }
44
+ function isValid(tc) {
45
+ const { method: m, path, enable = true, primaryKey, entity } = tc;
46
+ const method = m === null || m === void 0 ? void 0 : m.toUpperCase();
47
+ const label = `${method} ${path}`;
48
+ if (!enable) {
49
+ log.warn(`* Tracking changes on ${label} disabled`);
50
+ return false;
51
+ }
52
+ if (!METHODS.includes(method)) {
53
+ log.error(`* Tracking changes on ${label} available only on methods ${METHODS.join(', ')}`);
54
+ return false;
55
+ }
56
+ if (path == null || path.length === 0) {
57
+ log.error(`* Tracking changes on ${label} specify a valid path (ex /users)`);
58
+ return false;
59
+ }
60
+ if (entity == null || entity.length === 0) {
61
+ log.error(`* Tracking changes on ${label} specify a valid entity (ex User)`);
62
+ return false;
63
+ }
64
+ if (primaryKey == null || primaryKey.length === 0) {
65
+ log.error(`* Tracking changes on ${label} specify a valid primaryKey (ex id)`);
66
+ return false;
67
+ }
68
+ return true;
69
+ }
70
+ //# 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;IAC7C,IAAI,WAAW,GAAS,EAAE,CAAA;IAE1B,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,kBAAkB,CAAC,E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A;KACb;IAED,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,GAAG,CAAC,KAAK,CAAC,yBAAyB,KAAK,mCAAmC,CAAC,CAAA;QAC5E,OAAO,KAAK,CAAA;KACb;IAED,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACzC,GAAG,CAAC,KAAK,CAAC,yBAAyB,KAAK,mCAAmC,CAAC,CAAA;QAC5E,OAAO,KAAK,CAAA;KACb;IAED,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,GAAG,CAAC,KAAK,CAAC,yBAAyB,KAAK,qCAAqC,CAAC,CAAA;QAC9E,OAAO,KAAK,CAAA;KACb;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,123 @@
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, _e;
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
+ const fields = ((_d = tc.fields) === null || _d === void 0 ? void 0 : _d.includes) || Object.keys(payload) || [];
66
+ const excludes = ((_e = tc.fields) === null || _e === void 0 ? void 0 : _e.excludes) || [];
67
+ fields.forEach((field) => {
68
+ if (!excludes.includes(field)) {
69
+ const oldValue = oldData != null && field in oldData ? oldData[field] : undefined;
70
+ const newValue = payload != null && field in payload ? payload[field] : undefined;
71
+ if (newValue !== undefined && isFieldChanged(oldValue, newValue)) {
72
+ contents.push({ key: field, old: oldValue, new: newValue });
73
+ addChange = true;
74
+ }
75
+ }
76
+ });
77
+ }
78
+ if (addChange) {
79
+ log.trace(`Tracking changes: add ${changeEntity} for ${entity}, ${id}, ${userId}, ${status}`);
80
+ yield req.server['dataBaseManager'].addChange(entity, id, status, userId, contents, changeEntity);
81
+ }
82
+ }
83
+ catch (error) {
84
+ log.error(`Tracking changes: error on ${tc.code}`);
85
+ log.error(error);
86
+ }
87
+ }
88
+ }
89
+ });
90
+ }
91
+ exports.track = track;
92
+ function getTrackingConfigIfEnabled(req) {
93
+ var _a, _b, _c, _d;
94
+ try {
95
+ 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}`;
96
+ return code in global.tracking && global.tracking[code].enable ? Object.assign({ code }, global.tracking[code]) : null;
97
+ }
98
+ catch (error) {
99
+ log.error(error);
100
+ }
101
+ }
102
+ function isFieldChanged(oldValue, newValue) {
103
+ var _a;
104
+ if ((oldValue instanceof Date || newValue instanceof Date) && oldValue != null && newValue != undefined) {
105
+ return !(0, dayjs_1.default)(oldValue).isSame((0, dayjs_1.default)(newValue));
106
+ }
107
+ if ((oldValue instanceof Object || newValue instanceof Object) && oldValue != null && newValue != undefined) {
108
+ const primaryKey = (_a = global.trackingConfig) === null || _a === void 0 ? void 0 : _a.primaryKey;
109
+ const oldId = oldValue != null && primaryKey in oldValue
110
+ ? oldValue[primaryKey]
111
+ : typeof oldValue === 'string'
112
+ ? oldValue
113
+ : undefined;
114
+ const newId = newValue != null && primaryKey in newValue
115
+ ? newValue[primaryKey]
116
+ : typeof newValue === 'string'
117
+ ? newValue
118
+ : undefined;
119
+ return oldId !== undefined && newId !== undefined ? oldId != newId : false;
120
+ }
121
+ return oldValue != newValue;
122
+ }
123
+ //# 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,GAAmB,EAAE,KAAmB;;QACvE,IAAI,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,aAAa,EAAE,EAAE;YACjD,MAAM,EAAE,GAAG,0BAA0B,CAAC,GAAG,CAAC,CAAA;YAC1C,MAAM,OAAO,mCAAQ,GAAG,CAAC,UAAU,EAAE,GAAK,GAAG,CAAC,IAAI,EAAE,CAAE,CAAA;YAEtD,IAAI,EAAE,EAAE;gBACN,IAAI;oBACF,IAAI,OAAO,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC,UAAU,IAAI,OAAO,EAAE;wBACrE,MAAM,GAAG,GAAG,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,CAAA;wBAClC,GAAG,CAAC,YAAY,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;wBACjF,GAAG,CAAC,KAAK,CAAC,8BAA8B,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;qBACrG;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACd,GAAG,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;oBAClD,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;iBACjB;aACF;SACF;IACH,CAAC;CAAA;AAlBD,gCAkBC;AAED,SAAsB,KAAK,CAAC,GAAmB,EAAE,KA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AAQ;YACxC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtB,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ;gBAC9B,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,SAAS,CAAA;QACf,MAAM,KAAK,GACT,QAAQ,IAAI,IAAI,IAAI,UAAU,IAAI,QAAQ;YACxC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtB,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ;gBAC9B,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,SAAS,CAAA;QACf,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;KAC3E;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.5.3",
3
+ "version": "0.6.1",
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,15 @@ 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()
143
145
 
144
- const opts = yn(process.env.LOG_FASTIFY, false) ? { logger: logger } : {}
146
+ const { tracking, trackingConfig } = loaderTracking.load()
147
+ global.tracking = tracking
148
+ global.trackingConfig = trackingConfig
149
+
150
+ const opts = yn(process.env.LOG_FASTIFY, false) ? { logger: { development: logger } } : { logger: true }
145
151
  const server: FastifyInstance = fastify()
146
152
 
147
153
  const { HOST: host = '0.0.0.0', PORT: port = '2230', GRAPHQL } = process.env
@@ -190,61 +196,61 @@ const start = async (decorators) => {
190
196
  return false
191
197
  },
192
198
  isValidUser(data: any) {
193
- throw new Error('Not implemented')
199
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
194
200
  },
195
201
  createUser(data: any) {
196
- throw new Error('Not implemented')
202
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
197
203
  },
198
204
  resetExternalId(data: any) {
199
- throw new Error('Not implemented')
205
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
200
206
  },
201
207
  updateUserById(id: string, user: any) {
202
- throw new Error('Not implemented')
208
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
203
209
  },
204
210
  retrieveUserById(id: string) {
205
- throw new Error('Not implemented')
211
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
206
212
  },
207
213
  retrieveUserByEmail(email: string) {
208
- throw new Error('Not implemented')
214
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
209
215
  },
210
216
  retrieveUserByConfirmationToken(code: string) {
211
- throw new Error('Not implemented')
217
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
212
218
  },
213
219
  retrieveUserByResetPasswordToken(code: string) {
214
- throw new Error('Not implemented')
220
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
215
221
  },
216
222
  retrieveUserByUsername(username: string) {
217
- throw new Error('Not implemented')
223
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
218
224
  },
219
225
  retrieveUserByExternalId(externalId: string) {
220
- throw new Error('Not implemented')
226
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
221
227
  },
222
228
  retrieveUserByPassword(email: string, password: string) {
223
- throw new Error('Not implemented')
229
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
224
230
  },
225
231
  changePassword(email: string, password: string, oldPassword: string) {
226
- throw new Error('Not implemented')
232
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
227
233
  },
228
234
  forgotPassword(email: string) {
229
- throw new Error('Not implemented')
235
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
230
236
  },
231
237
  userConfirmation(user: any) {
232
- throw new Error('Not implemented')
238
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
233
239
  },
234
240
  resetPassword(user: any, password: string) {
235
- throw new Error('Not implemented')
241
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
236
242
  },
237
243
  blockUserById(id: string, reason: string) {
238
- throw new Error('Not implemented')
244
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
239
245
  },
240
246
  unblockUserById(data: any) {
241
- throw new Error('Not implemented')
247
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
242
248
  },
243
249
  countQuery(data: any) {
244
- throw new Error('Not implemented')
250
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
245
251
  },
246
252
  findQuery(data: any) {
247
- throw new Error('Not implemented')
253
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
248
254
  }
249
255
  } as UserManagement,
250
256
  tokenManager: {
@@ -252,45 +258,51 @@ const start = async (decorators) => {
252
258
  return false
253
259
  },
254
260
  isValidToken(data: any) {
255
- throw new Error('Not implemented')
261
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
256
262
  },
257
263
  createToken(data: any) {
258
- throw new Error('Not implemented')
264
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
259
265
  },
260
266
  resetExternalId(id: string) {
261
- throw new Error('Not implemented')
267
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
262
268
  },
263
269
  updateTokenById(id: string, token: any) {
264
- throw new Error('Not implemented')
270
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
265
271
  },
266
272
  retrieveTokenById(id: string) {
267
- throw new Error('Not implemented')
273
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
268
274
  },
269
275
  retrieveTokenByExternalId(id: string) {
270
- throw new Error('Not implemented')
276
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
271
277
  },
272
278
  blockTokenById(id: string, reason: string) {
273
- throw new Error('Not implemented')
279
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
274
280
  },
275
281
  unblockTokenById(id: string) {
276
- throw new Error('Not implemented')
282
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
277
283
  },
278
284
  countQuery(data: any) {
279
- throw new Error('Not implemented')
285
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
280
286
  },
281
287
  findQuery(data: any) {
282
- throw new Error('Not implemented')
288
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
283
289
  },
284
290
  removeTokenById(id: string) {
285
- throw new Error('Not implemented')
291
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
286
292
  }
287
293
  } as TokenManagement,
288
294
  dataBaseManager: {
289
295
  isImplemented() {
290
- return true
296
+ return false
291
297
  },
292
298
  synchronizeSchemas() {
293
- throw new Error('Not implemented')
299
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
300
+ },
301
+ retrieveBy(entityName, entityId) {
302
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
303
+ },
304
+ addChange(entityName, entityId, status, userId, contents, changeEntity) {
305
+ throw new Error('Not implemented. You need to define the specific decorator (manager).')
294
306
  }
295
307
  } as DataBaseManagement,
296
308
  ...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
+ }
@@ -0,0 +1,5 @@
1
+ import * as tracking from '../util/tracker'
2
+
3
+ module.exports = async (req, reply) => {
4
+ tracking.initialize(req, reply)
5
+ }
@@ -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,79 @@
1
+ import { TrackChanges, TrackChangesList, Data } 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
+ let trackConfig: Data = {}
10
+
11
+ const patterns = normalizePatterns(['..', 'config', 'tracking.{ts,js}'], ['src', 'config', 'tracking.{ts,js}'])
12
+ patterns.forEach((pattern) => {
13
+ log.t && log.trace('Looking for ' + pattern)
14
+ glob.sync(pattern).forEach((f: string) => {
15
+ const configTracking = require(f)
16
+ const { config, changes } = configTracking || {}
17
+ const { enableAll = true, primaryKey = 'id', changeEntity = 'Change' } = config || {}
18
+
19
+ trackConfig = { ...trackConfig, ...config }
20
+
21
+ enableAll &&
22
+ changes.forEach((change) => {
23
+ const tc: TrackChanges = { primaryKey: primaryKey, changeEntity: changeEntity, ...change } as TrackChanges
24
+ const code = getCodeBy(tc.method, tc.path)
25
+
26
+ if (code in trackChangesList) {
27
+ log.warn(`* Tracking changes on ${tc.method?.toUpperCase()} ${tc.path} already loaded (override)`)
28
+ trackChangesList[code] = { ...trackChangesList[code], ...tc }
29
+ } else if (isValid(tc)) {
30
+ trackChangesList[code] = tc
31
+ }
32
+ })
33
+ })
34
+ })
35
+
36
+ const keys = Object.keys(trackChangesList) || []
37
+ log.d && log.debug(`Tracking changes loaded: ${keys?.length || 0}`)
38
+ return { tracking: trackChangesList, trackingConfig: trackConfig }
39
+ }
40
+
41
+ function getCodeBy(method, path) {
42
+ if (method == null || path == null) {
43
+ throw new Error('Tracking changes: impossible retrieve code by method and path')
44
+ }
45
+ return `${method.toUpperCase()}::${path}` // ex POST::/users
46
+ }
47
+
48
+ function isValid(tc) {
49
+ const { method: m, path, enable = true, primaryKey, entity } = tc
50
+ const method = m?.toUpperCase()
51
+ const label = `${method} ${path}`
52
+
53
+ if (!enable) {
54
+ log.warn(`* Tracking changes on ${label} disabled`)
55
+ return false
56
+ }
57
+
58
+ if (!METHODS.includes(method)) {
59
+ log.error(`* Tracking changes on ${label} available only on methods ${METHODS.join(', ')}`)
60
+ return false
61
+ }
62
+
63
+ if (path == null || path.length === 0) {
64
+ log.error(`* Tracking changes on ${label} specify a valid path (ex /users)`)
65
+ return false
66
+ }
67
+
68
+ if (entity == null || entity.length === 0) {
69
+ log.error(`* Tracking changes on ${label} specify a valid entity (ex User)`)
70
+ return false
71
+ }
72
+
73
+ if (primaryKey == null || primaryKey.length === 0) {
74
+ log.error(`* Tracking changes on ${label} specify a valid primaryKey (ex id)`)
75
+ return false
76
+ }
77
+
78
+ return true
79
+ }
@@ -0,0 +1,112 @@
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
+ const fields = tc.fields?.includes || Object.keys(payload) || []
54
+ const excludes: string[] = tc.fields?.excludes || []
55
+
56
+ fields.forEach((field) => {
57
+ if (!excludes.includes(field)) {
58
+ const oldValue = oldData != null && field in oldData ? oldData[field] : undefined
59
+ const newValue = payload != null && field in payload ? payload[field] : undefined
60
+ if (newValue !== undefined && isFieldChanged(oldValue, newValue)) {
61
+ contents.push({ key: field, old: oldValue, new: newValue })
62
+ addChange = true
63
+ }
64
+ }
65
+ })
66
+ }
67
+
68
+ if (addChange) {
69
+ log.trace(`Tracking changes: add ${changeEntity} for ${entity}, ${id}, ${userId}, ${status}`)
70
+ await req.server['dataBaseManager'].addChange(entity, id, status, userId, contents, changeEntity)
71
+ }
72
+ } catch (error) {
73
+ log.error(`Tracking changes: error on ${tc.code}`)
74
+ log.error(error)
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ function getTrackingConfigIfEnabled(req) {
81
+ try {
82
+ const code = `${req.method?.toUpperCase()}::${req.routeOptions?.config?.url || req.routeConfig?.url || req.url}`
83
+ return code in global.tracking && global.tracking[code].enable ? { code, ...global.tracking[code] } : null
84
+ } catch (error) {
85
+ log.error(error)
86
+ }
87
+ }
88
+
89
+ function isFieldChanged(oldValue, newValue) {
90
+ if ((oldValue instanceof Date || newValue instanceof Date) && oldValue != null && newValue != undefined) {
91
+ return !dayjs(oldValue).isSame(dayjs(newValue))
92
+ }
93
+
94
+ if ((oldValue instanceof Object || newValue instanceof Object) && oldValue != null && newValue != undefined) {
95
+ const primaryKey = global.trackingConfig?.primaryKey
96
+ const oldId =
97
+ oldValue != null && primaryKey in oldValue
98
+ ? oldValue[primaryKey]
99
+ : typeof oldValue === 'string'
100
+ ? oldValue
101
+ : undefined
102
+ const newId =
103
+ newValue != null && primaryKey in newValue
104
+ ? newValue[primaryKey]
105
+ : typeof newValue === 'string'
106
+ ? newValue
107
+ : undefined
108
+ return oldId !== undefined && newId !== undefined ? oldId != newId : false
109
+ }
110
+
111
+ return oldValue != newValue
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volcanicminds/backend",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
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,23 @@ 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?: {
84
+ includes?: string[] | null
85
+ excludes?: string[] | null
86
+ } | null
87
+ primaryKey?: string | null
88
+ }
89
+
90
+ export interface TrackChangesList {
91
+ [option: string]: TrackChanges
92
+ }
93
+
77
94
  export interface UserManagement {
78
95
  isImplemented(): boolean
79
96
  isValidUser(data: any): boolean
@@ -115,6 +132,8 @@ export interface TokenManagement {
115
132
  export interface DataBaseManagement {
116
133
  isImplemented(): boolean
117
134
  synchronizeSchemas(): any | null
135
+ retrieveBy(entityName, entityId): any | null
136
+ addChange(entityName, entityId, status, userId, contents, changeEntity): any | null
118
137
  }
119
138
 
120
139
  declare module 'fastify' {
@@ -127,6 +146,7 @@ declare module 'fastify' {
127
146
  roles(): string[]
128
147
  hasRole(role: Role): boolean
129
148
  payloadSize?: number
149
+ trackingData?: any
130
150
  }
131
151
  export interface FastifyReply {
132
152
  payloadSize?: number
@@ -142,6 +162,7 @@ export interface FastifyRequest extends FastifyRequest {
142
162
  roles(): string[]
143
163
  hasRole(role: Role): boolean
144
164
  payloadSize?: number
165
+ trackingData?: any
145
166
  }
146
167
 
147
168
  export interface FastifyReply extends FastifyReply {
@@ -154,6 +175,8 @@ declare global {
154
175
  var log: any
155
176
  var server: any
156
177
  var roles: Roles
178
+ var tracking: TrackChangesList
179
+ var trackingConfig: Data
157
180
  var connection: any
158
181
  var entity: any
159
182
  var repository: any