Skip to content

Commit

Permalink
feat(DTFS-7049): added POST /emails endpoint for sending emails using…
Browse files Browse the repository at this point in the history
… GOV.UK Notify service (#820)

## Introduction ✏️
We are moving GOV.UK Notify integration from DTFS to MDM API.

## Resolution ✔️
* Created new helper module `govuk-notify`
* It uses npm package `notifications-node-client` to communicate with
GOV.UK Notify
* Created new NestJs module `emails` with endpoint POST /emails
* We create new instance of class `NotifyClient` for each request. This
is because each request can have different GOV.UK Notify API key.

### Request example:
Auth headers:
```
{ govUkNotifyKey: dtfsdev-1234567-1234-1234-abcd-123456789098-abcdefg-1234-1234-6789-def098765432 }
```
Body:
```
{
    "templateId": "abc45678-474e-4f34-a8d7-12345677890",
    "sendToEmailAddress": "JohnSm@example.com",
    "personalisation": {
      "firstName": "John",
      "surname": "Smith",
    }
}
``` 

### Response example:
```
{
    "status": 201,
    "data": {
        "content": {
            "body": "Dear John Smith,\r\n\r\nThe status of your MIA for Star has been updated.\r\n\r\n* With regards,\r\n\r\nThe Digital Trade Finance Service team\r\n\r\nEmail: DigitalService.TradeFinance@ukexportfinance.gov.uk\r\nPhone: +44 (0)207 271 8010\r\nOpening times: Monday to Friday, 9am to 5pm (excluding public holidays)",
            "from_email": "digital.trade.finance@example.com",
            "subject": "Status update: Star bridge",
            "unsubscribe_link": null
        },
        "id": "trans-id-123-0a55-48ae-ad6c-09874363723a",
        "reference": "123456789-474e-4f34-a8d7-abde48cdffce-1713345234336",
        "scheduled_for": null,
        "template": {
            "id": "123456789-474e-4f34-a8d7-abde48cdffce",
           "uri": "https://api.notifications.service.gov.uk/services/11111111-2222-3333-4444-55555555555/templates/123456789-474e-4f34-a8d7-abde48cdffce",
            "version": 24
        },
        "uri": "https://api.notifications.service.gov.uk/v2/notifications/trans-id-123-0a55-48ae-ad6c-09874363723a"
    }
}
```

## New packages
* `notifications-node-client` - GOV.UK Notify package

## New Environment variables
* NA

## Miscellaneous ➕
* Copied API test helper `withStringFieldValidationApiTests` from
`tfs-api` project
* Created API test helper `withEmailFieldValidationApiTests`
* Created API test helper `withObjectFieldValidationApiTests`
* Copied API test helper prepareModifiedRequest from `tfs-api` project
* Moved reusable sub tests from withStringFieldValidationApiTests, like:
  * withRequiredFieldValidationApiTests
  * withTypeFieldValidationApiTests
* Removed ```
        forbidNonWhitelisted: true,
        transformOptions: {
          enableImplicitConversion: true,
        },
``` from global ValidationPipe. It was creating auto transformations
after moving to single object payload.
  • Loading branch information
avaitonis committed May 31, 2024
2 parents 7860528 + 0e61f53 commit 3a1bf0e
Show file tree
Hide file tree
Showing 35 changed files with 4,700 additions and 4,615 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"acbs",
"APIM",
"azurecr",
"Bloggs",
"BBALIBOR",
"BLPU",
"BLPUs",
Expand All @@ -38,6 +39,7 @@
"ESRA",
"ESTR",
"EWCS",
"Govuk",
"hjlnp",
"HJLNP",
"huskyrc",
Expand All @@ -55,6 +57,7 @@
"satify",
"snet",
"szenius",
"tmpl",
"TOID",
"typeorm",
"Typeorm",
Expand Down
Loading

0 comments on commit 3a1bf0e

Please sign in to comment.