@carbonbox/domain 0.20.1 → 0.21.2

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.
Files changed (68) hide show
  1. package/build/carbonbox/shared/domain/enums/IdentityDocumentType.js +10 -0
  2. package/build/carbonbox/shared/domain/exceptions/InvalidIdentityDocumentTypeError.js +18 -0
  3. package/build/carbonbox/shared/domain/types/IdentityDocument.js +2 -0
  4. package/build/carbonbox/shared/domain/types/IdentityDocumentPrimitives.js +2 -0
  5. package/build/carbonbox/shared/domain/value-objects/CarbonClientReference.js +33 -13
  6. package/build/carbonbox/shared/domain/value-objects/CarbonClientReferences.js +24 -10
  7. package/build/carbonbox/shared/domain/value-objects/IdentityDocument.js +336 -0
  8. package/build/carbonbox/shared/domain/value-objects/StakeholderReference.js +25 -10
  9. package/build/carbonbox/shared/domain/value-objects/StakeholderReferences.js +34 -18
  10. package/build/carbonbox/stakeholders/carbon-clients/domain/entity/CarbonClient.js +22 -5
  11. package/build/carbonbox/stakeholders/carbon-clients/domain/value-objects/CarbonClientIdentityDocument.js +27 -0
  12. package/build/carbonbox/stakeholders/carbon-coordinators/domain/entity/CarbonCoordinator.js +22 -5
  13. package/build/carbonbox/stakeholders/carbon-coordinators/domain/value-objects/CarbonCoordinatorIdentityDocument.js +27 -0
  14. package/build/carbonbox/stakeholders/carbon-host/domain/entity/CarbonHost.js +15 -5
  15. package/build/carbonbox/stakeholders/carbon-managers/domain/entity/CarbonManager.js +22 -5
  16. package/build/carbonbox/stakeholders/carbon-managers/domain/value-objects/CarbonManagerIdentityDocument.js +27 -0
  17. package/build/carbonbox/stakeholders/shared/domain/entity/Stakeholder.js +21 -4
  18. package/build/carbonbox/stakeholders/shared/domain/value-objects/StakeholderIdentityDocument.js +47 -0
  19. package/build/main/index.js +16 -1
  20. package/build/types/carbonbox/shared/domain/enums/IdentityDocumentType.d.ts +7 -0
  21. package/build/types/carbonbox/shared/domain/enums/IdentityDocumentType.d.ts.map +1 -0
  22. package/build/types/carbonbox/shared/domain/exceptions/InvalidIdentityDocumentTypeError.d.ts +7 -0
  23. package/build/types/carbonbox/shared/domain/exceptions/InvalidIdentityDocumentTypeError.d.ts.map +1 -0
  24. package/build/types/carbonbox/shared/domain/types/CarbonClientReference.d.ts +1 -1
  25. package/build/types/carbonbox/shared/domain/types/CarbonClientReference.d.ts.map +1 -1
  26. package/build/types/carbonbox/shared/domain/types/CarbonClientReferencePrimitives.d.ts +1 -1
  27. package/build/types/carbonbox/shared/domain/types/CarbonClientReferencePrimitives.d.ts.map +1 -1
  28. package/build/types/carbonbox/shared/domain/types/IdentityDocument.d.ts +9 -0
  29. package/build/types/carbonbox/shared/domain/types/IdentityDocument.d.ts.map +1 -0
  30. package/build/types/carbonbox/shared/domain/types/IdentityDocumentPrimitives.d.ts +9 -0
  31. package/build/types/carbonbox/shared/domain/types/IdentityDocumentPrimitives.d.ts.map +1 -0
  32. package/build/types/carbonbox/shared/domain/types/StakeholderReference.d.ts +1 -1
  33. package/build/types/carbonbox/shared/domain/types/StakeholderReference.d.ts.map +1 -1
  34. package/build/types/carbonbox/shared/domain/types/StakeholderReferencePrimitives.d.ts +1 -1
  35. package/build/types/carbonbox/shared/domain/types/StakeholderReferencePrimitives.d.ts.map +1 -1
  36. package/build/types/carbonbox/shared/domain/value-objects/CarbonClientReference.d.ts +3 -3
  37. package/build/types/carbonbox/shared/domain/value-objects/CarbonClientReference.d.ts.map +1 -1
  38. package/build/types/carbonbox/shared/domain/value-objects/CarbonClientReferences.d.ts.map +1 -1
  39. package/build/types/carbonbox/shared/domain/value-objects/IdentityDocument.d.ts +132 -0
  40. package/build/types/carbonbox/shared/domain/value-objects/IdentityDocument.d.ts.map +1 -0
  41. package/build/types/carbonbox/shared/domain/value-objects/StakeholderReference.d.ts +4 -2
  42. package/build/types/carbonbox/shared/domain/value-objects/StakeholderReference.d.ts.map +1 -1
  43. package/build/types/carbonbox/shared/domain/value-objects/StakeholderReferences.d.ts.map +1 -1
  44. package/build/types/carbonbox/stakeholders/carbon-clients/domain/entity/CarbonClient.d.ts.map +1 -1
  45. package/build/types/carbonbox/stakeholders/carbon-clients/domain/value-objects/CarbonClientIdentityDocument.d.ts +10 -0
  46. package/build/types/carbonbox/stakeholders/carbon-clients/domain/value-objects/CarbonClientIdentityDocument.d.ts.map +1 -0
  47. package/build/types/carbonbox/stakeholders/carbon-coordinators/domain/entity/CarbonCoordinator.d.ts.map +1 -1
  48. package/build/types/carbonbox/stakeholders/carbon-coordinators/domain/value-objects/CarbonCoordinatorIdentityDocument.d.ts +10 -0
  49. package/build/types/carbonbox/stakeholders/carbon-coordinators/domain/value-objects/CarbonCoordinatorIdentityDocument.d.ts.map +1 -0
  50. package/build/types/carbonbox/stakeholders/carbon-host/domain/entity/CarbonHost.d.ts.map +1 -1
  51. package/build/types/carbonbox/stakeholders/carbon-managers/domain/entity/CarbonManager.d.ts.map +1 -1
  52. package/build/types/carbonbox/stakeholders/carbon-managers/domain/value-objects/CarbonManagerIdentityDocument.d.ts +10 -0
  53. package/build/types/carbonbox/stakeholders/carbon-managers/domain/value-objects/CarbonManagerIdentityDocument.d.ts.map +1 -0
  54. package/build/types/carbonbox/stakeholders/shared/domain/entity/IStakeholder.d.ts +3 -1
  55. package/build/types/carbonbox/stakeholders/shared/domain/entity/IStakeholder.d.ts.map +1 -1
  56. package/build/types/carbonbox/stakeholders/shared/domain/entity/Stakeholder.d.ts +3 -1
  57. package/build/types/carbonbox/stakeholders/shared/domain/entity/Stakeholder.d.ts.map +1 -1
  58. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderPrimitives.d.ts +3 -1
  59. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderPrimitives.d.ts.map +1 -1
  60. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderProps.d.ts +3 -1
  61. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderProps.d.ts.map +1 -1
  62. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderPropsWithHashedPassword.d.ts +3 -1
  63. package/build/types/carbonbox/stakeholders/shared/domain/types/StakeholderPropsWithHashedPassword.d.ts.map +1 -1
  64. package/build/types/carbonbox/stakeholders/shared/domain/value-objects/StakeholderIdentityDocument.d.ts +22 -0
  65. package/build/types/carbonbox/stakeholders/shared/domain/value-objects/StakeholderIdentityDocument.d.ts.map +1 -0
  66. package/build/types/main/index.d.ts +9 -0
  67. package/build/types/main/index.d.ts.map +1 -1
  68. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdentityDocumentType = void 0;
