test-entity-library-asm 3.9.7 → 3.9.9

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.
@@ -1,4 +1,4 @@
1
- import { MasterNotification, PartnerNotification, VerifyLocal } from "..";
1
+ import { MasterNotification, MasterSession, PartnerNotification, VerifyLocal } from "..";
2
2
  import { City } from "./City";
3
3
  import { DiscountCodeCompany } from "./DiscountCodeCompany";
4
4
  import { MasterRole } from "./MasterRole";
@@ -9,10 +9,11 @@ export declare class Master {
9
9
  name: string;
10
10
  surname: string;
11
11
  email: string;
12
- phone: string;
12
+ phone: string | null;
13
13
  city: City;
14
14
  address: string;
15
- password: string;
15
+ password: string | null;
16
+ google_id: string | null;
16
17
  profile: any | null;
17
18
  created: Date;
18
19
  updated: Date;
@@ -24,4 +25,5 @@ export declare class Master {
24
25
  master_notifications: MasterNotification[];
25
26
  masters_to_notification: MasterNotification[];
26
27
  masters_notification: PartnerNotification[];
28
+ masters_session: MasterSession[];
27
29
  }
@@ -69,9 +69,11 @@ __decorate([
69
69
  type: "varchar",
70
70
  length: 12,
71
71
  unique: true,
72
+ nullable: true,
73
+ default: null,
72
74
  comment: "Número de celular del master.",
73
75
  }),
74
- __metadata("design:type", String)
76
+ __metadata("design:type", Object)
75
77
  ], Master.prototype, "phone", void 0);
