notifications-node-client
Advanced tools
Comparing version 3.5.0 to 4.0.0
@@ -0,1 +1,9 @@ | ||
## [4.0.0] - 2017-11-07 | ||
### Changed | ||
* Updated `sendSms`, `sendEmail` and `sendLetter` to take an `options` object as a parameter. | ||
* `personalisation`, `reference`, `smsSenderId` and `emailReplyToId` now need to be passed to these functions inside `options`. | ||
* Removed the unused `Crypto` dependency | ||
## [3.5.0] - 2017-11-01 | ||
@@ -2,0 +10,0 @@ |
var jwt = require('jsonwebtoken'); | ||
var crypto = require('crypto'); | ||
@@ -4,0 +3,0 @@ |
@@ -119,9 +119,12 @@ var ApiClient = require('./api_client'), | ||
* @param {String} emailAddress | ||
* @param {Object} personalisation | ||
* @param {String} reference | ||
* @param {String} emailReplyToId | ||
* @param {Object} options | ||
* | ||
* @returns {Promise} | ||
*/ | ||
sendEmail: function (templateId, emailAddress, personalisation, reference, emailReplyToId) { | ||
sendEmail: function (templateId, emailAddress, options) { | ||
var options = options || {}, | ||
personalisation = options.personalisation || undefined, | ||
reference = options.reference || undefined, | ||
emailReplyToId = options.emailReplyToId || undefined; | ||
return this.apiClient.post('/v2/notifications/email', | ||
@@ -135,9 +138,12 @@ createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId)); | ||
* @param {String} phoneNumber | ||
* @param {Object} personalisation | ||
* @param {String} reference | ||
* @param {String} smsSenderId | ||
* @param {Object} options | ||
* | ||
* @returns {Promise} | ||
*/ | ||
sendSms: function (templateId, phoneNumber, personalisation, reference, smsSenderId) { | ||
sendSms: function (templateId, phoneNumber, options) { | ||
var options = options || {}; | ||
var personalisation = options.personalisation || undefined; | ||
var reference = options.reference || undefined; | ||
var smsSenderId = options.smsSenderId || undefined; | ||
return this.apiClient.post('/v2/notifications/sms', | ||
@@ -150,8 +156,11 @@ createNotificationPayload('sms', templateId, phoneNumber, personalisation, reference, smsSenderId)); | ||
* @param {String} templateId | ||
* @param {Object} personalisation | ||
* @param {String} reference | ||
* @param {Object} options | ||
* | ||
* @returns {Promise} | ||
*/ | ||
sendLetter: function (templateId, personalisation, reference) { | ||
sendLetter: function (templateId, options) { | ||
var options = options || {}; | ||
var personalisation = options.personalisation || undefined; | ||
var reference = options.reference || undefined; | ||
return this.apiClient.post('/v2/notifications/letter', | ||
@@ -158,0 +167,0 @@ createNotificationPayload('letter', templateId, undefined, personalisation, reference)); |
{ | ||
"name": "notifications-node-client", | ||
"version": "3.5.0", | ||
"version": "4.0.0", | ||
"description": "GOV.UK Notify Node.js client ", | ||
@@ -13,3 +13,2 @@ "main": "index.js", | ||
"dependencies": { | ||
"crypto": "0.0.3", | ||
"jsonwebtoken": "7.4.1", | ||
@@ -16,0 +15,0 @@ "request": "^2.73.0", |
786
README.md
@@ -1,6 +0,20 @@ | ||
[![Dependency Status](https://david-dm.org/alphagov/notifications-node-client.svg)](https://david-dm.org/alphagov/notifications-node-client) | ||
# GOV.UK Notify Node.js client | ||
This documentation is for developers interested in using this Node.js client to integrate their government service with GOV.UK Notify. | ||
## Table of Contents | ||
* [Installation](#installation) | ||
* [Getting started](#getting-started) | ||
* [Send messages](#send-messages) | ||
* [Get the status of one message](#get-the-status-of-one-message) | ||
* [Get the status of all messages](#get-the-status-of-all-messages) | ||
* [Get a template by ID](#get-a-template-by-id) | ||
* [Get a template by ID and version](#get-a-template-by-id-and-version) | ||
* [Get all templates](#get-all-templates) | ||
* [Generate a preview template](#generate-a-preview-template) | ||
* [Tests](#tests) | ||
## Installation | ||
```shell | ||
@@ -11,2 +25,3 @@ npm install --save notifications-node-client | ||
## Getting started | ||
```javascript | ||
@@ -17,7 +32,6 @@ var NotifyClient = require('notifications-node-client').NotifyClient, | ||
Generate an API key by logging in to | ||
[GOV.UK Notify](https://www.notifications.service.gov.uk) and going to | ||
the _API integration_ page. | ||
Generate an API key by logging in to [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the _API integration_ page. | ||
### Connect through a proxy (optional) | ||
``` | ||
@@ -31,2 +45,9 @@ notifyClient.setProxy(proxyUrl); | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -40,9 +61,13 @@ notifyClient | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -66,81 +91,28 @@ { | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "RateLimitError", | ||
"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "TooManyRequestsError", | ||
"message": "Exceeded send limits (50) for today" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Can"t send to this recipient using a team-only API key" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Can"t send to this recipient when service is in trial mode | ||
- see https://www.notifications.service.gov.uk/trial-mode" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|`err.error.status_code`|`err.error.errors`| | ||
|:---|:---| | ||
|`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"`<br>`}]`| | ||
|`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient using a team-only API key"`<br>`]}`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary> | ||
Arguments | ||
Click here to expand for more information. | ||
</summary> | ||
#### `phoneNumber` | ||
##### `phoneNumber` | ||
The phone number of the recipient, only required for sms notifications. | ||
#### `templateId` | ||
##### `templateId` | ||
Find by clicking **API info** for the template you want to send. | ||
#### `reference` | ||
##### `reference` | ||
@@ -151,5 +123,4 @@ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications. | ||
##### `personalisation` | ||
#### `personalisation` | ||
If a template has placeholders, you need to provide their values, for example: | ||
@@ -166,3 +137,3 @@ | ||
#### `smsSenderId` | ||
##### `smsSenderId` | ||
@@ -195,4 +166,12 @@ Optional. Specifies the identifier of the sms sender to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Text message sender'. | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -206,9 +185,14 @@ notifyClient | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -231,80 +215,30 @@ { | ||
``` | ||
Otherwise the client will return an error `error object`: | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "RateLimitError", | ||
"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "TooManyRequestsError", | ||
"message": "Exceeded send limits (50) for today" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Can"t send to this recipient using a team-only API key" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Can"t send to this recipient when service is in trial mode | ||
- see https://www.notifications.service.gov.uk/trial-mode" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"`<br>`}]`| | ||
|`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient using a team-only API key"`<br>`]}`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `emailAddress` | ||
##### `emailAddress` | ||
The email address of the recipient, only required for email notifications. | ||
#### `templateId` | ||
##### `templateId` | ||
Find by clicking **API info** for the template you want to send. | ||
#### `reference` | ||
##### `reference` | ||
@@ -315,24 +249,28 @@ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications. | ||
#### `emailReplyToId` | ||
##### `personalisation` | ||
If a template has placeholders, you need to provide their values, for example: | ||
```javascript | ||
personalisation={ | ||
'first_name': 'Amala', | ||
'application_number': '300241', | ||
} | ||
``` | ||
##### `emailReplyToId` | ||
Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'. | ||
If you omit this argument your default email reply-to address will be set for the notification. | ||
If other optional arguments before `emailReplyToId` are not in use they need to be set to `undefined`. | ||
Example usage with optional reference - | ||
``` | ||
sendEmail('123', 'test@gov.uk', undefined, 'your ref', '465') | ||
``` | ||
Example usage with optional personalisation - | ||
``` | ||
sendEmail('123', 'test@gov.uk', '{"name": "test"}', undefined, '465') | ||
``` | ||
Example usage with only optional `emailReplyToId` set - | ||
``` | ||
@@ -342,19 +280,14 @@ sendEmail('123', 'test@gov.uk', undefined, undefined, '465') | ||
#### `personalisation` | ||
</details> | ||
If a template has placeholders, you need to provide their values, for example: | ||
```javascript | ||
personalisation={ | ||
'first_name': 'Amala', | ||
'application_number': '300241', | ||
} | ||
``` | ||
### Letter | ||
Otherwise the parameter can be omitted or `undefined` can be passed in its place. | ||
#### Method | ||
</details> | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
### Letter | ||
```javascript | ||
@@ -364,3 +297,3 @@ notifyClient | ||
.then(response => console.log(response)) | ||
.catch(err => console.error(err)) | ||
.catch(err => console.error object) | ||
; | ||
@@ -381,10 +314,14 @@ ``` | ||
``` | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`: | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -409,88 +346,26 @@ { | ||
Otherwise the client will raise a `HTTPError`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`error.status_code`</th> | ||
<th>`error.message`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "RateLimitError", | ||
"message": "Exceeded rate limit for key type live of 10 requests per 20 seconds" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>429</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "TooManyRequestsError", | ||
"message": "Exceeded send limits (50) for today" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Cannot send letters with a team api key" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Cannot send letters when service is in trial mode" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "ValidationError", | ||
"message": "personalisation address_line_1 is a required property" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type live of 10 requests per 20 seconds"`<br>`}]`| | ||
|`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters with a team api key"`<br>`]}`| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "personalisation address_line_1 is a required property"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
##### `template_id` | ||
#### `template_id` | ||
Find by clicking **API info** for the template you want to send. | ||
#### `reference` | ||
##### `reference` | ||
@@ -501,3 +376,3 @@ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications. | ||
#### `personalisation` | ||
##### `personalisation` | ||
@@ -526,3 +401,12 @@ The letter must contain: | ||
## Get the status of one message | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -536,5 +420,10 @@ notifyClient | ||
</details> | ||
#### Response | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
@@ -571,42 +460,33 @@ | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>404</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "NoResultFound", | ||
"message": "No result found" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "ValidationError", | ||
"message": "id is not a valid UUID" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
Otherwise the client will return an error `error object`: | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
##### `notificationId` | ||
The ID of the notification. | ||
</details> | ||
## Get the status of all messages | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -619,10 +499,14 @@ notifyClient | ||
``` | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -661,45 +545,18 @@ { "notifications": | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
'error': 'ValidationError', | ||
'message': 'bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]' | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "ValidationError", | ||
"message": "Apple is not one of [sms, email, letter]" | ||
}] | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"`<br>`}]`| | ||
|`400`|`[{`<br>`"error": "Apple is not one of [sms, email, letter]"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `templateType` | ||
##### `templateType` | ||
@@ -712,6 +569,7 @@ If omitted all messages are returned. Otherwise you can filter by: | ||
##### `status` | ||
#### `status` | ||
__email__ | ||
If omitted all messages are returned. Otherwise you can filter by: | ||
You can filter by: | ||
@@ -721,18 +579,50 @@ * `sending` - the message is queued to be sent by the provider. | ||
* `failed` - this will return all failure statuses `permanent-failure`, `temporary-failure` and `technical-failure`. | ||
* `permanent-failure` - the provider was unable to deliver message, email or phone number does not exist; remove this recipient from your list. | ||
* `temporary-failure` - the provider was unable to deliver message, email box was full or the phone was turned off; you can try to send the message again. | ||
* `permanent-failure` - the provider was unable to deliver message, email does not exist; remove this recipient from your list. | ||
* `temporary-failure` - the provider was unable to deliver message, email box was full; you can try to send the message again. | ||
* `technical-failure` - Notify had a technical failure; you can try to send the message again. | ||
#### `reference` | ||
You can omit this argument to ignore this filter. | ||
__text message__ | ||
You can filter by: | ||
* `sending` - the message is queued to be sent by the provider. | ||
* `delivered` - the message was successfully delivered. | ||
* `failed` - this will return all failure statuses `permanent-failure`, `temporary-failure` and `technical-failure`. | ||
* `permanent-failure` - the provider was unable to deliver message, phone number does not exist; remove this recipient from your list. | ||
* `temporary-failure` - the provider was unable to deliver message, the phone was turned off; you can try to send the message again. | ||
* `technical-failure` - Notify had a technical failure; you can try to send the message again. | ||
You can omit this argument to ignore this filter. | ||
__letter__ | ||
You can filter by: | ||
* `accepted` - Notify is in the process of printing and posting the letter | ||
* `technical-failure` - Notify had an unexpected error while sending to our printing provider | ||
You can omit this argument to ignore this filter. | ||
##### `reference` | ||
This is the `reference` you gave at the time of sending the notification. This can be omitted to ignore the filter. | ||
#### `olderThan` | ||
##### `olderThan` | ||
If omitted all messages are returned. Otherwise you can filter to retrieve all notifications older than the given notification `id`. | ||
</details> | ||
## Get a template by ID | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -746,9 +636,14 @@ notifyClient | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -767,38 +662,34 @@ { | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>404</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "NoResultFound", | ||
"message": "No result found" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
Otherwise the client will return an error `error object`: | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `templateId` | ||
##### `templateId` | ||
Find by clicking **API info** for the template you want to send. | ||
</details> | ||
## Get a template by ID and version | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -812,9 +703,14 @@ notifyClient | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -832,39 +728,26 @@ { | ||
``` | ||
Otherwise the client will return an error `error object`: | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>404</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "NoResultFound", | ||
"message": "No result found" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"No result found"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `templateId` | ||
##### `templateId` | ||
Find by clicking **API info** for the template you want to send. | ||
#### `version` | ||
##### `version` | ||
The version number of the template | ||
</details> | ||
@@ -874,2 +757,9 @@ | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -882,11 +772,16 @@ notifyClient | ||
``` | ||
_This will return the latest version for each template_ | ||
This will return the latest version for each template. | ||
</details> | ||
#### Response | ||
If the request is successful, `response` will be an `object`. | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
If the request is successful, `response` will be an `object`: | ||
```javascript | ||
@@ -922,6 +817,11 @@ { | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `templateType` | ||
##### `templateType` | ||
@@ -933,6 +833,15 @@ If omitted all messages are returned. Otherwise you can filter by: | ||
* `letter` | ||
</details> | ||
## Generate a preview template | ||
#### Method | ||
<details> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
```javascript | ||
@@ -946,5 +855,11 @@ personalisation = { "foo": "bar" }; | ||
``` | ||
</details> | ||
#### Response | ||
<details> | ||
<summary> | ||
Response | ||
Click here to expand for more information. | ||
</summary> | ||
@@ -964,49 +879,24 @@ | ||
Otherwise the client will return an error `err`: | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>`err.error.status_code`</th> | ||
<th>`err.error.errors`</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre>400</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "BadRequestError", | ||
"message": "Missing personalisation: [name]" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<pre>404</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
[{ | ||
"error": "NoResultFound", | ||
"message": "No result found" | ||
]} | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
Otherwise the client will return an error `error object`: | ||
|`status_code`|`errors`| | ||
|:---|:---| | ||
|`400`|`[{`<br>`"error": "BadRequestError",`<br>`"Missing personalisation: [name]"`<br>`}]`| | ||
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"No result found"`<br>`}]`| | ||
</details> | ||
#### Arguments | ||
<details> | ||
<summary>Arguments</summary> | ||
<summary> | ||
Click here to expand for more information. | ||
</summary> | ||
#### `templateId` | ||
##### `templateId` | ||
Find by clicking **API info** for the template you want to send. | ||
#### `personalisation` | ||
##### `personalisation` | ||
@@ -1023,4 +913,6 @@ If a template has placeholders you need to provide their values. For example: | ||
Otherwise the parameter can be omitted or `undefined` can be passed in its place. | ||
</details> | ||
## Tests | ||
@@ -1041,1 +933,5 @@ | ||
``` | ||
var expect = require('chai').expect, | ||
MockDate = require('mockdate'), | ||
ApiClient = require('../client/api_client.js'), | ||
@@ -10,2 +11,10 @@ nock = require('nock'), | ||
beforeEach(function() { | ||
MockDate.set(1234567890000); | ||
}); | ||
afterEach(function() { | ||
MockDate.reset(); | ||
}); | ||
it('should make a get request with correct headers', function (done) { | ||
@@ -12,0 +21,0 @@ |
@@ -59,7 +59,9 @@ const NotifyClient = require('../../client/notification.js').NotifyClient; | ||
it('send email notification', () => { | ||
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'); | ||
return notifyClient.sendEmail(emailTemplateId, email, personalisation, clientRef).then((response) => { | ||
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'), | ||
options = {personalisation: personalisation, reference: clientRef}; | ||
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => { | ||
response.statusCode.should.equal(201); | ||
expect(response.body).to.be.jsonSchema(postEmailNotificationResponseJson); | ||
response.body.content.body.should.equal('Hello Foo\n\nFunctional test help make our world a better place'); | ||
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place'); | ||
response.body.content.subject.should.equal('Functional Tests are good'); | ||
@@ -72,8 +74,10 @@ response.body.reference.should.equal(clientRef); | ||
it('send email notification with email_reply_to_id', () => { | ||
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'); | ||
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'), | ||
options = {personalisation: personalisation, reference: clientRef, emailReplyToId: emailReplyToId}; | ||
should.exist(emailReplyToId); | ||
return notifyClient.sendEmail(emailTemplateId, email, personalisation, clientRef, emailReplyToId).then((response) => { | ||
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => { | ||
response.statusCode.should.equal(201); | ||
expect(response.body).to.be.jsonSchema(postEmailNotificationResponseJson); | ||
response.body.content.body.should.equal('Hello Foo\n\nFunctional test help make our world a better place'); | ||
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place'); | ||
response.body.content.subject.should.equal('Functional Tests are good'); | ||
@@ -86,7 +90,9 @@ response.body.reference.should.equal(clientRef); | ||
it('send sms notification', () => { | ||
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'); | ||
return notifyClient.sendSms(smsTemplateId, phoneNumber, personalisation).then((response) => { | ||
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'), | ||
options = {personalisation: personalisation}; | ||
return notifyClient.sendSms(smsTemplateId, phoneNumber, options).then((response) => { | ||
response.statusCode.should.equal(201); | ||
expect(response.body).to.be.jsonSchema(postSmsNotificationResponseJson); | ||
response.body.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place'); | ||
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place'); | ||
smsNotificationId = response.body.id; | ||
@@ -97,8 +103,10 @@ }); | ||
it('send sms notification with sms_sender_id', () => { | ||
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'); | ||
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'), | ||
options = {personalisation: personalisation, reference: clientRef, smsSenderId: smsSenderId}; | ||
should.exist(smsSenderId); | ||
return notifyClient.sendSms(smsTemplateId, phoneNumber, personalisation, clientRef, smsSenderId).then((response) => { | ||
return notifyClient.sendSms(smsTemplateId, phoneNumber, options).then((response) => { | ||
response.statusCode.should.equal(201); | ||
expect(response.body).to.be.jsonSchema(postSmsNotificationResponseJson); | ||
response.body.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place'); | ||
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place'); | ||
smsNotificationId = response.body.id; | ||
@@ -109,4 +117,6 @@ }); | ||
it('send letter notification', () => { | ||
var postLetterNotificationResponseJson = require('./schemas/v2/POST_notification_letter_response.json'); | ||
return notifyClient.sendLetter(letterTemplateId, letterContact).then((response) => { | ||
var postLetterNotificationResponseJson = require('./schemas/v2/POST_notification_letter_response.json'), | ||
options = {personalisation: letterContact}; | ||
return notifyClient.sendLetter(letterTemplateId, options).then((response) => { | ||
response.statusCode.should.equal(201); | ||
@@ -128,3 +138,3 @@ expect(response.body).to.be.jsonSchema(postLetterNotificationResponseJson); | ||
response.body.type.should.equal('email'); | ||
response.body.body.should.equal('Hello Foo\n\nFunctional test help make our world a better place'); | ||
response.body.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place'); | ||
response.body.subject.should.equal('Functional Tests are good'); | ||
@@ -140,3 +150,3 @@ }); | ||
response.body.type.should.equal('sms'); | ||
response.body.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place'); | ||
response.body.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place'); | ||
}); | ||
@@ -183,3 +193,3 @@ }); | ||
expect(response.body).to.be.jsonSchema(getTemplateJson); | ||
response.body.body.should.equal('Hello ((name))\n\nFunctional test help make our world a better place'); | ||
response.body.body.should.equal('Hello ((name))\r\n\r\nFunctional test help make our world a better place'); | ||
response.body.subject.should.equal('Functional Tests are good'); | ||
@@ -186,0 +196,0 @@ }); |
var expect = require('chai').expect, NotifyClient = require('../client/notification.js').NotifyClient, | ||
MockDate = require('mockdate'), | ||
nock = require('nock'), | ||
createGovukNotifyToken = require('../client/authentication.js'); | ||
MockDate.set(1234567890000); | ||
const baseUrl = 'http://localhost'; | ||
@@ -26,2 +29,10 @@ const serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1'; | ||
beforeEach(function() { | ||
MockDate.set(1234567890000); | ||
}); | ||
afterEach(function() { | ||
MockDate.reset(); | ||
}); | ||
var notifyClient = getNotifyClient(); | ||
@@ -34,7 +45,9 @@ var notifyAuthNock = getNotifyAuthNock(); | ||
templateId = '123', | ||
personalisation = {foo: 'bar'}, | ||
options = { | ||
personalisation: {foo: 'bar'}, | ||
}, | ||
data = { | ||
template_id: templateId, | ||
email_address: email, | ||
personalisation: personalisation | ||
personalisation: options.personalisation | ||
}; | ||
@@ -46,3 +59,3 @@ | ||
notifyClient.sendEmail(templateId, email, personalisation) | ||
notifyClient.sendEmail(templateId, email, options) | ||
.then(function (response) { | ||
@@ -59,10 +72,11 @@ expect(response.statusCode).to.equal(200); | ||
templateId = '123', | ||
personalisation = {foo: 'bar'}, | ||
reference = '', | ||
emailReplyToId = '456', | ||
options = { | ||
personalisation: {foo: 'bar'}, | ||
emailReplyToId: '456', | ||
}, | ||
data = { | ||
template_id: templateId, | ||
email_address: email, | ||
personalisation: personalisation, | ||
email_reply_to_id: emailReplyToId | ||
personalisation: options.personalisation, | ||
email_reply_to_id: options.emailReplyToId | ||
}; | ||
@@ -74,3 +88,3 @@ | ||
notifyClient.sendEmail(templateId, email, personalisation, reference, emailReplyToId) | ||
notifyClient.sendEmail(templateId, email, options) | ||
.then(function (response) { | ||
@@ -87,7 +101,9 @@ expect(response.statusCode).to.equal(200); | ||
templateId = '123', | ||
personalisation = {foo: 'bar'}, | ||
options = { | ||
personalisation: {foo: 'bar'}, | ||
}, | ||
data = { | ||
template_id: templateId, | ||
phone_number: phoneNo, | ||
personalisation: personalisation | ||
personalisation: options.personalisation | ||
}; | ||
@@ -99,3 +115,3 @@ | ||
notifyClient.sendSms(templateId, phoneNo, personalisation) | ||
notifyClient.sendSms(templateId, phoneNo, options) | ||
.then(function (response) { | ||
@@ -111,10 +127,11 @@ expect(response.statusCode).to.equal(200); | ||
templateId = '123', | ||
personalisation = {foo: 'bar'}, | ||
reference = '', | ||
sms_sender_id = '456', | ||
options = { | ||
personalisation: {foo: 'bar'}, | ||
smsSenderId: '456', | ||
}, | ||
data = { | ||
template_id: templateId, | ||
phone_number: phoneNo, | ||
personalisation: personalisation, | ||
sms_sender_id: sms_sender_id | ||
personalisation: options.personalisation, | ||
sms_sender_id: options.smsSenderId, | ||
}; | ||
@@ -126,3 +143,3 @@ | ||
notifyClient.sendSms(templateId, phoneNo, personalisation, reference, sms_sender_id) | ||
notifyClient.sendSms(templateId, phoneNo, options) | ||
.then(function (response) { | ||
@@ -137,10 +154,12 @@ expect(response.statusCode).to.equal(200); | ||
var templateId = '123', | ||
personalisation = { | ||
address_line_1: 'Mr Tester', | ||
address_line_2: '1 Test street', | ||
postcode: 'NW1 2UN' | ||
options = { | ||
personalisation: { | ||
address_line_1: 'Mr Tester', | ||
address_line_2: '1 Test street', | ||
postcode: 'NW1 2UN' | ||
}, | ||
}, | ||
data = { | ||
template_id: templateId, | ||
personalisation: personalisation | ||
personalisation: options.personalisation | ||
}; | ||
@@ -152,3 +171,3 @@ | ||
notifyClient.sendLetter(templateId, personalisation) | ||
notifyClient.sendLetter(templateId, options) | ||
.then(function (response) { | ||
@@ -371,1 +390,3 @@ expect(response.statusCode).to.equal(200); | ||
}); | ||
MockDate.reset(); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
83517
4
1578
0
903
- Removedcrypto@0.0.3
- Removedcrypto@0.0.3(transitive)