4
+ var IdentityDocumentType;
5
+ (function (IdentityDocumentType) {
6
+ IdentityDocumentType["CC"] = "CC";
7
+ IdentityDocumentType["CE"] = "CE";
8
+ IdentityDocumentType["PASSPORT"] = "PASSPORT";
9
+ IdentityDocumentType["DNI"] = "DNI";
10
+ })(IdentityDocumentType || (exports.IdentityDocumentType = IdentityDocumentType = {}));
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidIdentityDocumentTypeError = void 0;
4
+ const RootError_1 = require("./RootError");
5
+ class InvalidIdentityDocumentTypeError extends RootError_1.RootError {
6
+ constructor(invalidType, validTypes) {
7
+ const message = `Invalid identity document type: '${invalidType}'. Valid types: ${validTypes.join(', ')}.`;
8
+ super(message);
9
+ this.name = 'InvalidIdentityDocumentTypeError';
10
+ }
11
+ static create(invalidType, validTypes) {
12
+ return new InvalidIdentityDocumentTypeError(invalidType, validTypes);
13
+ }
14
+ logError() {
15
+ return `${this.name}: ${this.message}`;
16
+ }
17
+ }
18
+ exports.InvalidIdentityDocumentTypeError = InvalidIdentityDocumentTypeError;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -31,6 +31,7 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
31
31
  super(value, skipDomainValidation, propertyName, 'The provided value must be of type CarbonClientReference from the domain layer', { allowNull: false, allowUndefined: false });
32
32
  _CarbonClientReference_id.set(this, void 0);
33
33
  _CarbonClientReference_displayName.set(this, void 0);
34
+ // USR-020: una referencia a una persona natural puede no tener identificación tributaria.
34
35
  _CarbonClientReference_taxIdentification.set(this, void 0);
35
36
  _CarbonClientReference_roleType.set(this, void 0);
36
37
  _CarbonClientReference_accountType.set(this, void 0);
@@ -67,8 +68,8 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
67
68
  if (typeof value.displayName !== 'string') {
68
69
  throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('displayName', 'string', typeof value.displayName);
69
70
  }