76
78
  __decorate([
77
79
  (0, typeorm_1.ManyToOne)(() => City_1.City, (city) => city.masters, {
@@ -93,11 +95,24 @@ __decorate([
93
95
  __decorate([
94
96
  (0, typeorm_1.Column)({
95
97
  type: "varchar",
98
+ nullable: false,
99
+ default: null,
96
100
  length: 255,
97
101
  comment: "Contraseña almacenada tipo SHA256 del master.",
98
102
  }),
99
- __metadata("design:type", String)
103
+ __metadata("design:type", Object)
100
104
  ], Master.prototype, "password", void 0);
105
+ __decorate([
106
+ (0, typeorm_1.Column)({
107
+ length: 255,
108
+ type: "varchar",
109
+ unique: true,
110
+ nullable: true,
111
+ default: null,
112
+ comment: "Guardamos el token o lo que nos retorna google cuando le damos iniciar con google",
113
+ }),
114
+ __metadata("design:type", Object)
115
+ ], Master.prototype, "google_id", void 0);
101
116
  __decorate([
102
117
  (0, typeorm_1.Column)({
103
118
  type: "longtext",
@@ -188,6 +203,10 @@ __decorate([
188
203
  (0, typeorm_1.OneToMany)(() => __1.PartnerNotification, (partner_notification) => partner_notification.master),
189
204
  __metadata("design:type", Array)
190
205
  ], Master.prototype, "masters_notification", void 0);
206
+ __decorate([
207
+ (0, typeorm_1.OneToMany)(() => __1.MasterSession, (MasterSession) => MasterSession.master),
208
+ __metadata("design:type", Array)
209
+ ], Master.prototype, "masters_session", void 0);
191
210
  exports.Master = Master = __decorate([
192
211
  (0, typeorm_1.Entity)({
193
212
  comment: "Tabla agregada para los usuarios qué son administradores de la plataforma.",
@@ -0,0 +1,13 @@
1
+ import { Master } from "..";
2
+ export declare class MasterSession {
3
+ id: number;
4
+ master: Master;
5
+ platform: number;
6
+ token: string;
7
+ ip_address: string;
8
+ start_time: Date;
9
+ finish_time: Date | null;
10
+ status: number;
11
+ created: Date;
12
+ updated: Date | null;
13
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MasterSession = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const __1 = require("..");
15
+ const dateTransformer_1 = require("../transformers/dateTransformer");
16
+ let MasterSession = class MasterSession {
17
+ };
18
+ exports.MasterSession = MasterSession;
19
+ __decorate([
20
+ (0, typeorm_1.PrimaryGeneratedColumn)({
21
+ type: "int",
22
+ comment: "Número de identificación (ID) único de cada registro.",
23
+ }),
24
+ __metadata("design:type", Number)
25
+ ], MasterSession.prototype, "id", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.ManyToOne)(() => __1.Master, (master) => master.masters_session, {
28
+ onDelete: "CASCADE",
29
+ onUpdate: "NO ACTION",
30
+ }),
31
+ (0, typeorm_1.JoinColumn)({ name: "master" }),
32
+ __metadata("design:type", __1.Master)
33
+ ], MasterSession.prototype, "master", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({
36
+ type: "int",
37
+ default: 1,
38
+ comment: "Plataforma a la que está inciando sesión:\r\n1. Administrador.",
39
+ }),
40
+ __metadata("design:type", Number)
41
+ ], MasterSession.prototype, "platform", void 0);
42
+ __decorate([
43
+ (0, typeorm_1.Column)({
44
+ length: 255,
45
+ type: "varchar",
46
+ comment: "Token generado para la sesión.",
47
+ }),
48
+ __metadata("design:type", String)
49
+ ], MasterSession.prototype, "token", void 0);
50
+ __decorate([
51
+ (0, typeorm_1.Column)({
52
+ length: 255,
53
+ type: "varchar",
54
+ comment: "Dirección IP de donde está accediendo.",
55
+ }),
56
+ __metadata("design:type", String)
57
+ ], MasterSession.prototype, "ip_address", void 0);
58
+ __decorate([
59
+ (0, typeorm_1.Column)({
60
+ type: "datetime",
61
+ comment: "Fecha de inicio de la sesión.",
62
+ transformer: new dateTransformer_1.DateTransformer(),
63
+ }),
64
+ __metadata("design:type", Date)
65
+ ], MasterSession.prototype, "start_time", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)({
68
+ type: "datetime",
69
+ nullable: true,
70
+ default: null,
71
+ comment: "Fecha de finalización de la sesión.",
72
+ transformer: new dateTransformer_1.DateTransformer(),
73
+ }),
74
+ __metadata("design:type", Object)
75
+ ], MasterSession.prototype, "finish_time", void 0);
76
+ __decorate([
77
+ (0, typeorm_1.Column)({
78
+ default: 1,
79
+ type: "int",
80
+ width: 1,
81
+ comment: "Estado de la sesión:\r\n1. Activa.\r\n2. Expirada.\r\n3. Revocada.",
82
+ }),
83
+ __metadata("design:type", Number)
84
+ ], MasterSession.prototype, "status", void 0);
85
+ __decorate([
86
+ (0, typeorm_1.Column)({
87
+ type: "datetime",
88
+ comment: "Fecha de creación del registro.",
89
+ transformer: new dateTransformer_1.DateTransformer(),
90
+ }),
91
+ __metadata("design:type", Date)
92
+ ], MasterSession.prototype, "created", void 0);
93
+ __decorate([
94
+ (0, typeorm_1.Column)({
95
+ type: "datetime",
96
+ nullable: true,
97
+ comment: "Fecha de actualización del registro.",
98
+ transformer: new dateTransformer_1.DateTransformer(),
99
+ }),
100
+ __metadata("design:type", Object)
101
+ ], MasterSession.prototype, "updated", void 0);
102
+ exports.MasterSession = MasterSession = __decorate([
103
+ (0, typeorm_1.Entity)({
104
+ comment: "Tabla creada para llevar el control de las sesiones (master)",
105
+ name: "master_session",
106
+ })
107
+ ], MasterSession);
@@ -71,6 +71,7 @@ export { ProductImage } from "./entities/ProductImage";
71
71
  export { LocalPaymentMethod } from "./entities/LocalPaymentMethod";
72
72
  export { VerificationCode } from "./entities/VerificationCode";
73
73
  export { PartnerPlatformSectionPermissionAssociate } from "./entities/PartnerPlatformSectionPermissionAssociate";
74
+ export { MasterSession } from "./entities/MasterSession";
74
75
  export { LocalsCompany } from "./views/LocalsCompany";
75
76
  export { VerifyLocals } from "./views/VerifyLocals";
76
77
  export { MasterNotifications } from "./views/MasterNotifications";
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ToppingImage = exports.ProductDate = exports.ProductSchedule = exports.CategoryDate = exports.Bank = exports.ServicePlan = exports.PartnerPlatform = exports.PartnerPlatformSection = exports.LocalPlan = exports.MasterNotification = exports.VerifyLocal = exports.PosSystem = exports.AuthenticationCredential = exports.BusinessType = exports.UserAddress = exports.User = exports.TypeMeasureIngredient = exports.Square = exports.RequestProductGroupComplement = exports.RequestProduct = exports.Request = exports.Region = exports.ProductTopping = exports.ProductIngredient = exports.ProductGroupComplement = exports.ProductGroup = exports.Product = exports.Plan = exports.PaymentMethod = exports.PartnerRole = exports.PartnerPlatformSectionPermission = exports.PartnerNotification = exports.Partner = exports.MasterRole = exports.MasterPermission = exports.Master = exports.LocalQualification = exports.Local = exports.DiscountCodeUser = exports.DiscountCodeCompany = exports.Day = exports.Country = exports.Configuration = exports.Company = exports.CodeRedemptionHistoryUser = exports.CodeRedemptionHistoryCompany = exports.City = exports.ScheduleCategory = exports.Category = exports.BusinessTypeProduct = void 0;
18
- exports.CustomRepository = exports.getLocalReservesInformation = exports.getVerifyLocalsInformation = exports.getLocalsCompanyInformation = exports.getDiscountsCodeUserInformation = exports.getDiscountsCodeCompanyInformation = exports.LocalsCompanyInformationForTheTable = exports.LocalsCompanyInformationForTheMap = exports.LocalReserves = exports.LocalTableZonesFilter = exports.PartnerNotifications = exports.DiscountsCodeUser = exports.Partners = exports.ViewLocalsCompanies = exports.MasterNotifications = exports.VerifyLocals = exports.LocalsCompany = exports.PartnerPlatformSectionPermissionAssociate = exports.VerificationCode = exports.LocalPaymentMethod = exports.ProductImage = exports.Gallery = exports.RequestLocalTable = exports.RequestInvoiceCategory = exports.RequestInvoice = exports.LocalTableReserve = exports.LocalReserveStatus = exports.LocalReserve = exports.LocalTableReservePayment = exports.DecorationReserve = exports.LocalDecorationReserve = exports.LocalTable = exports.LocalTableZone = exports.RequestPrint = exports.ReceiptConfig = exports.RequestLocalPayment = exports.UserPaymentMethod = exports.RequestLocalHistory = exports.RequestLocal = exports.PartnerSession = void 0;
18
+ exports.CustomRepository = exports.getLocalReservesInformation = exports.getVerifyLocalsInformation = exports.getLocalsCompanyInformation = exports.getDiscountsCodeUserInformation = exports.getDiscountsCodeCompanyInformation = exports.LocalsCompanyInformationForTheTable = exports.LocalsCompanyInformationForTheMap = exports.LocalReserves = exports.LocalTableZonesFilter = exports.PartnerNotifications = exports.DiscountsCodeUser = exports.Partners = exports.ViewLocalsCompanies = exports.MasterNotifications = exports.VerifyLocals = exports.LocalsCompany = exports.MasterSession = exports.PartnerPlatformSectionPermissionAssociate = exports.VerificationCode = exports.LocalPaymentMethod = exports.ProductImage = exports.Gallery = exports.RequestLocalTable = exports.RequestInvoiceCategory = exports.RequestInvoice = exports.LocalTableReserve = exports.LocalReserveStatus = exports.LocalReserve = exports.LocalTableReservePayment = exports.DecorationReserve = exports.LocalDecorationReserve = exports.LocalTable = exports.LocalTableZone = exports.RequestPrint = exports.ReceiptConfig = exports.RequestLocalPayment = exports.UserPaymentMethod = exports.RequestLocalHistory = exports.RequestLocal = exports.PartnerSession = void 0;
19
19
  var BusinessTypeProduct_1 = require("./entities/BusinessTypeProduct");
20
20
  Object.defineProperty(exports, "BusinessTypeProduct", { enumerable: true, get: function () { return BusinessTypeProduct_1.BusinessTypeProduct; } });
21
21
  var Category_1 = require("./entities/Category");
@@ -162,6 +162,8 @@ var VerificationCode_1 = require("./entities/VerificationCode");
162
162
  Object.defineProperty(exports, "VerificationCode", { enumerable: true, get: function () { return VerificationCode_1.VerificationCode; } });
163
163
  var PartnerPlatformSectionPermissionAssociate_1 = require("./entities/PartnerPlatformSectionPermissionAssociate");
164
164
  Object.defineProperty(exports, "PartnerPlatformSectionPermissionAssociate", { enumerable: true, get: function () { return PartnerPlatformSectionPermissionAssociate_1.PartnerPlatformSectionPermissionAssociate; } });
165
+ var MasterSession_1 = require("./entities/MasterSession");
166
+ Object.defineProperty(exports, "MasterSession", { enumerable: true, get: function () { return MasterSession_1.MasterSession; } });
165
167
  var LocalsCompany_1 = require("./views/LocalsCompany");
166
168
  Object.defineProperty(exports, "LocalsCompany", { enumerable: true, get: function () { return LocalsCompany_1.LocalsCompany; } });
167
169
  var VerifyLocals_1 = require("./views/VerifyLocals");
@@ -4,7 +4,7 @@ exports.JsonEncryptionTransformer = void 0;
4
4
  const crypto = require("crypto");
5
5
  const ENCRYPTION_KEY = process.env.SECRET_ENCRYPTION_KEY || "clave-32-bytes-segura";
6
6
  const ALGORITHM = "aes-256-cbc";
7
- // KeyObject de 32 bytes (evita líos de tipos con CipherKey)
7
+ // KeyObject de 32 bytes
8
8
  const KEY = crypto.createSecretKey(crypto.createHash("sha256").update(String(ENCRYPTION_KEY)).digest());
9
9
  function looksLikeCBC(encoded) {
10
10
  // formato: iv:cipherHex
@@ -13,12 +13,10 @@ function looksLikeCBC(encoded) {
13
13
  function decryptValue(value) {
14
14
  if (typeof value !== "string" || !looksLikeCBC(value))
15
15
  return value;
16
- var parts = value.split(":");
17
- var ivHex = parts[0];
18
- var contentHex = parts[1];
19
- var iv = Buffer.from(ivHex, "hex");
20
- var decipher = crypto.createDecipheriv(ALGORITHM, KEY, iv);
21
- var dec = Buffer.concat([
16
+ const [ivHex, contentHex] = value.split(":");
17
+ const iv = Buffer.from(ivHex, "hex");
18
+ const decipher = crypto.createDecipheriv(ALGORITHM, KEY, iv);
19
+ const dec = Buffer.concat([
22
20
  decipher.update(Buffer.from(contentHex, "hex")),
23
21
  decipher.final(),
24
22
  ]);
@@ -27,45 +25,84 @@ function decryptValue(value) {
27
25
  function encryptValue(plain) {
28
26
  if (plain === null || plain === undefined)
29
27
  return null;
30
- var text = String(plain);
31
- var iv = crypto.randomBytes(16);
32
- var cipher = crypto.createCipheriv(ALGORITHM, KEY, iv);
33
- var enc = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]);
28
+ const text = String(plain);
29
+ const iv = crypto.randomBytes(16);
30
+ const cipher = crypto.createCipheriv(ALGORITHM, KEY, iv);
31
+ const enc = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]);
34
32
  return iv.toString("hex") + ":" + enc.toString("hex");
35
33
  }
36
- exports.JsonEncryptionTransformer = {
37
- to(value) {
38
- if (typeof value !== "object" || value === null)
39
- return JSON.stringify({});
40
- var out = {};
41
- for (var k in value) {
42
- var v = value[k];
43
- // No usamos startsWith (no tipado en ES5)
34
+ /** Recorre profundo y encripta solo claves `encrypted_*` */
35
+ function deepEncrypt(input) {
36
+ if (input === null || input === undefined)
37
+ return input;
38
+ if (Array.isArray(input)) {
39
+ const arr = [];
40
+ for (let i = 0; i < input.length; i++) {
41
+ arr[i] = deepEncrypt(input[i]);
42
+ }
43
+ return arr;
44
+ }
45
+ if (typeof input === "object") {
46
+ const out = {};
47
+ for (const k in input) {
48
+ const v = input[k];
44
49
  if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
45
50
  out[k] = encryptValue(v);
46
51
  }
47
52
  else {
48
- out[k] = v;
53
+ out[k] = deepEncrypt(v);
49
54
  }
50
55
  }
51
- return JSON.stringify(out);
56
+ return out;
57
+ }
58
+ // primitivos
59
+ return input;
60
+ }
61
+ /** Recorre profundo y desencripta solo claves `encrypted_*` */
62
+ function deepDecrypt(input) {
63
+ if (input === null || input === undefined)
64
+ return input;
65
+ if (Array.isArray(input)) {
66
+ const arr = [];
67
+ for (let i = 0; i < input.length; i++) {
68
+ arr[i] = deepDecrypt(input[i]);
69
+ }
70
+ return arr;
71
+ }
72
+ if (typeof input === "object") {
73
+ const out = {};
74
+ for (const k in input) {
75
+ const v = input[k];
76
+ if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
77
+ try {
78
+ out[k] = decryptValue(v);
79
+ }
80
+ catch {
81
+ out[k] = v; // si está corrupto, lo dejamos como está
82
+ }
83
+ }
84
+ else {
85
+ out[k] = deepDecrypt(v);
86
+ }
87
+ }
88
+ return out;
89
+ }
90
+ // primitivos
91
+ return input;
92
+ }
93
+ exports.JsonEncryptionTransformer = {
94
+ to(value) {
95
+ if (typeof value !== "object" || value === null)
96
+ return JSON.stringify({});
97
+ return JSON.stringify(deepEncrypt(value));
52
98
  },
53
99
  from(dbValue) {
54
100
  try {
55
- var parsed = JSON.parse(dbValue);
56
- for (var k in parsed) {
57
- if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
58
- try {
59
- parsed[k] = decryptValue(parsed[k]);
60
- }
61
- catch {
62
- // si falla, deja el valor original
63
- }
64
- }
65
- }
66
- return parsed;
101
+ const parsed = JSON.parse(dbValue);
102
+ return deepDecrypt(parsed);
67
103
  }
68
104
  catch {
105
+ // si no es JSON válido, no tumbar todo
69
106
  return {};
70
107
  }
71
108
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "3.9.7",
3
+ "version": "3.9.9",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@ import {
8
8
  OneToMany,
9
9
  PrimaryGeneratedColumn,
10
10
  } from "typeorm";
11
- import { MasterNotification, PartnerNotification, VerifyLocal } from "..";
11
+ import { MasterNotification, MasterSession, PartnerNotification, VerifyLocal } from "..";
12
12
  import { DateTransformer } from "../transformers/dateTransformer";
13
13
  import { jsonTransformer } from "../transformers/jsonTransformer";
14
14
  import { City } from "./City";
@@ -62,9 +62,11 @@ export class Master {
62
62
  type: "varchar",
63
63
  length: 12,
64
64
  unique: true,
65
+ nullable: true,
66
+ default: null,
65
67
  comment: "Número de celular del master.",
66
68
  })
67
- phone: string;
69
+ phone: string | null;
68
70
 
69
71
  @ManyToOne(() => City, (city) => city.masters, {
70
72
  onDelete: "RESTRICT",
@@ -83,10 +85,23 @@ export class Master {
83
85
 
84
86
  @Column({
85
87
  type: "varchar",
88
+ nullable: false,
89
+ default: null,
86
90
  length: 255,
87
91
  comment: "Contraseña almacenada tipo SHA256 del master.",
88
92
  })
89
- password: string;
93
+ password: string | null;
94
+
95
+ @Column({
96
+ length: 255,
97
+ type: "varchar",
98
+ unique: true,
99
+ nullable: true,
100
+ default: null,
101
+ comment:
102
+ "Guardamos el token o lo que nos retorna google cuando le damos iniciar con google",
103
+ })
104
+ google_id: string | null;
90
105
 
91
106
  @Column({
92
107
  type: "longtext",
@@ -180,4 +195,7 @@ export class Master {
180
195
  (partner_notification) => partner_notification.master
181
196
  )
182
197
  masters_notification: PartnerNotification[];
198
+
199
+ @OneToMany(() => MasterSession, (MasterSession) => MasterSession.master)
200
+ masters_session: MasterSession[];
183
201
  }
@@ -0,0 +1,89 @@
1
+ import {
2
+ Column,
3
+ Entity,
4
+ JoinColumn,
5
+ ManyToOne,
6
+ PrimaryGeneratedColumn,
7
+ } from "typeorm";
8
+ import { Master } from "..";
9
+ import { DateTransformer } from "../transformers/dateTransformer";
10
+
11
+ @Entity({
12
+ comment: "Tabla creada para llevar el control de las sesiones (master)",
13
+ name: "master_session",
14
+ })
15
+ export class MasterSession {
16
+ @PrimaryGeneratedColumn({
17
+ type: "int",
18
+ comment: "Número de identificación (ID) único de cada registro.",
19
+ })
20
+ id: number;
21
+
22
+ @ManyToOne(() => Master, (master) => master.masters_session, {
23
+ onDelete: "CASCADE",
24
+ onUpdate: "NO ACTION",
25
+ })
26
+ @JoinColumn({ name: "master" })
27
+ master: Master;
28
+
29
+ @Column({
30
+ type: "int",
31
+ default: 1,
32
+ comment: "Plataforma a la que está inciando sesión:\r\n1. Administrador.",
33
+ })
34
+ platform: number;
35
+
36
+ @Column({
37
+ length: 255,
38
+ type: "varchar",
39
+ comment: "Token generado para la sesión.",
40
+ })
41
+ token: string;
42
+
43
+ @Column({
44
+ length: 255,
45
+ type: "varchar",
46
+ comment: "Dirección IP de donde está accediendo.",
47
+ })
48
+ ip_address: string;
49
+
50
+ @Column({
51
+ type: "datetime",
52
+ comment: "Fecha de inicio de la sesión.",
53
+ transformer: new DateTransformer(),
54
+ })
55
+ start_time: Date;
56
+
57
+ @Column({
58
+ type: "datetime",
59
+ nullable: true,
60
+ default: null,
61
+ comment: "Fecha de finalización de la sesión.",
62
+ transformer: new DateTransformer(),
63
+ })
64
+ finish_time: Date | null;
65
+
66
+ @Column({
67
+ default: 1,
68
+ type: "int",
69
+ width: 1,
70
+ comment:
71
+ "Estado de la sesión:\r\n1. Activa.\r\n2. Expirada.\r\n3. Revocada.",
72
+ })
73
+ status: number;
74
+
75
+ @Column({
76
+ type: "datetime",
77
+ comment: "Fecha de creación del registro.",
78
+ transformer: new DateTransformer(),
79
+ })
80
+ created: Date;
81
+
82
+ @Column({
83
+ type: "datetime",
84
+ nullable: true,
85
+ comment: "Fecha de actualización del registro.",
86
+ transformer: new DateTransformer(),
87
+ })
88
+ updated: Date | null;
89
+ }
@@ -71,6 +71,7 @@ export { ProductImage } from "./entities/ProductImage";
71
71
  export { LocalPaymentMethod } from "./entities/LocalPaymentMethod";
72
72
  export { VerificationCode } from "./entities/VerificationCode";
73
73
  export { PartnerPlatformSectionPermissionAssociate } from "./entities/PartnerPlatformSectionPermissionAssociate";
74
+ export { MasterSession } from "./entities/MasterSession";
74
75
 
75
76
  export { LocalsCompany } from "./views/LocalsCompany";
76
77
  export { VerifyLocals } from "./views/VerifyLocals";
@@ -5,7 +5,7 @@ const ENCRYPTION_KEY =
5
5
  process.env.SECRET_ENCRYPTION_KEY || "clave-32-bytes-segura";
6
6
  const ALGORITHM = "aes-256-cbc";
7
7
 
8
- // KeyObject de 32 bytes (evita líos de tipos con CipherKey)
8
+ // KeyObject de 32 bytes
9
9
  const KEY = crypto.createSecretKey(
10
10
  crypto.createHash("sha256").update(String(ENCRYPTION_KEY)).digest()
11
11
  );
@@ -17,14 +17,10 @@ function looksLikeCBC(encoded: string) {
17
17
 
18
18
  function decryptValue(value: any): any {
19
19
  if (typeof value !== "string" || !looksLikeCBC(value)) return value;
20
-
21
- var parts = value.split(":");
22
- var ivHex = parts[0];
23
- var contentHex = parts[1];
24
-
25
- var iv = Buffer.from(ivHex, "hex");
26
- var decipher = crypto.createDecipheriv(ALGORITHM, KEY, iv);
27
- var dec = Buffer.concat([
20
+ const [ivHex, contentHex] = value.split(":");
21
+ const iv = Buffer.from(ivHex, "hex");
22
+ const decipher = crypto.createDecipheriv(ALGORITHM, KEY, iv);
23
+ const dec = Buffer.concat([
28
24
  decipher.update(Buffer.from(contentHex, "hex")),
29
25
  decipher.final(),
30
26
  ]);
@@ -33,45 +29,87 @@ function decryptValue(value: any): any {
33
29
 
34
30
  function encryptValue(plain: any): string | null {
35
31
  if (plain === null || plain === undefined) return null;
36
- var text = String(plain);
37
-
38
- var iv = crypto.randomBytes(16);
39
- var cipher = crypto.createCipheriv(ALGORITHM, KEY, iv);
40
- var enc = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]);
32
+ const text = String(plain);
33
+ const iv = crypto.randomBytes(16);
34
+ const cipher = crypto.createCipheriv(ALGORITHM, KEY, iv);
35
+ const enc = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]);
41
36
  return iv.toString("hex") + ":" + enc.toString("hex");
42
37
  }
43
38
 
44
- export const JsonEncryptionTransformer: ValueTransformer = {
45
- to(value: any): string {
46
- if (typeof value !== "object" || value === null) return JSON.stringify({});
39
+ /** Recorre profundo y encripta solo claves `encrypted_*` */
40
+ function deepEncrypt(input: any): any {
41
+ if (input === null || input === undefined) return input;
42
+
43
+ if (Array.isArray(input)) {
44
+ const arr: any[] = [];
45
+ for (let i = 0; i < input.length; i++) {
46
+ arr[i] = deepEncrypt(input[i]);
47
+ }
48
+ return arr;
49
+ }
47
50
 
48
- var out: { [k: string]: any } = {};
49
- for (var k in value) {
50
- var v = value[k];
51
- // No usamos startsWith (no tipado en ES5)
51
+ if (typeof input === "object") {
52
+ const out: { [k: string]: any } = {};
53
+ for (const k in input) {
54
+ const v = input[k];
52
55
  if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
53
56
  out[k] = encryptValue(v);
54
57
  } else {
55
- out[k] = v;
58
+ out[k] = deepEncrypt(v);
56
59
  }
57
60
  }
58
- return JSON.stringify(out);
61
+ return out;
62
+ }
63
+
64
+ // primitivos
65
+ return input;
66
+ }
67
+
68
+ /** Recorre profundo y desencripta solo claves `encrypted_*` */
69
+ function deepDecrypt(input: any): any {
70
+ if (input === null || input === undefined) return input;
71
+
72
+ if (Array.isArray(input)) {
73
+ const arr: any[] = [];
74
+ for (let i = 0; i < input.length; i++) {
75
+ arr[i] = deepDecrypt(input[i]);
76
+ }
77
+ return arr;
78
+ }
79
+
80
+ if (typeof input === "object") {
81
+ const out: { [k: string]: any } = {};
82
+ for (const k in input) {
83
+ const v = input[k];
84
+ if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
85
+ try {
86
+ out[k] = decryptValue(v);
87
+ } catch {
88
+ out[k] = v; // si está corrupto, lo dejamos como está
89
+ }
90
+ } else {
91
+ out[k] = deepDecrypt(v);
92
+ }
93
+ }
94
+ return out;
95
+ }
96
+
97
+ // primitivos
98
+ return input;
99
+ }
100
+
101
+ export const JsonEncryptionTransformer: ValueTransformer = {
102
+ to(value: any): string {
103
+ if (typeof value !== "object" || value === null) return JSON.stringify({});
104
+ return JSON.stringify(deepEncrypt(value));
59
105
  },
60
106
 
61
107
  from(dbValue: string): any {
62
108
  try {
63
- var parsed = JSON.parse(dbValue);
64
- for (var k in parsed) {
65
- if (k.length >= 10 && k.substr(0, 10) === "encrypted_") {
66
- try {
67
- parsed[k] = decryptValue(parsed[k]);
68
- } catch {
69
- // si falla, deja el valor original
70
- }
71
- }
72
- }
73
- return parsed;
109
+ const parsed = JSON.parse(dbValue);
110
+ return deepDecrypt(parsed);
74
111
  } catch {
112
+ // si no es JSON válido, no tumbar todo
75
113
  return {};
76
114
  }
77
115
  },