|
| 1 | +# NFT Event Generator |
| 2 | + |
| 3 | +This script generates events and sends them in batches of 10 to the AWS EventBridge event bus: **`nhs-<environment>-dl`** (where `<environment>` is the environment specified at the command line). |
| 4 | + |
| 5 | +It supports two event types, each invoked as a subcommand: |
| 6 | + |
| 7 | +- **`supplier-api-letter-event`** – generates `SupplierApiLetterEvent` events (mirrors the `LetterEvent` consumed by `print-status-handler`) |
| 8 | +- **`paper-letter-opt-out-event`** – generates `PaperLetterOptedOut` channel status events, reading input from a CSV file |
| 9 | + |
| 10 | +## Common features |
| 11 | + |
| 12 | +- Custom environments (e.g. `pr293`, `main`, `nft`) |
| 13 | +- Controlled delay between batches of maximum 10 messages |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Subcommand: `supplier-api-letter-event` |
| 18 | + |
| 19 | +Generates a configurable number of supplier API letter events with dynamic or fixed field values. |
| 20 | + |
| 21 | +### CLI Options |
| 22 | + |
| 23 | +| Option | Type | Required | Default | Description | |
| 24 | +|----------------------|--------|----------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 25 | +| `--numberOfEvents` | number | ✅ | | Total number of events to generate and send | |
| 26 | +| `--environment` | string | ❌ | `nft` | Target environment (e.g. `main`, `nft`, `pr283`) | |
| 27 | +| `--interval` | number | ❌ | `1000` | Delay between batches in milliseconds | |
| 28 | +| `--status` | string | ❌ | `ACCEPTED` | Letter status for generated events. One of: `ACCEPTED`, `REJECTED`, `PRINTED`, `DISPATCHED`, `FAILED`, `RETURNED`, `PENDING`, `ENCLOSED`, `CANCELLED`, `FORWARDED`, `DELIVERED` | |
| 29 | +| `--id` | string | ❌ | *(generated)* | Fixed event `id` (uuid). If omitted, a new uuid is generated per event | |
| 30 | +| `--time` | string | ❌ | *(generated)* | Fixed event `time` (ISO 8601). If omitted, the current time is used per event | |
| 31 | +| `--subject` | string | ❌ | *(generated)* | Fixed event `subject`. If omitted, a subject is built from `messageReference` | |
| 32 | +| `--messageReference` | string | ❌ | *(generated)* | Fixed message reference (uuid) embedded in `subject` and `data.origin.subject`. If omitted, a new uuid is generated per event | |
| 33 | + |
| 34 | +### Examples |
| 35 | + |
| 36 | +Generate 2 events in the `nft` environment with a 2-second interval between batches: |
| 37 | + |
| 38 | +```shell |
| 39 | +npm start -- supplier-api-letter-event --environment nft --numberOfEvents 2 --interval 2000 |
| 40 | +``` |
| 41 | + |
| 42 | +Generate events with a specific status: |
| 43 | + |
| 44 | +```shell |
| 45 | +npm start -- supplier-api-letter-event --environment pr293 --numberOfEvents 5 --status PRINTED |
| 46 | +``` |
| 47 | + |
| 48 | +Generate events with a fixed `messageReference` (useful for targeting a specific letter request): |
| 49 | + |
| 50 | +```shell |
| 51 | +npm start -- supplier-api-letter-event --environment pr293 --numberOfEvents 1 --messageReference aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## Subcommand: `paper-letter-opt-out-event` |
| 57 | + |
| 58 | +Reads a CSV file and generates one `PaperLetterOptedOut` channel status event per row. |
| 59 | + |
| 60 | +### CSV format |
| 61 | + |
| 62 | +The CSV file must have two columns per row (no header): |
| 63 | + |
| 64 | +| Column | Description | |
| 65 | +|--------|---------------------------------| |
| 66 | +| 1 | `messageReference` (uuid) | |
| 67 | +| 2 | `senderId` | |
| 68 | + |
| 69 | +Example `opt-outs.csv`: |
| 70 | + |
| 71 | +```csv |
| 72 | +aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee,sender-001 |
| 73 | +11111111-2222-3333-4444-555555555555,sender-002 |
| 74 | +``` |
| 75 | + |
| 76 | +The `messageReference` field in each generated event is built as `<senderId>_<messageReference>`. |
| 77 | + |
| 78 | +### CLI Options |
| 79 | + |
| 80 | +| Option | Type | Required | Default | Description | |
| 81 | +|-----------------|--------|----------|---------------|----------------------------------------------------| |
| 82 | +| `--csvFile` | string | ✅ | | Path to the CSV file (`messageReference,senderId`) | |
| 83 | +| `--environment` | string | ❌ | `nft` | Target environment (e.g. `main`, `nft`, `pr283`) | |
| 84 | +| `--interval` | number | ❌ | `1000` | Delay between batches in milliseconds | |
| 85 | + |
| 86 | +### Examples |
| 87 | + |
| 88 | +Send opt-out events from a CSV file to the `nft` environment: |
| 89 | + |
| 90 | +```shell |
| 91 | +npm start -- paper-letter-opt-out-event --environment nft --csvFile ./opt-outs.csv |
| 92 | +``` |
| 93 | + |
| 94 | +Send to a PR environment with a custom batch interval: |
| 95 | + |
| 96 | +```shell |
| 97 | +npm start -- paper-letter-opt-out-event --environment pr293 --csvFile ./opt-outs.csv --interval 500 |
| 98 | +``` |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Running via Make |
| 103 | + |
| 104 | +To run this script from anywhere in the repository: |
| 105 | + |
| 106 | +```shell |
| 107 | +make perf-test |
| 108 | +``` |
| 109 | + |
| 110 | +The make command runs the following script (configured in `package.json`): |
| 111 | + |
| 112 | +```shell |
| 113 | +"start:nft": "npm start -- supplier-api-letter-event --environment nft --numberOfEvents 2 --interval 2000" |
| 114 | +``` |
| 115 | + |
| 116 | +## Help |
| 117 | + |
| 118 | +To see all available options for a subcommand: |
| 119 | + |
| 120 | +```shell |
| 121 | +npm start -- supplier-api-letter-event --help |
| 122 | +npm start -- paper-letter-opt-out-event --help |
| 123 | +``` |
0 commit comments