70
- if (this.taxIdentificationIsInvalid(value.taxIdentification)) {
71
- throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('taxIdentification', 'TaxIdentification object', typeof value.taxIdentification);
71
+ if (value.taxIdentification !== null && this.taxIdentificationIsInvalid(value.taxIdentification)) {
72
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('taxIdentification', 'TaxIdentification object | null', typeof value.taxIdentification);
72
73
  }
73
74
  if (typeof value.roleType !== 'string') {
74
75
  throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('roleType', 'string', typeof value.roleType);
@@ -112,8 +113,9 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
112
113
  * Valida la identificación tributaria usando las validaciones del VO TaxIdentification.
113
114
  */
114
115
  static guardAgainstInvalidTaxIdentification(taxIdentification) {
116
+ // USR-020: null es válido (persona natural sin identificación tributaria).
115
117
  if (this.taxIdentificationIsNull(taxIdentification)) {
116
- throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('taxIdentification', 'TaxIdentification object', 'null or undefined');
118
+ return;
117
119
  }
118
120
  // Usar las validaciones completas del VO TaxIdentification
119
121
  TaxIdentification_1.TaxIdentification.validateCompletely(taxIdentification, 'taxIdentification');
@@ -219,18 +221,21 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
219
221
  * Verifica si la identificación tributaria tiene entidad emisora.
220
222
  */
221
223
  hasIssuedBy() {
222
- return __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").issuedBy !== null;
224
+ return (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.issuedBy ?? null) !== null;
223
225
  }
224
226
  /**
225
227
  * Verifica si la identificación tributaria tiene fechas de validez.
226
228
  */
227
229
  hasValidityPeriod() {
228
- return __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validFrom !== null || __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validUntil !== null;
230
+ return (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.validFrom ?? null) !== null || (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.validUntil ?? null) !== null;
229
231
  }
230
232
  /**
231
233
  * Verifica si el cliente puede participar en operaciones.
232
234
  */
233
235
  canParticipateInOperations() {
236
+ if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === null) {
237
+ return true;
238
+ }
234
239
  const now = new Date();
235
240
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
236
241
  if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validFrom) {
@@ -258,13 +263,13 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
258
263
  * Verifica si pertenece a un país específico.
259
264
  */
260
265
  belongsToCountry(countryCode) {
261
- return __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country === countryCode.trim().toUpperCase();
266
+ return __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.country === countryCode.trim().toUpperCase();
262
267
  }
263
268
  /**
264
269
  * Verifica si requiere renovación próxima (dentro de 30 días).
265
270
  */
266
271
  requiresRenewalSoon() {
267
- if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validUntil === null) {
272
+ if ((__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.validUntil ?? null) === null) {
268
273
  return false; // Si no tiene fecha de vencimiento, no requiere renovación
269
274
  }
270
275
  const now = new Date();
@@ -275,6 +280,9 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
275
280
  * Verifica si la identificación tributaria será válida en una fecha específica.
276
281
  */
277
282
  isValidOnDate(date) {
283
+ if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === null) {
284
+ return true;
285
+ }
278
286
  const checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
279
287
  if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validFrom) {
280
288
  const fromDate = this.parseDate(__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validFrom);
@@ -294,12 +302,13 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
294
302
  * Obtiene días restantes hasta el vencimiento.
295
303
  */
296
304
  getDaysUntilExpiration() {
297
- if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validUntil === null) {
305
+ const validUntil = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.validUntil ?? null;
306
+ if (validUntil === null) {
298
307
  return null;
299
308
  }
300
309
  const now = new Date();
301
310
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
302
- const [day, month, year] = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validUntil.split('/').map(Number);
311
+ const [day, month, year] = validUntil.split('/').map(Number);
303
312
  const expirationDate = new Date(year, month - 1, day);
304
313
  const diffTime = expirationDate.getTime() - today.getTime();
305
314
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
@@ -309,15 +318,17 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
309
318
  * Obtiene una representación formateada para mostrar al usuario.
310
319
  */
311
320
  getFormattedDisplay() {
312
- const taxInfo = `${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type}-${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").number}-${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country}`;
321
+ const taxInfo = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === null
322
+ ? 'N/A'
323
+ : `${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type}-${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").number}-${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country}`;
313
324
  return `${__classPrivateFieldGet(this, _CarbonClientReference_displayName, "f")} (${taxInfo}) - ${__classPrivateFieldGet(this, _CarbonClientReference_accountType, "f")} Carbon Client`;
314
325
  }
315
326
  /**
316
327
  * Obtiene información resumida del cliente de carbono.
317
328
  */
318
329
  getSummary() {
319
- const { country } = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f");
320
- const taxType = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type;
330
+ const country = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.country ?? 'N/A';
331
+ const taxType = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f")?.type ?? 'N/A';
321
332
  return `${__classPrivateFieldGet(this, _CarbonClientReference_displayName, "f")} - ${__classPrivateFieldGet(this, _CarbonClientReference_accountType, "f").toLowerCase()} carbon client from ${country} (${taxType})`;
322
333
  }
323
334
  /**
@@ -343,6 +354,9 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
343
354
  * Compara si dos identificaciones tributarias son iguales.
344
355
  */
345
356
  taxIdentificationsAreEqual(other) {
357
+ if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === null || other === null) {
358
+ return __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === other;
359
+ }
346
360
  return (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type === other.type
347
361
  && __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").number === other.number
348
362
  && __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country === other.country
@@ -364,6 +378,9 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
364
378
  * Compara si dos identificaciones tributarias representan el mismo identificador.
365
379
  */
366
380
  hasSameIdentifier(other) {
381
+ if (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f") === null || other === null) {
382
+ return false;
383
+ }
367
384
  return (__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type === other.type
368
385
  && __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").number === other.number
369
386
  && __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country === other.country);
@@ -372,7 +389,10 @@ class CarbonClientReference extends ObjectValueObject_1.ObjectValueObject {
372
389
  * Genera un hash code para usar en colecciones.
373
390
  */
374
391
  hashCode() {
375
- const taxHash = `${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").type}_${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").number}_${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").country}_${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").issuedBy}_${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validFrom}_${__classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f").validUntil}`;
392
+ const t = __classPrivateFieldGet(this, _CarbonClientReference_taxIdentification, "f");
393
+ const taxHash = t === null
394
+ ? 'no-tax'
395
+ : `${t.type}_${t.number}_${t.country}_${t.issuedBy}_${t.validFrom}_${t.validUntil}`;
376
396
  return `${__classPrivateFieldGet(this, _CarbonClientReference_id, "f")}_${__classPrivateFieldGet(this, _CarbonClientReference_displayName, "f")}_${taxHash}_${__classPrivateFieldGet(this, _CarbonClientReference_roleType, "f")}_${__classPrivateFieldGet(this, _CarbonClientReference_accountType, "f")}`;
377
397
  }
378
398
  /**
@@ -66,7 +66,9 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
66
66
  * Valida que no haya identificaciones tributarias duplicadas.
67
67
  */
68
68
  static guardAgainstDuplicateClientTaxIdentifications(value, propertyName) {
69
- const taxIdentifications = value.map((client) => `${client.taxIdentification.type}-${client.taxIdentification.number}-${client.taxIdentification.country}`);
69
+ const taxIdentifications = value
70
+ .filter((client) => client.taxIdentification !== null)
71
+ .map((client) => `${client.taxIdentification.type}-${client.taxIdentification.number}-${client.taxIdentification.country}`);
70
72
  const uniqueIds = new Set(taxIdentifications);
71
73
  if (taxIdentifications.length !== uniqueIds.size) {
72
74
  throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(`${propertyName}.taxIdentification`, 'unique tax identifications', 'duplicate tax identifications found');
@@ -96,8 +98,8 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
96
98
  if (typeof clientReference.displayName !== 'string') {
97
99
  throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create(`${propertyName}.displayName`, 'string', typeof clientReference.displayName);
98
100
  }
99
- if (!clientReference.taxIdentification || typeof clientReference.taxIdentification !== 'object') {
100
- throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create(`${propertyName}.taxIdentification`, 'TaxIdentification object', typeof clientReference.taxIdentification);
101
+ if (clientReference.taxIdentification !== null && typeof clientReference.taxIdentification !== 'object') {
102
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create(`${propertyName}.taxIdentification`, 'TaxIdentification object | null', typeof clientReference.taxIdentification);
101
103
  }
102
104
  if (typeof clientReference.roleType !== 'string') {
103
105
  throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create(`${propertyName}.roleType`, 'string', typeof clientReference.roleType);
@@ -154,7 +156,8 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
154
156
  * Obtiene un cliente por su identificación tributaria.
155
157
  */
156
158
  getClientByTaxIdentification(type, number, country) {
157
- const clientFound = __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").find((client) => client.taxIdentification.type === type.trim()
159
+ const clientFound = __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").find((client) => client.taxIdentification !== null
160
+ && client.taxIdentification.type === type.trim()
158
161
  && client.taxIdentification.number === number.trim()
159
162
  && client.taxIdentification.country === country.trim().toUpperCase());
160
163
  return clientFound || null;
@@ -197,7 +200,9 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
197
200
  * Obtiene todas las identificaciones tributarias como strings.
198
201
  */
199
202
  getAllTaxIdentificationStrings() {
200
- return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").map((client) => `${client.taxIdentification.type}-${client.taxIdentification.number}-${client.taxIdentification.country}`);
203
+ return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").map((client) => (client.taxIdentification === null
204
+ ? 'N/A'
205
+ : `${client.taxIdentification.type}-${client.taxIdentification.number}-${client.taxIdentification.country}`));
201
206
  }
202
207
  /**
203
208
  * Busca clientes por texto en el nombre.
@@ -212,8 +217,8 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
212
217
  findClientsMatching(searchText) {
213
218
  const lowerSearchText = searchText.toLowerCase().trim();
214
219
  return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").filter((client) => client.displayName.toLowerCase().includes(lowerSearchText)
215
- || client.taxIdentification.number.toLowerCase().includes(lowerSearchText)
216
- || client.taxIdentification.type.toLowerCase().includes(lowerSearchText));
220
+ || (client.taxIdentification !== null && client.taxIdentification.number.toLowerCase().includes(lowerSearchText))
221
+ || (client.taxIdentification !== null && client.taxIdentification.type.toLowerCase().includes(lowerSearchText)));
217
222
  }
218
223
  /**
219
224
  * Obtiene los primeros N clientes.
@@ -238,14 +243,14 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
238
243
  */
239
244
  getClientsByCountry(countryCode) {
240
245
  const upperCountryCode = countryCode.trim().toUpperCase();
241
- return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").filter((client) => client.taxIdentification.country === upperCountryCode);
246
+ return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").filter((client) => client.taxIdentification?.country === upperCountryCode);
242
247
  }
243
248
  /**
244
249
  * Obtiene clientes por tipo de identificación tributaria.
245
250
  */
246
251
  getClientsByTaxType(taxType) {
247
252
  const upperTaxType = taxType.trim().toUpperCase();
248
- return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").filter((client) => client.taxIdentification.type === upperTaxType);
253
+ return __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f").filter((client) => client.taxIdentification?.type === upperTaxType);
249
254
  }
250
255
  /**
251
256
  * Verifica si todos los clientes tienen nombres únicos.
@@ -308,6 +313,9 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
308
313
  * Compara si dos identificaciones tributarias son iguales.
309
314
  */
310
315
  taxIdentificationsAreEqual(tax1, tax2) {
316
+ if (tax1 === null || tax1 === undefined || tax2 === null || tax2 === undefined) {
317
+ return (tax1 ?? null) === (tax2 ?? null);
318
+ }
311
319
  return (tax1.type === tax2.type
312
320
  && tax1.number === tax2.number
313
321
  && tax1.country === tax2.country
@@ -320,7 +328,13 @@ class CarbonClientReferences extends ValueObject_1.ValueObject {
320
328
  */
321
329
  hashCode() {
322
330
  const clientHashes = __classPrivateFieldGet(this, _CarbonClientReferences_clientReferences, "f")
323
- .map((client) => `${client.id}_${client.displayName}_${client.accountType}_${client.taxIdentification.type}_${client.taxIdentification.number}_${client.taxIdentification.country}`)
331
+ .map((client) => {
332
+ const tax = client.taxIdentification;
333
+ const taxHash = tax === null
334
+ ? 'no-tax'
335
+ : `${tax.type}_${tax.number}_${tax.country}`;
336
+ return `${client.id}_${client.displayName}_${client.accountType}_${taxHash}`;
337
+ })
324
338
  .join('|');
325
339
  const optionsHash = __classPrivateFieldGet(this, _CarbonClientReferences_options, "f").allowEmpty ? 'allowEmpty' : 'requireElements';
326
340
  return `${optionsHash}_${clientHashes}`;
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _IdentityDocument_type, _IdentityDocument_number, _IdentityDocument_country, _IdentityDocument_issuedBy, _IdentityDocument_validFrom, _IdentityDocument_validUntil;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.IdentityDocument = void 0;
16
+ const InvalidPropertyTypeError_1 = require("../exceptions/InvalidPropertyTypeError");
17
+ const InvalidIdentityDocumentTypeError_1 = require("../exceptions/InvalidIdentityDocumentTypeError");
18
+ const InvalidCountryCodeError_1 = require("../exceptions/InvalidCountryCodeError");
19
+ const InvalidDateRangeError_1 = require("../exceptions/InvalidDateRangeError");
20
+ const ObjectValueObject_1 = require("./ObjectValueObject");
21
+ const String_1 = require("./String");
22
+ const NullableDate_1 = require("./NullableDate");
23
+ const CountryCode_1 = require("../enums/CountryCode");
24
+ const IdentityDocumentType_1 = require("../enums/IdentityDocumentType");
25
+ class IdentityDocument extends ObjectValueObject_1.ObjectValueObject {
26
+ /**
27
+ * Constructor protegido para que solo clases hijas puedan instanciar.
28
+ * Aplica todas las validaciones de dominio al momento de construcción.
29
+ */
30
+ constructor(value, skipDomainValidation, propertyName = IdentityDocument.DEFAULT_PROPERTY_NAME) {
31
+ super(value, skipDomainValidation, propertyName, 'The provided value must be of type IdentityDocument from the domain layer', { allowNull: false, allowUndefined: false });
32
+ _IdentityDocument_type.set(this, void 0);
33
+ _IdentityDocument_number.set(this, void 0);
34
+ _IdentityDocument_country.set(this, void 0);
35
+ _IdentityDocument_issuedBy.set(this, void 0);
36
+ _IdentityDocument_validFrom.set(this, void 0);
37
+ _IdentityDocument_validUntil.set(this, void 0);
38
+ if (skipDomainValidation === false) {
39
+ IdentityDocument.validateIdentityDocument(value, propertyName);
40
+ }
41
+ __classPrivateFieldSet(this, _IdentityDocument_type, value.type.trim().toUpperCase(), "f");
42
+ __classPrivateFieldSet(this, _IdentityDocument_number, value.number.trim(), "f");
43
+ __classPrivateFieldSet(this, _IdentityDocument_country, value.country.trim().toUpperCase(), "f");
44
+ __classPrivateFieldSet(this, _IdentityDocument_issuedBy, value.issuedBy?.trim() || null, "f");
45
+ __classPrivateFieldSet(this, _IdentityDocument_validFrom, value.validFrom?.trim() || null, "f");
46
+ __classPrivateFieldSet(this, _IdentityDocument_validUntil, value.validUntil?.trim() || null, "f");
47
+ }
48
+ /**
49
+ * Validación estática para reutilización en factory methods y constructores.
50
+ */
51
+ static validateIdentityDocument(value, propertyName) {
52
+ this.guardAgainstInvalidType(value, propertyName);
53
+ this.guardAgainstInvalidDocumentType(value.type);
54
+ this.guardAgainstInvalidNumber(value.number);
55
+ this.guardAgainstInvalidCountryCode(value.country);
56
+ this.guardAgainstInvalidIssuedBy(value.issuedBy);
57
+ this.guardAgainstInvalidValidFrom(value.validFrom);
58
+ this.guardAgainstInvalidValidUntil(value.validUntil);
59
+ this.guardAgainstInvalidDateRange(value.validFrom, value.validUntil);
60
+ }
61
+ /**
62
+ * Valida que el objeto tenga la estructura correcta.
63
+ */
64
+ static guardAgainstInvalidType(value, propertyName) {
65
+ if (!value || typeof value !== 'object') {
66
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create(propertyName, 'IdentityDocument object', typeof value);
67
+ }
68
+ if (typeof value.type !== 'string') {
69
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('type', 'string', typeof value.type);
70
+ }
71
+ if (typeof value.number !== 'string') {
72
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('number', 'string', typeof value.number);
73
+ }
74
+ if (typeof value.country !== 'string') {
75
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('country', 'string', typeof value.country);
76
+ }
77
+ if (value.issuedBy !== null && typeof value.issuedBy !== 'string') {
78
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('issuedBy', 'string | null', typeof value.issuedBy);
79
+ }
80
+ if (value.validFrom !== null && typeof value.validFrom !== 'string') {
81
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('validFrom', 'string | null', typeof value.validFrom);
82
+ }
83
+ if (value.validUntil !== null && typeof value.validUntil !== 'string') {
84
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('validUntil', 'string | null', typeof value.validUntil);
85
+ }
86
+ }
87
+ /**
88
+ * Valida que el tipo de documento de identidad sea válido.
89
+ */
90
+ static guardAgainstInvalidDocumentType(type) {
91
+ const trimmedType = type.trim().toUpperCase();
92
+ if (trimmedType.length === 0) {
93
+ throw InvalidIdentityDocumentTypeError_1.InvalidIdentityDocumentTypeError.create('empty identity document type', this.VALID_TYPES);
94
+ }
95
+ if (!this.VALID_TYPES.includes(trimmedType)) {
96
+ throw InvalidIdentityDocumentTypeError_1.InvalidIdentityDocumentTypeError.create(trimmedType, this.VALID_TYPES);
97
+ }
98
+ }
99
+ /**
100
+ * Valida el número del documento de identidad (no vacío y dentro de los límites de longitud).
101
+ */
102
+ static guardAgainstInvalidNumber(number) {
103
+ const trimmedNumber = number.trim();
104
+ if (trimmedNumber.length === 0) {
105
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('number', 'non-empty identity document number', 'empty string');
106
+ }
107
+ if (trimmedNumber.length < this.MIN_NUMBER_LENGTH || trimmedNumber.length > this.MAX_NUMBER_LENGTH) {
108
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('number', `identity document number with length between ${this.MIN_NUMBER_LENGTH} and ${this.MAX_NUMBER_LENGTH}`, `length ${trimmedNumber.length}`);
109
+ }
110
+ }
111
+ /**
112
+ * Valida el código de país según los valores permitidos en el enum CountryCode.
113
+ */
114
+ static guardAgainstInvalidCountryCode(country) {
115
+ const trimmedCountry = country.trim().toUpperCase();
116
+ if (trimmedCountry.length === 0) {
117
+ throw InvalidCountryCodeError_1.InvalidCountryCodeError.create('empty country code');
118
+ }
119
+ if (!this.VALID_COUNTRY_CODES.includes(trimmedCountry)) {
120
+ throw InvalidCountryCodeError_1.InvalidCountryCodeError.create(trimmedCountry);
121
+ }
122
+ }
123
+ /**
124
+ * Valida la entidad emisora si está presente.
125
+ */
126
+ static guardAgainstInvalidIssuedBy(issuedBy) {
127
+ if (issuedBy !== null) {
128
+ String_1.String.guardAgainstEmptyValue(issuedBy, 'issuedBy');
129
+ }
130
+ }
131
+ /**
132
+ * Valida la fecha de inicio de validez si está presente.
133
+ */
134
+ static guardAgainstInvalidValidFrom(validFrom) {
135
+ if (validFrom !== null) {
136
+ if (!NullableDate_1.NullableDate.isValidNullableDate(validFrom)) {
137
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('validFrom', 'valid date string (DD/MM/YYYY)', validFrom);
138
+ }
139
+ }
140
+ }
141
+ /**
142
+ * Valida la fecha de fin de validez si está presente.
143
+ */
144
+ static guardAgainstInvalidValidUntil(validUntil) {
145
+ if (validUntil !== null) {
146
+ if (!NullableDate_1.NullableDate.isValidNullableDate(validUntil)) {
147
+ throw InvalidPropertyTypeError_1.InvalidPropertyTypeError.create('validUntil', 'valid date string (DD/MM/YYYY)', validUntil);
148
+ }
149
+ }
150
+ }
151
+ /**
152
+ * Valida que el rango de fechas sea consistente.
153
+ */
154
+ static guardAgainstInvalidDateRange(validFrom, validUntil) {
155
+ if (validFrom && validUntil) {
156
+ const fromDate = this.parseDate(validFrom);
157
+ const untilDate = this.parseDate(validUntil);
158
+ if (fromDate >= untilDate) {
159
+ throw InvalidDateRangeError_1.InvalidDateRangeError.create(validFrom, validUntil);
160
+ }
161
+ }
162
+ }
163
+ /**
164
+ * Método auxiliar para parsear fechas en formato DD/MM/YYYY.
165
+ */
166
+ static parseDate(dateString) {
167
+ const [day, month, year] = dateString.split('/').map(Number);
168
+ return new Date(year, month - 1, day);
169
+ }
170
+ /**
171
+ * Tipo de documento de identidad (CC, CE, PASSPORT, DNI).
172
+ */
173
+ get type() {
174
+ return __classPrivateFieldGet(this, _IdentityDocument_type, "f");
175
+ }
176
+ /**
177
+ * Número del documento de identidad.
178
+ */
179
+ get number() {
180
+ return __classPrivateFieldGet(this, _IdentityDocument_number, "f");
181
+ }
182
+ /**
183
+ * País de emisión del documento.
184
+ */
185
+ get country() {
186
+ return __classPrivateFieldGet(this, _IdentityDocument_country, "f");
187
+ }
188
+ /**
189
+ * Entidad emisora del documento (opcional).
190
+ */
191
+ get issuedBy() {
192
+ return __classPrivateFieldGet(this, _IdentityDocument_issuedBy, "f");
193
+ }
194
+ /**
195
+ * Fecha de inicio de validez (opcional).
196
+ */
197
+ get validFrom() {
198
+ return __classPrivateFieldGet(this, _IdentityDocument_validFrom, "f");
199
+ }
200
+ /**
201
+ * Fecha de fin de validez (opcional).
202
+ */
203
+ get validUntil() {
204
+ return __classPrivateFieldGet(this, _IdentityDocument_validUntil, "f");
205
+ }
206
+ /**
207
+ * Verifica si el documento de identidad tiene entidad emisora.
208
+ */
209
+ hasIssuedBy() {
210
+ return __classPrivateFieldGet(this, _IdentityDocument_issuedBy, "f") !== null;
211
+ }
212
+ /**
213
+ * Verifica si el documento de identidad tiene fechas de validez.
214
+ */
215
+ hasValidityPeriod() {
216
+ return __classPrivateFieldGet(this, _IdentityDocument_validFrom, "f") !== null || __classPrivateFieldGet(this, _IdentityDocument_validUntil, "f") !== null;
217
+ }
218
+ /**
219
+ * Verifica si el documento de identidad está actualmente válido.
220
+ */
221
+ isCurrentlyValid() {
222
+ const now = new Date();
223
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
224
+ if (__classPrivateFieldGet(this, _IdentityDocument_validFrom, "f")) {
225
+ const fromDate = IdentityDocument.parseDate(__classPrivateFieldGet(this, _IdentityDocument_validFrom, "f"));
226
+ if (today < fromDate) {
227
+ return false;
228
+ }
229
+ }
230
+ if (__classPrivateFieldGet(this, _IdentityDocument_validUntil, "f")) {
231
+ const untilDate = IdentityDocument.parseDate(__classPrivateFieldGet(this, _IdentityDocument_validUntil, "f"));
232
+ if (today > untilDate) {
233
+ return false;
234
+ }
235
+ }
236
+ return true;
237
+ }
238
+ /**
239
+ * Verifica si el documento de identidad será válido en una fecha específica.
240
+ */
241
+ isValidOnDate(date) {
242
+ const checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
243
+ if (__classPrivateFieldGet(this, _IdentityDocument_validFrom, "f")) {
244
+ const fromDate = IdentityDocument.parseDate(__classPrivateFieldGet(this, _IdentityDocument_validFrom, "f"));
245
+ if (checkDate < fromDate) {
246
+ return false;
247
+ }
248
+ }
249
+ if (__classPrivateFieldGet(this, _IdentityDocument_validUntil, "f")) {
250
+ const untilDate = IdentityDocument.parseDate(__classPrivateFieldGet(this, _IdentityDocument_validUntil, "f"));
251
+ if (checkDate > untilDate) {
252
+ return false;
253
+ }
254
+ }
255
+ return true;
256
+ }
257
+ /**
258
+ * Verifica si pertenece a un país específico.
259
+ */
260
+ belongsToCountry(countryCode) {
261
+ return __classPrivateFieldGet(this, _IdentityDocument_country, "f") === countryCode.trim().toUpperCase();
262
+ }
263
+ /**
264
+ * Verifica si es del mismo tipo que otro documento de identidad.
265
+ */
266
+ isSameType(other) {
267
+ return __classPrivateFieldGet(this, _IdentityDocument_type, "f") === __classPrivateFieldGet(other, _IdentityDocument_type, "f");
268
+ }
269
+ /**
270
+ * Compara la igualdad semántica con otro objeto IdentityDocument.
271
+ */
272
+ equals(other) {
273
+ if (!(other instanceof IdentityDocument)) {
274
+ return false;
275
+ }
276
+ return (__classPrivateFieldGet(this, _IdentityDocument_type, "f") === __classPrivateFieldGet(other, _IdentityDocument_type, "f")
277
+ && __classPrivateFieldGet(this, _IdentityDocument_number, "f") === __classPrivateFieldGet(other, _IdentityDocument_number, "f")
278
+ && __classPrivateFieldGet(this, _IdentityDocument_country, "f") === __classPrivateFieldGet(other, _IdentityDocument_country, "f")
279
+ && __classPrivateFieldGet(this, _IdentityDocument_issuedBy, "f") === __classPrivateFieldGet(other, _IdentityDocument_issuedBy, "f")
280
+ && __classPrivateFieldGet(this, _IdentityDocument_validFrom, "f") === __classPrivateFieldGet(other, _IdentityDocument_validFrom, "f")
281
+ && __classPrivateFieldGet(this, _IdentityDocument_validUntil, "f") === __classPrivateFieldGet(other, _IdentityDocument_validUntil, "f"));
282
+ }
283
+ /**
284
+ * Compara si dos documentos de identidad representan el mismo número
285
+ * independientemente de fechas de validez y entidad emisora.
286
+ */
287
+ hasSameIdentifier(other) {
288
+ if (!(other instanceof IdentityDocument)) {
289
+ return false;
290
+ }
291
+ return (__classPrivateFieldGet(this, _IdentityDocument_type, "f") === __classPrivateFieldGet(other, _IdentityDocument_type, "f")
292
+ && __classPrivateFieldGet(this, _IdentityDocument_number, "f") === __classPrivateFieldGet(other, _IdentityDocument_number, "f")
293
+ && __classPrivateFieldGet(this, _IdentityDocument_country, "f") === __classPrivateFieldGet(other, _IdentityDocument_country, "f"));
294
+ }
295
+ /**
296
+ * Convierte a representación primitiva para persistencia.
297
+ */
298
+ toPrimitives() {
299
+ return {
300
+ type: __classPrivateFieldGet(this, _IdentityDocument_type, "f"),
301
+ number: __classPrivateFieldGet(this, _IdentityDocument_number, "f"),
302
+ country: __classPrivateFieldGet(this, _IdentityDocument_country, "f"),
303
+ issuedBy: __classPrivateFieldGet(this, _IdentityDocument_issuedBy, "f"),
304
+ validFrom: __classPrivateFieldGet(this, _IdentityDocument_validFrom, "f"),
305
+ validUntil: __classPrivateFieldGet(this, _IdentityDocument_validUntil, "f"),
306
+ };
307
+ }
308
+ /**
309
+ * Representación como string.
310
+ */
311
+ toString() {
312
+ return `${__classPrivateFieldGet(this, _IdentityDocument_type, "f")}-${__classPrivateFieldGet(this, _IdentityDocument_number, "f")}-${__classPrivateFieldGet(this, _IdentityDocument_country, "f")}`;
313
+ }
314
+ /**
315
+ * Representación JSON para serialización.
316
+ */
317
+ toJSON() {
318
+ return this.toPrimitives();
319
+ }
320
+ /**
321
+ * Método de utilidad para validar completamente un IdentityDocument antes de crear la instancia.
322
+ */
323
+ static validateCompletely(value, propertyName = this.DEFAULT_PROPERTY_NAME) {
324
+ this.validateIdentityDocument(value, propertyName);
325
+ }
326
+ }
327
+ exports.IdentityDocument = IdentityDocument;
328
+ _IdentityDocument_type = new WeakMap(), _IdentityDocument_number = new WeakMap(), _IdentityDocument_country = new WeakMap(), _IdentityDocument_issuedBy = new WeakMap(), _IdentityDocument_validFrom = new WeakMap(), _IdentityDocument_validUntil = new WeakMap();
329
+ IdentityDocument.DEFAULT_PROPERTY_NAME = 'identityDocument';
330
+ // Tipos de documento de identidad válidos
331
+ IdentityDocument.VALID_TYPES = Object.values(IdentityDocumentType_1.IdentityDocumentType);
332
+ // Códigos de país válidos
333
+ IdentityDocument.VALID_COUNTRY_CODES = Object.values(CountryCode_1.CountryCode);
334
+ // Límites de longitud del número de documento (cédula, pasaporte, DNI, etc.)
335
+ IdentityDocument.MIN_NUMBER_LENGTH = 3;
336
+ IdentityDocument.MAX_NUMBER_LENGTH = 20;