wsp-ms-core 1.0.57 → 1.0.58

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.cjs CHANGED
@@ -37,8 +37,10 @@ __export(src_exports, {
37
37
  DomainEntity: () => DomainEntity,
38
38
  DomainError: () => DomainError,
39
39
  DomainEvent: () => DomainEvent,
40
+ DomainEventStatus: () => DomainEventStatus,
40
41
  Email: () => Email,
41
42
  ErrorManager: () => ErrorManager,
43
+ EventBus: () => EventBus,
42
44
  ExchangeRates: () => ExchangeRates,
43
45
  FatalError: () => FatalError,
44
46
  HttpHealthCheckController: () => HttpHealthCheckController,
@@ -223,17 +225,186 @@ var DomainError = class extends Error {
223
225
  }
224
226
  };
225
227
 
228
+ // src/domain/errors/InternalError.ts
229
+ var InternalError = class extends DomainError {
230
+ constructor(type, message = "") {
231
+ super(type, message);
232
+ }
233
+ };
234
+
235
+ // src/domain/value-objects/UUID.ts
236
+ var crypto = __toESM(require("crypto"));
237
+ var _UUID = class _UUID extends ValueObject {
238
+ constructor(value) {
239
+ super(value);
240
+ }
241
+ validate(uuid) {
242
+ if (!_UUID.isValid(uuid)) {
243
+ throw new InternalError(`Invalid uuid <${uuid}>`);
244
+ }
245
+ }
246
+ toPrimitives() {
247
+ return { value: this.value };
248
+ }
249
+ static create(uuid) {
250
+ return new _UUID(uuid != null ? uuid : crypto.randomUUID());
251
+ }
252
+ static version(uuid) {
253
+ const m = /^[0-9a-f]{8}-[0-9a-f]{4}-([1-8])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.exec(uuid);
254
+ return m ? Number(m[1]) : void 0;
255
+ }
256
+ static isNil(uuid) {
257
+ return /^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(uuid);
258
+ }
259
+ static isRFCStyle(uuid) {
260
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
261
+ }
262
+ static isValid(uuid, opts = {}) {
263
+ var _a, _b;
264
+ const allowed = (_a = opts.allowedVersions) != null ? _a : [1, 2, 3, 4, 5, 6, 7, 8];
265
+ const allowNil = (_b = opts.allowNil) != null ? _b : false;
266
+ if (allowNil && _UUID.isNil(uuid))
267
+ return true;
268
+ if (!_UUID.isRFCStyle(uuid))
269
+ return false;
270
+ const v = _UUID.version(uuid);
271
+ return !!v && allowed.includes(v);
272
+ }
273
+ };
274
+ _UUID.NIL = "00000000-0000-0000-0000-000000000000";
275
+ var UUID = _UUID;
276
+
277
+ // src/domain/value-objects/DomainEventStatus.ts
278
+ var _DomainEventStatus = class _DomainEventStatus extends ValueObject {
279
+ constructor(status) {
280
+ super(status.trim().toUpperCase());
281
+ }
282
+ validate(value) {
283
+ if (!_DomainEventStatus.SUPPORTED.includes(value)) {
284
+ throw new InternalError(`Domain event status <${value}> is not supported`);
285
+ }
286
+ }
287
+ toPrimitives() {
288
+ return void 0;
289
+ }
290
+ static create(status) {
291
+ return new _DomainEventStatus(status);
292
+ }
293
+ };
294
+ _DomainEventStatus.SUPPORTED = ["PENDING", "PROCESSING", "PROCESSED", "FAILED", "DEAD"];
295
+ _DomainEventStatus.PENDING = new _DomainEventStatus("PENDING");
296
+ _DomainEventStatus.PROCESSING = new _DomainEventStatus("PROCESSING");
297
+ _DomainEventStatus.PROCESSED = new _DomainEventStatus("PROCESSED");
298
+ _DomainEventStatus.FAILED = new _DomainEventStatus("FAILED");
299
+ _DomainEventStatus.DEAD = new _DomainEventStatus("DEAD");
300
+ var DomainEventStatus = _DomainEventStatus;
301
+
226
302
  // src/domain/contracts/DomainEvent.ts
227
- var DomainEvent = class {
228
- constructor(payload) {
303
+ var DomainEvent = class _DomainEvent {
304
+ constructor(eventUuid, tenantUuid, aggregateUuid, aggregateType, eventType, topic, payload, status, attempts, errorMessage, publishedAt, lastAttempt, createdAt) {
305
+ this._eventUuid = eventUuid;
306
+ this._tenantUuid = tenantUuid;
307
+ this._aggregateUuid = aggregateUuid;
308
+ this._aggregateType = aggregateType;
309
+ this._eventType = eventType;
310
+ this._topic = topic;
229
311
  this._payload = payload;
230
- this._occurredAt = DateTime.create();
312
+ this._status = status;
313
+ this._attempts = 0;
314
+ this._errorMessage = errorMessage;
315
+ this._publishedAt = publishedAt;
316
+ this._lastAttempt = lastAttempt;
317
+ this._createdAt = createdAt;
318
+ }
319
+ get eventUuid() {
320
+ return this._eventUuid;
321
+ }
322
+ get tenantUuid() {
323
+ return this._tenantUuid;
324
+ }
325
+ get aggregateUuid() {
326
+ return this._aggregateUuid;
327
+ }
328
+ get aggregateType() {
329
+ return this._aggregateType;
330
+ }
331
+ get eventType() {
332
+ return this._eventType;
333
+ }
334
+ get topic() {
335
+ return this._topic;
231
336
  }
232
337
  get payload() {
233
338
  return this._payload;
234
339
  }
235
- get occurredAt() {
236
- return this._occurredAt;
340
+ get status() {
341
+ return this._status;
342
+ }
343
+ get attempts() {
344
+ return this._attempts;
345
+ }
346
+ get errorMessage() {
347
+ return this._errorMessage;
348
+ }
349
+ get publishedAt() {
350
+ return this._publishedAt;
351
+ }
352
+ get lastAttempt() {
353
+ return this._lastAttempt;
354
+ }
355
+ get createdAt() {
356
+ return this._createdAt;
357
+ }
358
+ incrementAttempts() {
359
+ this._attempts++;
360
+ this._lastAttempt = DateTime.now();
361
+ }
362
+ markProcessed() {
363
+ this._status = DomainEventStatus.PROCESSED;
364
+ this._publishedAt = DateTime.now();
365
+ }
366
+ markProcessing() {
367
+ this._status = DomainEventStatus.PROCESSING;
368
+ }
369
+ markWithError(error) {
370
+ this._status = DomainEventStatus.FAILED;
371
+ this._errorMessage = error;
372
+ }
373
+ toPrimitives() {
374
+ var _a, _b, _c, _d, _e;
375
+ return {
376
+ eventUuid: this.eventUuid.value,
377
+ tenantUuid: this.tenantUuid.value,
378
+ aggregateUuid: this.aggregateUuid.value,
379
+ aggregateType: this.aggregateType,
380
+ eventType: this.eventType,
381
+ topic: this.topic,
382
+ payload: this.payload,
383
+ status: this.status.value,
384
+ attempts: this.attempts,
385
+ errorMessage: (_a = this.errorMessage) != null ? _a : void 0,
386
+ publishedAt: (_c = (_b = this.publishedAt) == null ? void 0 : _b.value) != null ? _c : void 0,
387
+ lastAttempt: (_e = (_d = this.lastAttempt) == null ? void 0 : _d.value) != null ? _e : void 0,
388
+ createdAt: this.createdAt.value
389
+ };
390
+ }
391
+ static reconstitute(data) {
392
+ var _a;
393
+ return new _DomainEvent(
394
+ UUID.create(data.event_uuid),
395
+ UUID.create(data.tenant_uuid),
396
+ UUID.create(data.aggregate_uuid),
397
+ String(data.aggregate_type),
398
+ String(data.event_type),
399
+ String(data.topic),
400
+ String(data.payload),
401
+ DomainEventStatus.create(data.status),
402
+ Number(data.attempts),
403
+ (_a = data.error_message) != null ? _a : void 0,
404
+ data.published_at ? DateTime.create(data.published_at) : void 0,
405
+ data.last_attempt ? DateTime.create(data.last_attempt) : void 0,
406
+ data.created_at ? DateTime.create(data.created_at) : void 0
407
+ );
237
408
  }
238
409
  };
239
410
 
@@ -251,13 +422,6 @@ var FatalError = class extends DomainError {
251
422
  }
252
423
  };
253
424
 
254
- // src/domain/errors/InternalError.ts
255
- var InternalError = class extends DomainError {
256
- constructor(type, message = "") {
257
- super(type, message);
258
- }
259
- };
260
-
261
425
  // src/domain/errors/UsageError.ts
262
426
  var UsageError = class extends DomainError {
263
427
  constructor(type, vars = {}) {
@@ -452,93 +616,6 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
452
616
  _Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
453
617
  var Language = _Language;
454
618
 
455
- // src/domain/value-objects/payments/PaymentGateway.ts
456
- var _PaymentGateway = class _PaymentGateway extends ValueObject {
457
- constructor(gateway) {
458
- super(gateway);
459
- }
460
- validate(value) {
461
- if (!_PaymentGateway.SUPPORTED.includes(value)) {
462
- throw new InternalError(`Payment gateway <${value}> is not supported`);
463
- }
464
- }
465
- isExternal() {
466
- return _PaymentGateway.EXTERNALS.includes(this.value);
467
- }
468
- toPrimitives() {
469
- return { value: this.value };
470
- }
471
- static create(gateway) {
472
- return new _PaymentGateway(gateway.trim().toUpperCase());
473
- }
474
- };
475
- _PaymentGateway.SUPPORTED = [
476
- "MERCADOPAGO",
477
- "HANDY",
478
- "WONA_DEBIT",
479
- "WONA_CARD",
480
- "WONA_CASH",
481
- "WONA_TRANSFER",
482
- "WONA_MERCADOPAGO"
483
- ];
484
- _PaymentGateway.EXTERNALS = ["MERCADOPAGO", "STRIPE"];
485
- _PaymentGateway.MERCADOPAGO = new _PaymentGateway("MERCADOPAGO");
486
- _PaymentGateway.HANDY = new _PaymentGateway("HANDY");
487
- _PaymentGateway.WONA_DEBIT = new _PaymentGateway("WONA_DEBIT");
488
- _PaymentGateway.WONA_CARD = new _PaymentGateway("WONA_CARD");
489
- _PaymentGateway.WONA_CASH = new _PaymentGateway("WONA_CASH");
490
- _PaymentGateway.WONA_TRANSFER = new _PaymentGateway("WONA_TRANSFER");
491
- _PaymentGateway.WONA_MERCADOPAGO = new _PaymentGateway("WONA_MERCADOPAGO");
492
- var PaymentGateway = _PaymentGateway;
493
-
494
- // src/domain/value-objects/payments/PaymentStatus.ts
495
- var _PaymentStatus = class _PaymentStatus extends ValueObject {
496
- constructor(status) {
497
- super(status);
498
- }
499
- validate(status) {
500
- if (!_PaymentStatus.SUPPORTED.includes(status)) {
501
- throw new InternalError(`Payment status <${status}> is not supported`);
502
- }
503
- }
504
- get isDone() {
505
- return this.value === "DONE";
506
- }
507
- get isPending() {
508
- return this.value === "PENDING";
509
- }
510
- get isInProgress() {
511
- return this.value === "IN_PROGRESS";
512
- }
513
- get isFailed() {
514
- return this.value === "FAILED";
515
- }
516
- get isCanceled() {
517
- return this.value === "CANCELED";
518
- }
519
- get isHold() {
520
- return this.value === "HOLD";
521
- }
522
- get isRefunded() {
523
- return this.value === "REFUNDED";
524
- }
525
- toPrimitives() {
526
- return { value: this.value };
527
- }
528
- static create(gateway) {
529
- return new _PaymentStatus(gateway.trim().toUpperCase());
530
- }
531
- };
532
- _PaymentStatus.SUPPORTED = ["DONE", "PENDING", "FAILED", "CANCELED", "HOLD", "REFUNDED", "IN_PROGRESS"];
533
- _PaymentStatus.DONE = new _PaymentStatus("DONE");
534
- _PaymentStatus.PENDING = new _PaymentStatus("PENDING");
535
- _PaymentStatus.IN_PROGRESS = new _PaymentStatus("IN_PROGRESS");
536
- _PaymentStatus.FAILED = new _PaymentStatus("FAILED");
537
- _PaymentStatus.CANCELED = new _PaymentStatus("CANCELED");
538
- _PaymentStatus.HOLD = new _PaymentStatus("HOLD");
539
- _PaymentStatus.REFUNDED = new _PaymentStatus("REFUNDED");
540
- var PaymentStatus = _PaymentStatus;
541
-
542
619
  // src/utils/StringVars.ts
543
620
  var StringVars = class {
544
621
  static parse(str, ob) {
@@ -694,47 +771,107 @@ _Price.MIN_AMOUNT = -1e6;
694
771
  _Price.MAX_AMOUNT = 1e9;
695
772
  var Price = _Price;
696
773
 
697
- // src/domain/value-objects/UUID.ts
698
- var crypto = __toESM(require("crypto"));
699
- var _UUID = class _UUID extends ValueObject {
700
- constructor(value) {
701
- super(value);
774
+ // src/domain/value-objects/payments/PaymentGateway.ts
775
+ var _PaymentGateway = class _PaymentGateway extends ValueObject {
776
+ constructor(gateway) {
777
+ super(gateway);
702
778
  }
703
- validate(uuid) {
704
- if (!_UUID.isValid(uuid)) {
705
- throw new InternalError(`Invalid uuid <${uuid}>`);
779
+ validate(value) {
780
+ if (!_PaymentGateway.SUPPORTED.includes(value)) {
781
+ throw new InternalError(`Payment gateway <${value}> is not supported`);
706
782
  }
707
783
  }
784
+ isExternal() {
785
+ return _PaymentGateway.EXTERNALS.includes(this.value);
786
+ }
708
787
  toPrimitives() {
709
788
  return { value: this.value };
710
789
  }
711
- static create(uuid) {
712
- return new _UUID(uuid != null ? uuid : crypto.randomUUID());
790
+ static create(gateway) {
791
+ return new _PaymentGateway(gateway.trim().toUpperCase());
713
792
  }
714
- static version(uuid) {
715
- const m = /^[0-9a-f]{8}-[0-9a-f]{4}-([1-8])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.exec(uuid);
716
- return m ? Number(m[1]) : void 0;
793
+ };
794
+ _PaymentGateway.SUPPORTED = [
795
+ "MERCADOPAGO",
796
+ "HANDY",
797
+ "WONA_DEBIT",
798
+ "WONA_CARD",
799
+ "WONA_CASH",
800
+ "WONA_TRANSFER",
801
+ "WONA_MERCADOPAGO"
802
+ ];
803
+ _PaymentGateway.EXTERNALS = ["MERCADOPAGO", "STRIPE"];
804
+ _PaymentGateway.MERCADOPAGO = new _PaymentGateway("MERCADOPAGO");
805
+ _PaymentGateway.HANDY = new _PaymentGateway("HANDY");
806
+ _PaymentGateway.WONA_DEBIT = new _PaymentGateway("WONA_DEBIT");
807
+ _PaymentGateway.WONA_CARD = new _PaymentGateway("WONA_CARD");
808
+ _PaymentGateway.WONA_CASH = new _PaymentGateway("WONA_CASH");
809
+ _PaymentGateway.WONA_TRANSFER = new _PaymentGateway("WONA_TRANSFER");
810
+ _PaymentGateway.WONA_MERCADOPAGO = new _PaymentGateway("WONA_MERCADOPAGO");
811
+ var PaymentGateway = _PaymentGateway;
812
+
813
+ // src/domain/value-objects/payments/PaymentStatus.ts
814
+ var _PaymentStatus = class _PaymentStatus extends ValueObject {
815
+ constructor(status) {
816
+ super(status);
717
817
  }
718
- static isNil(uuid) {
719
- return /^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(uuid);
818
+ validate(status) {
819
+ if (!_PaymentStatus.SUPPORTED.includes(status)) {
820
+ throw new InternalError(`Payment status <${status}> is not supported`);
821
+ }
720
822
  }
721
- static isRFCStyle(uuid) {
722
- return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
823
+ get isDone() {
824
+ return this.value === "DONE";
723
825
  }
724
- static isValid(uuid, opts = {}) {
725
- var _a, _b;
726
- const allowed = (_a = opts.allowedVersions) != null ? _a : [1, 2, 3, 4, 5, 6, 7, 8];
727
- const allowNil = (_b = opts.allowNil) != null ? _b : false;
728
- if (allowNil && _UUID.isNil(uuid))
729
- return true;
730
- if (!_UUID.isRFCStyle(uuid))
731
- return false;
732
- const v = _UUID.version(uuid);
733
- return !!v && allowed.includes(v);
826
+ get isPending() {
827
+ return this.value === "PENDING";
828
+ }
829
+ get isInProgress() {
830
+ return this.value === "IN_PROGRESS";
831
+ }
832
+ get isFailed() {
833
+ return this.value === "FAILED";
834
+ }
835
+ get isCanceled() {
836
+ return this.value === "CANCELED";
837
+ }
838
+ get isHold() {
839
+ return this.value === "HOLD";
840
+ }
841
+ get isRefunded() {
842
+ return this.value === "REFUNDED";
843
+ }
844
+ toPrimitives() {
845
+ return { value: this.value };
846
+ }
847
+ static create(gateway) {
848
+ return new _PaymentStatus(gateway.trim().toUpperCase());
849
+ }
850
+ };
851
+ _PaymentStatus.SUPPORTED = ["DONE", "PENDING", "FAILED", "CANCELED", "HOLD", "REFUNDED", "IN_PROGRESS"];
852
+ _PaymentStatus.DONE = new _PaymentStatus("DONE");
853
+ _PaymentStatus.PENDING = new _PaymentStatus("PENDING");
854
+ _PaymentStatus.IN_PROGRESS = new _PaymentStatus("IN_PROGRESS");
855
+ _PaymentStatus.FAILED = new _PaymentStatus("FAILED");
856
+ _PaymentStatus.CANCELED = new _PaymentStatus("CANCELED");
857
+ _PaymentStatus.HOLD = new _PaymentStatus("HOLD");
858
+ _PaymentStatus.REFUNDED = new _PaymentStatus("REFUNDED");
859
+ var PaymentStatus = _PaymentStatus;
860
+
861
+ // src/application/event-bus/EventBus.ts
862
+ var EventBus = class {
863
+ constructor(repository) {
864
+ this.repository = repository;
865
+ }
866
+ async publish(event) {
867
+ await this.repository.create(event);
868
+ }
869
+ async publishMany(events) {
870
+ for (let event of events) {
871
+ await this.publish(event);
872
+ }
734
873
  }
735
874
  };
736
- _UUID.NIL = "00000000-0000-0000-0000-000000000000";
737
- var UUID = _UUID;
738
875
 
739
876
  // src/application/unit-of-work/BasicUnitOfWork.ts
740
877
  var BasicUnitOfWork = class {
@@ -1060,8 +1197,10 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
1060
1197
  DomainEntity,
1061
1198
  DomainError,
1062
1199
  DomainEvent,
1200
+ DomainEventStatus,
1063
1201
  Email,
1064
1202
  ErrorManager,
1203
+ EventBus,
1065
1204
  ExchangeRates,
1066
1205
  FatalError,
1067
1206
  HttpHealthCheckController,