legend-transactional 2.3.2 → 2.3.3

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.d.mts CHANGED
@@ -52,6 +52,10 @@ declare const availableMicroservices: {
52
52
  * Represents the "room-snapshot" microservice.
53
53
  */
54
54
  readonly RoomSnapshot: "room-snapshot";
55
+ /**
56
+ * Represents the "transactional" microservice.
57
+ */
58
+ readonly Transactional: "transactional";
55
59
  /**
56
60
  * Represents the "legend-send-email" microservice.
57
61
  */
@@ -466,14 +470,39 @@ interface EventPayload {
466
470
  bucketName: string;
467
471
  filePaths: string[];
468
472
  };
473
+ /**
474
+ * Emitted when an event is published by a microservice (audit tracking)
475
+ */
476
+ 'audit.published': {
477
+ /**
478
+ * The microservice that published the event
479
+ */
480
+ publisher_microservice: string;
481
+ /**
482
+ * The event that was published
483
+ */
484
+ published_event: string;
485
+ /**
486
+ * Timestamp when the event was published (UNIX timestamp in seconds)
487
+ */
488
+ published_at: number;
489
+ /**
490
+ * UUID v7 unique identifier for cross-event tracking
491
+ */
492
+ event_id: string;
493
+ };
469
494
  /**
470
495
  * Emitted when an event is received by a microservice before processing starts (audit tracking)
471
496
  */
472
497
  'audit.received': {
498
+ /**
499
+ * The microservice that published the original event
500
+ */
501
+ publisher_microservice: string;
473
502
  /**
474
503
  * The microservice that received the event
475
504
  */
476
- microservice: string;
505
+ receiver_microservice: string;
477
506
  /**
478
507
  * The event that was received
479
508
  */
@@ -487,18 +516,22 @@ interface EventPayload {
487
516
  */
488
517
  queue_name: string;
489
518
  /**
490
- * Optional event identifier for tracking
519
+ * UUID v7 from message properties for cross-event tracking
491
520
  */
492
- event_id?: string;
521
+ event_id: string;
493
522
  };
494
523
  /**
495
524
  * Emitted when an event is successfully processed by a microservice for audit tracking
496
525
  */
497
526
  'audit.processed': {
527
+ /**
528
+ * The microservice that published the original event
529
+ */
530
+ publisher_microservice: string;
498
531
  /**
499
532
  * The microservice that processed the event
500
533
  */
501
- microservice: string;
534
+ processor_microservice: string;
502
535
  /**
503
536
  * The original event that was processed
504
537
  */
@@ -512,18 +545,22 @@ interface EventPayload {
512
545
  */
513
546
  queue_name: string;
514
547
  /**
515
- * Optional event identifier for tracking
548
+ * UUID v7 from message properties for cross-event tracking
516
549
  */
517
- event_id?: string;
550
+ event_id: string;
518
551
  };
519
552
  /**
520
553
  * Emitted when a message is rejected/nacked and sent to dead letter queue
521
554
  */
522
555
  'audit.dead_letter': {
556
+ /**
557
+ * The microservice that published the original event
558
+ */
559
+ publisher_microservice: string;
523
560
  /**
524
561
  * The microservice that rejected the event
525
562
  */
526
- microservice: string;
563
+ rejector_microservice: string;
527
564
  /**
528
565
  * The original event that was rejected
529
566
  */
@@ -545,9 +582,9 @@ interface EventPayload {
545
582
  */
546
583
  retry_count?: number;
547
584
  /**
548
- * Optional event identifier for tracking
585
+ * UUID v7 from message properties for cross-event tracking
549
586
  */
550
- event_id?: string;
587
+ event_id: string;
551
588
  };
552
589
  }
553
590
  /**
@@ -556,6 +593,7 @@ interface EventPayload {
556
593
  declare const microserviceEvent: {
557
594
  readonly 'TEST.IMAGE': "test.image";
558
595
  readonly 'TEST.MINT': "test.mint";
596
+ readonly 'AUDIT.PUBLISHED': "audit.published";
559
597
  readonly 'AUDIT.RECEIVED': "audit.received";
560
598
  readonly 'AUDIT.PROCESSED': "audit.processed";
561
599
  readonly 'AUDIT.DEAD_LETTER': "audit.dead_letter";
@@ -694,21 +732,31 @@ declare class EventsConsumeChannel extends ConsumeChannel {
694
732
  /**
695
733
  * The microservice name that is processing the event
696
734
  */
697
- private readonly microservice;
735
+ private readonly processorMicroservice;
698
736
  /**
699
737
  * The original event that was received
700
738
  */
701
739
  private readonly processedEvent;
740
+ /**
741
+ * The unique event identifier (messageId) for tracking across audit events
742
+ */
743
+ private readonly eventId;
744
+ /**
745
+ * The microservice that originally published the event
746
+ */
747
+ private readonly publisherMicroservice;
702
748
  /**
703
749
  * Creates a new EventsConsumeChannel instance
704
750
  *
705
751
  * @param channel - The AMQP Channel
706
752
  * @param msg - The consumed message
707
753
  * @param queueName - The queue name
708
- * @param microservice - The microservice name processing the event
754
+ * @param processorMicroservice - The microservice name processing the event
709
755
  * @param processedEvent - The event type being processed
756
+ * @param eventId - Unique event identifier (messageId) for audit tracking
757
+ * @param publisherMicroservice - The microservice that originally published the event
710
758
  */
711
- constructor(channel: Channel, msg: ConsumeMessage, queueName: string, microservice: string, processedEvent: string);
759
+ constructor(channel: Channel, msg: ConsumeMessage, queueName: string, processorMicroservice: string, processedEvent: string, eventId: string, publisherMicroservice: string);
712
760
  /**
713
761
  * Acknowledges the consumed saga event/command.
714
762
  * Automatically emits audit.processed event after successful ACK.
@@ -753,6 +801,7 @@ declare const queue: {
753
801
  * Audit queue names for separate audit event types
754
802
  * @constant
755
803
  */
804
+ readonly AuditPublished: "audit_published_commands";
756
805
  readonly AuditReceived: "audit_received_commands";
757
806
  readonly AuditProcessed: "audit_processed_commands";
758
807
  readonly AuditDeadLetter: "audit_dead_letter_commands";
@@ -1035,6 +1084,15 @@ declare const rankingsCommands: {};
1035
1084
  */
1036
1085
  type RankingsCommands = (typeof rankingsCommands)[keyof typeof rankingsCommands];
1037
1086
 
1087
+ /**
1088
+ * Different commands related to the "transactional" microservice.
1089
+ */
1090
+ declare const transactionalCommands: {};
1091
+ /**
1092
+ * Available commands for the "transactional" microservice.
1093
+ */
1094
+ type TransactionalCommands = (typeof transactionalCommands)[keyof typeof transactionalCommands];
1095
+
1038
1096
  /**
1039
1097
  * A map that defines the relationship between microservices and their corresponding commands.
1040
1098
  */
@@ -1109,6 +1167,10 @@ interface CommandMap {
1109
1167
  * Represents the mapping of "legend-storage" microservice commands.
1110
1168
  */
1111
1169
  [availableMicroservices.Storage]: StorageCommands;
1170
+ /**
1171
+ * Represents the mapping of "transactional" microservice commands.
1172
+ */
1173
+ [availableMicroservices.Transactional]: TransactionalCommands;
1112
1174
  }
1113
1175
  /**
1114
1176
  * Represents a command specific to a microservice.
@@ -1591,16 +1653,11 @@ declare const getConsumeChannel: () => Promise<Channel>;
1591
1653
  */
1592
1654
  declare const closeConsumeChannel: () => Promise<void>;
1593
1655
 
1594
- /**
1595
- * Save the RabbitMQ URI for establishing a connection.
1596
- *
1597
- * @param {string} uri - The RabbitMQ URI to save.
1598
- */
1599
- declare const saveUri: (uri: string) => void;
1656
+ declare const getStoredConfig: () => TransactionalConfig<AvailableMicroservices, MicroserviceEvent>;
1600
1657
  /**
1601
1658
  * Get the RabbitMQ connection or establish a new connection if not already connected.
1602
1659
  *
1603
- * @returns {Promise<Connection>} A promise that resolves to the RabbitMQ connection.
1660
+ * @returns {Promise<ChannelModel>} A promise that resolves to the RabbitMQ connection.
1604
1661
  */
1605
1662
  declare const getRabbitMQConn: () => Promise<ChannelModel>;
1606
1663
  /**
@@ -1619,82 +1676,6 @@ declare const saveQueueForHealthCheck: (queue: string) => void;
1619
1676
  * @returns {Promise<boolean>} A promise that resolves to `true` if the connection is healthy and the queue exists, or `false` otherwise.
1620
1677
  */
1621
1678
  declare const isConnectionHealthy: () => Promise<boolean>;
1622
-
1623
- /**
1624
- * Start a global saga listener to handle incoming saga events/commands from all microservices.
1625
- *
1626
- * @param {string} url - The RabbitMQ URL to establish a connection.
1627
- *
1628
- * @returns {Promise<Emitter>} Emitter<ConsumerSagaEvents<T>> - A promise that resolves to an emitter
1629
- * for handling the saga events emitted by the specified microservice.
1630
- * @throws {Error} If the RabbitMQ URI is not initialized or there is an issue with the connection.
1631
- *
1632
- * @template T
1633
- * @example
1634
- * await prepare('amqp://localhost');
1635
- * const sagaEmitter = await startGlobalSagaListener<AvailableMicroservices>();
1636
- * // Also valid and equivalent to the above
1637
- * const g = await startGlobalSagaListener();
1638
- *
1639
- * // Listen to a single microservice saga event
1640
- * g.on(MintCommands.MintImage, async ({ channel, step }) => {
1641
- * // ... do something, ack or nack the message
1642
- * });
1643
- *
1644
- * // Listen to all microservice saga events, take notice that the event already listen above it needs to be ignored here.
1645
- * g.on('*', async (command, { step, channel }) => {
1646
- * if (command === MintCommands.MintImage) {
1647
- * // Ignore the event already listened above
1648
- * return;
1649
- * }
1650
- * // ... do something ack or nack if there are commands that are not handled
1651
- * });
1652
- *
1653
- * // When not needed anymore, you can close the RabbitMQ connection
1654
- * await stopRabbitMQ();
1655
- * @see stopRabbitMQ
1656
- * @see prepare
1657
- * @see startSaga
1658
- * @see connectToSagaCommandEmitter
1659
- * @see commenceSagaListener
1660
- */
1661
- declare const startGlobalSagaStepListener: <T extends AvailableMicroservices>(url: string) => Promise<Emitter<SagaConsumeSagaEvents<T>>>;
1662
- /**
1663
- * Start a saga listener to handle incoming **commence saga events**
1664
- *
1665
- * @param {string} url - The RabbitMQ URL to establish a connection.
1666
- *
1667
- * @returns {Promise<Emitter>} Emitter<ConsumerCommenceSaga<T>> - A promise that resolves to an emitter
1668
- * for handling the saga emitted to commence a saga.
1669
- * @throws {Error} If the RabbitMQ URI is not initialized or there is an issue with the connection.
1670
- *
1671
- * @example
1672
- * await prepare('amqp://localhost');
1673
- * const c = await commenceSagaListener();
1674
- *
1675
- * // Listen to a single saga commence event
1676
- * c.on(sagaTitle.RechargeBalance, async ({ saga, channel }) => {
1677
- * // ... start the saga
1678
- * });
1679
- *
1680
- * // Listen to all saga events, take notice that the event already listen above it needs to be ignored here.
1681
- * c.on('*', async (sagaTitle, { saga, channel }) => {
1682
- * if (sagaTitle === sagaTitle.RechargeBalance) {
1683
- * // Ignore the event already listened above
1684
- * return;
1685
- * }
1686
- * // ... start the sagas
1687
- * });
1688
- *
1689
- * // When not needed anymore, you can close the RabbitMQ connection
1690
- * await stopRabbitMQ();
1691
- * @see stopRabbitMQ
1692
- * @see prepare
1693
- * @see startSaga
1694
- * @see connectToSagaCommandEmitter
1695
- * @see startGlobalSagaStepListener
1696
- */
1697
- declare const commenceSagaListener: <U extends SagaTitle>(url: string) => Promise<Emitter<CommenceSagaEvents<U>>>;
1698
1679
  /**
1699
1680
  * A class to connect to the saga orchestration system and handle incoming saga events/commands.
1700
1681
  * @template T - `AvailableMicroservices` enum.
@@ -1750,80 +1731,6 @@ interface TransactionalConfig<T extends AvailableMicroservices, U extends Micros
1750
1731
  microservice: T;
1751
1732
  events: U[];
1752
1733
  }
1753
- /**
1754
- * Connects to a specific microservice's saga command emitter to handle incoming saga events/commands.
1755
- *
1756
- * @param [config] - Configuration for receiving saga commands to a specific microservice and handle incoming saga commands.
1757
- * @returns {Promise<Emitter>} Emitter<MicroserviceConsumeSagaEvents<T>> - A promise that resolves to an emitter for handling the saga commands
1758
- * emitted to a specified microservice.
1759
- * @throws {Error} If the RabbitMQ URI is not initialized or there is an issue with the connection.
1760
- *
1761
- * @template T - The specific microservice to connect to (e.g., 'image', 'payment'). Must be one of the types defined in the `AvailableMicroservices` enum.
1762
- *
1763
- * @example
1764
- * // Establish a connection and connect to the 'image' microservice's saga command emitter
1765
- * await prepare('amqp://localhost');
1766
- * const e = await connectToSagaCommandEmitter(AvailableMicroservices.Image);
1767
- *
1768
- * // Listen for 'image' microservice saga events/commands
1769
- * e.on(ImageCommands.CreateImage, async ({ channel, sagaId, payload }) => {
1770
- * // Handle the 'create_image' saga event/command for the 'image' microservice, ack or nack the message
1771
- * });
1772
- *
1773
- * // Listen to all commands/events emitted by the 'image' microservice or use a global pattern, take notice that the events already listen above it needs to be ignored here.
1774
- * e.on('*', async (command, { channel, sagaId, payload }) => {
1775
- * if (command === ImageCommands.CreateImage) {
1776
- * // Ignore the event already listened above
1777
- * return;
1778
- * }
1779
- * // ... do something ack or nack if there are commands that are not handled
1780
- * });
1781
- *
1782
- * // When not needed anymore, you can close the RabbitMQ connection
1783
- * await stopRabbitMQ();
1784
- * @see stopRabbitMQ
1785
- * @see startTransactional
1786
- */
1787
- declare const connectToSagaCommandEmitter: <T extends AvailableMicroservices>(config: TransactionalConfig<T, MicroserviceEvent>) => Promise<Emitter<MicroserviceConsumeSagaEvents<T>>>;
1788
- /**
1789
- * Connects to specific events emitted by a particular microservice.
1790
- *
1791
- * This allows you to listen for and handle specific events of interest, filtering out other events the microservice might emit.
1792
- *
1793
- * @template T - The specific microservice to connect to (e.g., 'image', 'payment'). Must be one of the types defined in the `AvailableMicroservices` enum.
1794
- * @template U - The type of event to listen for. Must be one of the types defined in the `MicroserviceEvent` enum.
1795
- *
1796
- * @param {TransactionalConfig<T, U>} config - Configuration for receiving saga commands to a specific microservice and handle incoming subscription events.
1797
- * @returns {Promise<Emitter>} Emitter<MicroserviceConsumeEvents<U>> - A promise that resolves to an emitter, providing a way to listen to the specified events.
1798
- * @async
1799
- *
1800
- * @example
1801
- * const url = 'amqp://localhost';
1802
- * await prepare(url);
1803
- * // Connect to the 'image' microservice and listen for 'ImageCreated' and 'ImageDeleted' events
1804
- * const emitter = await connectToEvents(AvailableMicroservices.Image, [MicroserviceEvent.ImageCreated, MicroserviceEvent.ImageDeleted]);
1805
- *
1806
- * // Handle 'ImageCreated' events
1807
- * emitter.on(MicroserviceEvent.ImageCreated, ({ channel, payload }) => {
1808
- * // Process the image creation payload
1809
- * });
1810
- *
1811
- * // Handle 'ImageDeleted' events
1812
- * emitter.on(MicroserviceEvent.ImageDeleted, ({ channel, payload }) => {
1813
- * // Process the image deletion payload
1814
- * });
1815
- *
1816
- * // When not needed anymore, you can close the RabbitMQ connection
1817
- * await stopRabbitMQ();
1818
- *
1819
- * @see stopRabbitMQ
1820
- * @see prepare
1821
- * @see connectToSagaCommandEmitter
1822
- * @see startTransactional
1823
- * @see AvailableMicroservices
1824
- * @see MicroserviceEvent
1825
- */
1826
- declare const connectToEvents: <T extends AvailableMicroservices, U extends MicroserviceEvent>(config: TransactionalConfig<T, U>) => Promise<Emitter<MicroserviceConsumeEvents<U>>>;
1827
1734
  /**
1828
1735
  * A class to connect to a specific microservice's saga command emitter and handle incoming saga events/commands.
1829
1736
  * @template T - The specific microservice to connect to (e.g., 'image', 'payment'). Must be one of the types defined in the `AvailableMicroservices` enum.
@@ -1943,4 +1850,4 @@ declare const getEventObject: (event: MicroserviceEvent) => {
1943
1850
  */
1944
1851
  declare function extractMicroserviceFromQueue(queueName: string): string;
1945
1852
 
1946
- export { type AuditEdaCommands, type AuthCommands, type AvailableMicroservices, type BlockchainCommands, type CoinsCommands, type CommandMap, type CommenceSaga, type CommenceSagaEvents, type CommenceSagaHandler, type CompletedRanking, type EventPayload, EventsConsumeChannel, type EventsHandler, type Exchange, type Gender, MAX_NACK_RETRIES, MAX_OCCURRENCE, type MicroserviceCommand, MicroserviceConsumeChannel, type MicroserviceConsumeEvents, type MicroserviceConsumeSagaEvents, type MicroserviceEvent, type MicroserviceHandler, NACKING_DELAY_MS, type Nack, type PaymentEmailType, PaymentEmailTypes, type QueueConsumerProps, type RankingWinners, type RankingsCommands, type RapidMessagingCommands, type Room, type RoomCreatorCommands, type RoomInventoryCommands, type RoomSnapshotCommands, type RoomType, RoomTypes, Saga, SagaCommenceConsumeChannel, type SagaCommencePayload, SagaConsumeChannel, type SagaConsumeSagaEvents, type SagaHandler, type SagaStep, type SagaStepDefaults, type SagaTitle, type SendEmailCommands, type ShowcaseCommands, type SocialCommands, type SocialMediaRoomsCommands, type SocialUser, type Status, type StorageCommands, type TestImageCommands, type TestMintCommands, Transactional, type TransactionalConfig, type UserLocation, auditEdaCommands, authCommands, availableMicroservices, blockchainCommands, closeConsumeChannel, closeRabbitMQConn, closeSendChannel, coinsCommands, commenceSaga, commenceSagaConsumeCallback, commenceSagaListener, connectToEvents, connectToSagaCommandEmitter, consume, createAuditLoggingResources, createConsumers, createHeaderConsumers, eventCallback, exchange, extractMicroserviceFromQueue, fibonacci, gender, getConsumeChannel, getEventKey, getEventObject, getQueueConsumer, getQueueName, getRabbitMQConn, getSendChannel, isConnectionHealthy, microserviceEvent, nodeDataDefaults, publishEvent, queue, rankingsCommands, rapidMessagingCommands, roomCreatorCommands, roomInventoryCommands, roomSnapshotCommands, sagaConsumeCallback, sagaStepCallback, sagaTitle, saveQueueForHealthCheck, saveUri, sendEmailCommands, sendToQueue, showcaseCommands, socialCommands, socialMediaRoomsCommands, startGlobalSagaStepListener, status, stopRabbitMQ, storageCommands, testImageCommands, testMintCommands };
1853
+ export { type AuditEdaCommands, type AuthCommands, type AvailableMicroservices, type BlockchainCommands, type CoinsCommands, type CommandMap, type CommenceSaga, type CommenceSagaEvents, type CommenceSagaHandler, type CompletedRanking, type EventPayload, EventsConsumeChannel, type EventsHandler, type Exchange, type Gender, MAX_NACK_RETRIES, MAX_OCCURRENCE, type MicroserviceCommand, MicroserviceConsumeChannel, type MicroserviceConsumeEvents, type MicroserviceConsumeSagaEvents, type MicroserviceEvent, type MicroserviceHandler, NACKING_DELAY_MS, type Nack, type PaymentEmailType, PaymentEmailTypes, type QueueConsumerProps, type RankingWinners, type RankingsCommands, type RapidMessagingCommands, type Room, type RoomCreatorCommands, type RoomInventoryCommands, type RoomSnapshotCommands, type RoomType, RoomTypes, Saga, SagaCommenceConsumeChannel, type SagaCommencePayload, SagaConsumeChannel, type SagaConsumeSagaEvents, type SagaHandler, type SagaStep, type SagaStepDefaults, type SagaTitle, type SendEmailCommands, type ShowcaseCommands, type SocialCommands, type SocialMediaRoomsCommands, type SocialUser, type Status, type StorageCommands, type TestImageCommands, type TestMintCommands, Transactional, type TransactionalCommands, type TransactionalConfig, type UserLocation, auditEdaCommands, authCommands, availableMicroservices, blockchainCommands, closeConsumeChannel, closeRabbitMQConn, closeSendChannel, coinsCommands, commenceSaga, commenceSagaConsumeCallback, consume, createAuditLoggingResources, createConsumers, createHeaderConsumers, eventCallback, exchange, extractMicroserviceFromQueue, fibonacci, gender, getConsumeChannel, getEventKey, getEventObject, getQueueConsumer, getQueueName, getRabbitMQConn, getSendChannel, getStoredConfig, isConnectionHealthy, microserviceEvent, nodeDataDefaults, publishEvent, queue, rankingsCommands, rapidMessagingCommands, roomCreatorCommands, roomInventoryCommands, roomSnapshotCommands, sagaConsumeCallback, sagaStepCallback, sagaTitle, saveQueueForHealthCheck, sendEmailCommands, sendToQueue, showcaseCommands, socialCommands, socialMediaRoomsCommands, status, stopRabbitMQ, storageCommands, testImageCommands, testMintCommands, transactionalCommands };