{"_id":"@adamhancock/nestjs-eventhubs","name":"@adamhancock/nestjs-eventhubs","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@adamhancock/nestjs-eventhubs","version":"0.1.0","description":"NestJS module for Azure Event Hubs integration","author":{"name":"Adam Hancock"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/adamhancock/nestjs-libs.git"},"keywords":["nestjs","azure","event-hubs","eventhubs"],"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"pnpm exec tsc -p tsconfig.lib.json","prepublishOnly":"pnpm run build"},"peerDependencies":{"@azure/event-hubs":"^5.12.2","@nestjs/common":"^10.0.0","@nestjs/core":"^10.0.0","@nestjs/config":"^3.3.0","reflect-metadata":"^0.2.0","rxjs":"^7.8.1"},"devDependencies":{"typescript":"^5.1.3"},"publishConfig":{"access":"public"},"_id":"@adamhancock/nestjs-eventhubs@0.1.0","gitHead":"bfc0b19f680c00ff43d2e03c15b838fdb1ce591c","bugs":{"url":"https://github.com/adamhancock/nestjs-libs/issues"},"homepage":"https://github.com/adamhancock/nestjs-libs#readme","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-gBOn7lf4ELYu+bTSYzErr1sdQn4L22spXVBGUJkJJn1ZM1HBCohaiOcVfwYInEe57resjSO4jVHRYET+Y7Anlw==","shasum":"8f48e5bb4e2b6686ad895f919ee911834a7adacd","tarball":"https://registry.npmjs.org/@adamhancock/nestjs-eventhubs/-/nestjs-eventhubs-0.1.0.tgz","fileCount":17,"unpackedSize":30038,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFF3GBwSapnuhdcvXVzdwVNgd/KVZHPdvwGahCLrxeClAiAkXdgZnnfGSiFi9whjZrcZ4lqQeEWjIM5s/whfkOuYqQ=="}]},"_npmUser":{"name":"adam1571","email":"adammhancock@gmail.com"},"directories":{},"maintainers":[{"name":"adam1571","email":"adammhancock@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nestjs-eventhubs_0.1.0_1734597091543_0.45178581730596257"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-19T08:31:31.465Z","0.1.0":"2024-12-19T08:31:31.713Z","modified":"2024-12-19T08:31:32.017Z"},"maintainers":[{"name":"adam1571","email":"adammhancock@gmail.com"}],"description":"NestJS module for Azure Event Hubs integration","homepage":"https://github.com/adamhancock/nestjs-libs#readme","keywords":["nestjs","azure","event-hubs","eventhubs"],"repository":{"type":"git","url":"git+https://github.com/adamhancock/nestjs-libs.git"},"author":{"name":"Adam Hancock"},"bugs":{"url":"https://github.com/adamhancock/nestjs-libs/issues"},"license":"MIT","readme":"# @adamhancock/nestjs-eventhubs\n\nA NestJS module for Azure Event Hubs integration.\n\n## Installation\n\n```bash\nnpm install @adamhancock/nestjs-eventhubs\n# or\nyarn add @adamhancock/nestjs-eventhubs\n# or\npnpm add @adamhancock/nestjs-eventhubs\n```\n\n## Local Development\n\nTo use this library locally in another project, you have two options:\n\n### Option 1: Using pnpm link\n\n1. In the library directory:\n\n```bash\ncd libs/nestjs-eventhubs\npnpm link --global\n```\n\n2. In your project directory:\n\n```bash\npnpm link --global @adamhancock/nestjs-eventhubs\n```\n\n### Option 2: Direct path in package.json\n\nAdd the library directly to your project's package.json:\n\n```json\n{\n  \"dependencies\": {\n    \"@adamhancock/nestjs-eventhubs\": \"file:/path/to/nestjs-libs/libs/nestjs-eventhubs\"\n  }\n}\n```\n\nThen run:\n\n```bash\npnpm install\n```\n\n## Description\n\nThis module provides integration between NestJS applications and Azure Event Hubs. It allows you to easily work with Azure Event Hubs in your NestJS applications using decorators for publishing and subscribing to events.\n\n## Configuration\n\nYou can configure the module using either static or async configuration:\n\n### Static Configuration\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { EventHubModule } from '@adamhancock/nestjs-eventhubs';\n\n@Module({\n  imports: [\n    EventHubModule.forRoot({\n      connectionString: 'your-eventhubs-connection-string',\n      eventHubName: 'your-eventhub-name', // optional if included in connection string\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n### Async Configuration\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport { EventHubModule } from '@adamhancock/nestjs-eventhubs';\n\n@Module({\n  imports: [\n    ConfigModule.forRoot(),\n    EventHubModule.forRootAsync({\n      imports: [ConfigModule],\n      useFactory: (configService: ConfigService) => ({\n        connectionString: configService.get('EVENTHUB_CONNECTION_STRING'),\n        eventHubName: configService.get('EVENTHUB_NAME'),\n      }),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n## Usage\n\n### Publishing Events\n\nUse the `@EventHubPublish` decorator to mark methods that should publish their return value to Event Hubs:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { EventHubPublish } from '@adamhancock/nestjs-eventhubs';\n\n@Injectable()\nexport class UserService {\n  @EventHubPublish({\n    routingKey: 'user.created',\n    partitionKey: 'userId', // optional\n    eventHubName: 'users', // optional, overrides the global eventHubName\n  })\n  async createUser(userData: any) {\n    // Your user creation logic\n    return {\n      userId: 'user123',\n      ...userData,\n    };\n  }\n}\n```\n\n### Subscribing to Events\n\nUse the `@EventHubSubscribe` decorator to mark methods that should handle incoming events:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { EventHubSubscribe } from '@adamhancock/nestjs-eventhubs';\n\n@Injectable()\nexport class NotificationService {\n  @EventHubSubscribe({\n    routingKey: 'user.created',\n    consumerGroup: 'notifications', // optional, defaults to '$Default'\n    eventHubName: 'users', // optional, overrides the global eventHubName\n  })\n  async handleUserCreated(eventData: any) {\n    // Handle the event\n    console.log('New user created:', eventData);\n  }\n}\n```\n\n### Event Types\n\nThe module includes TypeScript interfaces for type safety:\n\n```typescript\nimport { EventData, UserEventData } from '@adamhancock/nestjs-eventhubs';\n\ninterface CreateUserEvent extends UserEventData {\n  data: {\n    userId: string;\n    email: string;\n  };\n}\n```\n\n### Decorator Options\n\nBoth `@EventHubPublish` and `@EventHubSubscribe` accept the following options:\n\n```typescript\ninterface EventHubMetadata {\n  eventHubName?: string; // Optional, overrides the global eventHubName\n  routingKey?: string; // For message routing\n  consumerGroup?: string; // For subscribers\n  partitionKey?: string; // For publishers\n}\n```\n\n## Error Handling\n\nThe module includes built-in error handling and logging. All errors are logged using NestJS's built-in logger. You can extend the error handling by catching errors in your event handlers:\n\n```typescript\n@EventHubSubscribe({ routingKey: 'user.created' })\nasync handleUserCreated(eventData: any) {\n  try {\n    await this.processEvent(eventData);\n  } catch (error) {\n    // Custom error handling\n    this.logger.error('Failed to process user creation event', error);\n  }\n}\n```\n\n## Development Status\n\n⚠️ This package is currently under active development. The API is not yet stable and may change without notice.\n\n## License\n\nMIT\n\n## Author\n\nAdam Hancock\n","readmeFilename":"README.md"}