{"_id":"@emerson-evolution-gym/events","name":"@emerson-evolution-gym/events","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@emerson-evolution-gym/events","version":"0.1.0","description":"Event bus and event handling utilities for Evolution Gym","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","dev":"tsc --watch","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build"},"keywords":["events","event-bus","rabbitmq","evolution-gym"],"author":{"name":"Evolution Team"},"license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/emersonbrs/evolution.git","directory":"packages/events"},"dependencies":{"@emerson-evolution-gym/types":"^0.1.0","@emerson-evolution-gym/logger":"^0.1.0","amqplib":"^0.10.9"},"devDependencies":{"typescript":"^5.3.3","@types/node":"^20.10.5","@types/amqplib":"^0.10.7"},"peerDependencies":{"amqplib":"^0.10.0"},"_id":"@emerson-evolution-gym/events@0.1.0","gitHead":"dfb38092cc2fa84e738805b9fd92b540265f556a","bugs":{"url":"https://github.com/emersonbrs/evolution/issues"},"homepage":"https://github.com/emersonbrs/evolution#readme","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-o4sB4xqe/oL1qm6vXbxhhks4oXYR4367FkedqpwVhHAvSB5rF2e8Pt5gLatKPFet8nmwV+UbQYH5y5Pw5w3dKw==","shasum":"3d70a9523fb8fff4f6dd05343266d7ca19f1858f","tarball":"https://registry.npmjs.org/@emerson-evolution-gym/events/-/events-0.1.0.tgz","fileCount":14,"unpackedSize":18773,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDs0JODQxvPD9SUHSz9ZPmtbLXhpmJorsJWY0wvraimFwIhAJxCEitXH6hKjaigQokHac9eODzeHp+U6cBcyKPvvGWV"}]},"_npmUser":{"name":"mersonsi","email":"mersonsi@gmail.com"},"directories":{},"maintainers":[{"name":"mersonsi","email":"mersonsi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/events_0.1.0_1759499965182_0.6013273334128038"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-03T13:59:25.131Z","0.1.0":"2025-10-03T13:59:25.372Z","modified":"2025-10-03T13:59:25.614Z"},"maintainers":[{"name":"mersonsi","email":"mersonsi@gmail.com"}],"description":"Event bus and event handling utilities for Evolution Gym","homepage":"https://github.com/emersonbrs/evolution#readme","keywords":["events","event-bus","rabbitmq","evolution-gym"],"repository":{"type":"git","url":"git+https://github.com/emersonbrs/evolution.git","directory":"packages/events"},"author":{"name":"Evolution Team"},"bugs":{"url":"https://github.com/emersonbrs/evolution/issues"},"license":"MIT","readme":"# @evolution-gym/events\n\nEvent bus and event handling utilities for Evolution Gym microservices using RabbitMQ.\n\n## Installation\n\n```bash\nnpm install @evolution-gym/events\n```\n\n## Usage\n\n### Initialize Event Bus\n\n```typescript\nimport { RabbitMQEventBus } from '@evolution-gym/events';\n\nconst eventBus = new RabbitMQEventBus({\n  url: process.env.RABBITMQ_URL || 'amqp://localhost',\n  exchange: 'evolution-gym-events',\n  queuePrefix: 'auth-service-'\n});\n\nawait eventBus.connect();\n```\n\n### Publish Events\n\n```typescript\nimport { EventFactory } from '@evolution-gym/events';\nimport { EventType } from '@evolution-gym/types';\n\n// Create and publish event\nconst event = EventFactory.createMemberEvent(\n  EventType.MEMBER_CREATED,\n  memberId,\n  tenantId,\n  'member-service',\n  { name: 'John Doe' }\n);\n\nawait eventBus.publish(event);\n```\n\n### Subscribe to Events\n\n```typescript\nimport { EventHandler } from '@evolution-gym/types';\nimport { EventType } from '@evolution-gym/types';\n\nclass MemberCreatedHandler implements EventHandler {\n  eventType = EventType.MEMBER_CREATED;\n\n  async handle(event) {\n    console.log('Member created:', event.data);\n    // Handle the event\n  }\n}\n\nconst handler = new MemberCreatedHandler();\nawait eventBus.subscribe(EventType.MEMBER_CREATED, handler);\n```\n\n### Event Factory Helpers\n\n```typescript\nimport { EventFactory } from '@evolution-gym/events';\nimport { EventType } from '@evolution-gym/types';\n\n// User events\nconst userEvent = EventFactory.createUserEvent(\n  EventType.USER_CREATED,\n  userId,\n  'auth-service'\n);\n\n// Member events\nconst memberEvent = EventFactory.createMemberEvent(\n  EventType.MEMBER_CHECK_IN,\n  memberId,\n  tenantId,\n  'member-service',\n  { locationId: 'gym-1' }\n);\n\n// Payment events\nconst paymentEvent = EventFactory.createPaymentEvent(\n  EventType.PAYMENT_APPROVED,\n  paymentId,\n  userId,\n  'payment-service',\n  { amount: 99.90 }\n);\n```\n\n### Graceful Shutdown\n\n```typescript\nprocess.on('SIGTERM', async () => {\n  await eventBus.close();\n  process.exit(0);\n});\n```\n\n## Configuration\n\nEnvironment variables:\n- `RABBITMQ_URL` - RabbitMQ connection URL\n\n## Event Flow\n\n1. Service publishes event to exchange\n2. Exchange routes event to queues based on routing key\n3. Consumers process events from their queues\n4. Acknowledgment ensures reliable delivery\n\n## Best Practices\n\n1. **Always handle errors** in event handlers\n2. **Use idempotency keys** to prevent duplicate processing\n3. **Keep events small** - include only necessary data\n4. **Version your events** for backward compatibility\n5. **Monitor dead letter queues** for failed events\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-af09a49d1ec940d379d7b520391f9a9d"}