notifications-node-client 8.3.0 → 8.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/package.json +7 -2
  2. package/.dockerignore +0 -1
  3. package/.github/PULL_REQUEST_TEMPLATE.md +0 -18
  4. package/CHANGELOG.md +0 -297
  5. package/CONTRIBUTING.md +0 -59
  6. package/Dockerfile +0 -17
  7. package/Makefile +0 -42
  8. package/scripts/run_with_docker.sh +0 -21
  9. package/scripts/test_send.js +0 -57
  10. package/spec/api_client.js +0 -156
  11. package/spec/authentication.js +0 -32
  12. package/spec/integration/schemas/v1/GET_notifications_return.json +0 -37
  13. package/spec/integration/schemas/v1/POST_notification_return_email.json +0 -27
  14. package/spec/integration/schemas/v1/POST_notification_return_sms.json +0 -26
  15. package/spec/integration/schemas/v1/definitions.json +0 -12
  16. package/spec/integration/schemas/v1/email_notification.json +0 -106
  17. package/spec/integration/schemas/v1/sms_notification.json +0 -104
  18. package/spec/integration/schemas/v2/GET_notification_response.json +0 -50
  19. package/spec/integration/schemas/v2/GET_notifications_response.json +0 -29
  20. package/spec/integration/schemas/v2/GET_received_text_response.json +0 -23
  21. package/spec/integration/schemas/v2/GET_received_texts_response.json +0 -29
  22. package/spec/integration/schemas/v2/GET_template_by_id.json +0 -30
  23. package/spec/integration/schemas/v2/GET_templates_response.json +0 -15
  24. package/spec/integration/schemas/v2/POST_notification_email_response.json +0 -18
  25. package/spec/integration/schemas/v2/POST_notification_letter_response.json +0 -19
  26. package/spec/integration/schemas/v2/POST_notification_precompiled_letter_response.json +0 -19
  27. package/spec/integration/schemas/v2/POST_notification_sms_response.json +0 -18
  28. package/spec/integration/schemas/v2/POST_template_preview.json +0 -14
  29. package/spec/integration/schemas/v2/definitions.json +0 -51
  30. package/spec/integration/test.js +0 -415
  31. package/spec/integration/test_files/one_page_pdf.pdf +0 -0
  32. package/spec/notification.js +0 -633
  33. package/spec/test_files/simple.csv +0 -2
  34. package/spec/types-test.ts +0 -153
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifications-node-client",
3
- "version": "8.3.0",
3
+ "version": "8.3.1",
4
4
  "homepage": "https://docs.notifications.service.gov.uk/node.html",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,12 +9,17 @@
9
9
  "description": "GOV.UK Notify Node.js client ",
10
10
  "main": "index.js",
11
11
  "types": "types/index.d.ts",
12
+ "files": [
13
+ "client",
14
+ "types",
15
+ "tsconfig.json"
16
+ ],
12
17
  "scripts": {
13
18
  "test": "mocha \"spec/**/*.js\" && npm run test:markdown:standard",
14
19
  "test:markdown:standard": "standard-markdown DOCUMENTATION.md",
15
20
  "integration": "mocha spec/integration/test.js",
16
21
  "build:types": "tsc",
17
- "check:types": "tsc --noEmit"
22
+ "check:types": "tsc --noEmit ./spec/types-test.ts"
18
23
  },
19
24
  "engines": {
20
25
  "npm": ">=6.14.13",
package/.dockerignore DELETED
@@ -1 +0,0 @@
1
- **/.git/*
@@ -1,18 +0,0 @@
1
- <!--Thanks for contributing to GOV.UK Notify. Using this template to write your pull request message will help get it merged as soon as possible. -->
2
-
3
- ## What problem does the pull request solve?
4
- <!--- Describe why you’re making this change -->
5
-
6
- ## Checklist
7
-
8
- <!--- All of the following are normally needed. Don’t worry if you haven’t done them or don’t know how – someone from the Notify team will be able to help. -->
9
- - [x] I’ve used the pull request template
10
- - [ ] I’ve written unit tests for these changes
11
- - [ ] I’ve updated the documentation in
12
- - [notifications-tech-docs repository](https://github.com/alphagov/notifications-tech-docs/blob/main/source/documentation/client_docs/_node.md)
13
- - `CHANGELOG.md`
14
- - [ ] I’ve bumped the version number in
15
- - `package.json`
16
- - [ ] I've added new environment variables in
17
- - `CONTRIBUTING.md`
18
- - `notifications-node-client/scripts/generate_docker_env.sh`
package/CHANGELOG.md DELETED
@@ -1,297 +0,0 @@
1
- ## 8.3.0 - 2026-02-19
2
-
3
- * Adds Typescript hints (run `npm build:types` to generate type files in `types/`)
4
- * Bump axios from 1.7.2 to 1.13.5
5
-
6
- ## 8.2.1 - 2024-07-03
7
-
8
- * Fix a bug where an internal API client function isn't being exposed in the library.
9
-
10
- ## 8.2.0 - 2024-05-17
11
-
12
- * Add support for providing a custom underlying Axios client via `setClient`.
13
-
14
- ## 8.1.0 - 2024-05-09
15
-
16
- * The `sendEmail` function can now be passed `oneClickUnsubscribeURL` as an optional argument.
17
-
18
- ## 8.0.0 - 2023-12-27
19
-
20
- * Remove the default `is_csv` boolean parameter from `prepareUpload`. This method now accepts a file and an options map with the following options. For more specific information please read the documentation.
21
- * `filename` (string) - specify the document's filename upon download
22
- * `confirm_email_before_download` (boolean) - require the user to enter their email address before the file can be downloaded.
23
- * `retention_period` (string) - how long Notify should make the file available to the user for.
24
-
25
- ## 7.0.6 - 2023-11-13
26
-
27
- * Bump axios from 1.2.6 to 1.6.1
28
-
29
- ## 7.0.5 - 2023-11-13
30
-
31
- * Fix a few cases of assignment to undeclared (global) variables
32
-
33
- ## 7.0.4 - 2023-11-10
34
-
35
- * Bump axios to the 1.x branch to address CVE-2023-45857. Due to underlying changes in Axios you may have to explicitly set the `protocol` property when constructing your `proxyConfig` object, if using a proxy.
36
-
37
- ## 7.0.3 - 2023-07-21
38
-
39
- * Bump word-wrap from 1.2.3 to 1.2.4 to address CVE-2023-26115.
40
-
41
- ## 7.0.2 - 2023-07-13
42
-
43
- * Bump semver from 5.7.1 to 5.7.2
44
-
45
- ## 7.0.1 - 2023-07-13
46
-
47
- * Fix a bug with default behaviour for `confirmEmailBeforeDownload`, which coalesced false to null.
48
-
49
- ## 7.0.0 - 2023-01-12
50
-
51
- * Remove support for node versions below v14.17.3.
52
-
53
- ## 6.0.0 - 2022-12-22
54
-
55
- * Bump jsonwebtokens from 8.5.1 to 9.0.0 to mitigate CVE-2022-23529. We don't believe this CVE affects any use-cases of notifications-node-client; this update is out of best-practice rather than any direct concern.
56
- * Remove support for node versions below v12.
57
-
58
- ## 5.2.3 - 2022-11-22
59
-
60
- * Bump follow-redirects from 1.14.7 to 1.15.2
61
-
62
- ## 5.2.2 - 2022-11-16
63
-
64
- * Upgrade ansi-regex dependencies to mitigate CVE-2021-3807.
65
-
66
- ## 5.2.1 - 2022-10-19
67
-
68
- * Support strings in calls to `prepareUpload`. `fs.readFile` can return strings if an encoding is provided, and the client didn't handle these correctly.
69
-
70
- ## 5.2.0 - 2022-09-27
71
-
72
- * Add support for new security features when sending a file by email:
73
- * `confirmEmailBeforeDownload` can be set to `true` to require the user to enter their email address before accessing the file.
74
- * `retentionPeriod` can be set to `<1-78> weeks` to set how long the file should be made available.
75
-
76
- * The `isCsv` parameter to `prepareUpload` has now been replaced by an `options` parameter. The implementation has been done in a backwards-compatible way, so if you are just sending `true/false` values as the seecond parameter, that will continue to work. Though we still recommend updating to use the new options format.
77
-
78
-
79
- ## 5.1.2 - 2022-09-23
80
-
81
- Remove underscore.js dependencyr new send a file features)
82
-
83
- ## 5.1.1 - 2022-01-18
84
-
85
- Upgrade axios version from ^0.21.1 to ^0.25.0
86
-
87
- ## 5.1.0 - 2020-12-30
88
-
89
- ### Changed
90
-
91
- * Upgrade axios version from 0.19.2 to 0.21.1
92
- * Allow any compatible version of axios to be used (0.21.1 to <1.0.0)
93
- * Allow any compatible version of jsonwebtoken to be used (8.2.1 to <9.0.0)
94
-
95
- ## 5.0.2 - 2020-11-20
96
-
97
- ### Changed
98
-
99
- Correct incorrect description of parameter to be used by `NotifyClient.setProxy`
100
-
101
- ## 5.0.1 - 2020-11-18
102
-
103
- ### Changed
104
-
105
- Remove unintentional global nature of variable `version`
106
-
107
- ## 5.0.0 - 2020-09-02
108
-
109
- ### Changed
110
-
111
- We have replaced the use of the npm [request-promise](https://www.npmjs.com/package/request-promise) package with [axios](https://www.npmjs.com/package/axios) as the npm [request](https://www.npmjs.com/package/request) package has been deprecated. This makes the following breaking changes:
112
-
113
- 1. The `response` `object` returned by a successful API call is now in the form of an [axios response](https://www.npmjs.com/package/axios#response-schema). This has a different interface to a [request response](https://nodejs.org/api/http.html#http_class_http_incomingmessage). For example:
114
-
115
- * `response.body` becomes `response.data`
116
- * `response.statusCode` becomes `response.status`
117
-
118
- 2. The `err` `object` returned by an unsuccessful API call has a different interface. For example, `err.error` becomes `err.response.data`. See the axios documentation for further details on [error handling](https://www.npmjs.com/package/axios#handling-errors).
119
-
120
- 3. To configure the use of a proxy you should pass the proxy configuration as an `object` rather than a URL. For details, see the [axios client](https://github.com/axios/axios).
121
-
122
- 4. We now return native [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) rather than [bluebird promises](http://bluebirdjs.com). You will not need to make any changes unless you are using some of the additional methods found on bluebird promises that do not exist on native promises.
123
-
124
-
125
- ## 4.9.0 - 2020-08-19
126
-
127
- ### Changed
128
-
129
- * Added `letter_contact_block` to the responses for `getTemplateById`, `getTemplateByIdAndVersion` and `getAllTemplates`.
130
-
131
- ## 4.8.0 - 2020-06-18
132
-
133
- ### Changed
134
-
135
- * Add support for an optional `isCsv` parameter in the `prepareUpload` function. This fixes a bug when sending a CSV file by email. This ensures that the file is downloaded as a CSV rather than a TXT file.
136
-
137
- ## [4.7.3] - 2020-04-03
138
-
139
- ### Changed
140
-
141
- * Remove `__dirname` global call from api client
142
-
143
- ## [4.7.2] - 2020-01-31
144
-
145
- ### Changed
146
-
147
- * Add homepage to package.json
148
-
149
- ## [4.7.1] - 2020-01-27
150
-
151
- ### Changed
152
-
153
- * Refer to files, not documents, in error messages
154
-
155
- ## [4.7.0] - 2019-11-01
156
-
157
- ### Changed
158
-
159
- * Add `notifyClient.getPdfForLetterNotification(notificationId)`
160
- * Returns a Buffer with pdf data
161
- * Will raise a BadRequestError if the PDF is not available
162
-
163
- ## [4.6.0] - 2019-02-01
164
-
165
- ### Changed
166
-
167
- * Added an optional postage argument to `sendPrecompiledLetter`
168
-
169
- ## [4.5.2] - 2018-11-05
170
-
171
- ### Changed
172
-
173
- * Moved documentation to https://docs.notifications.service.gov.uk/node.html (generated from DOCUMENTATION.md)
174
-
175
- ## [4.5.1] - 2018-09-14
176
-
177
- ### Changed
178
-
179
- * Made formatting consistent across documentation.
180
-
181
- ## [4.5.0] - 2018-09-13
182
-
183
- ### Changed
184
-
185
- * Added a function to send precompiled letter through the client.
186
- * the new function uses a helper function to check if the file size is within the 5MB limit and to encode the file using base64. Then a POST request to our API is made with the file data and user reference.
187
- * instructions for the new functionality added to the documentation.
188
-
189
- ## [4.4.0] - 2018-09-05
190
-
191
- ### Changed
192
-
193
- * Added instructions for uploading a document to be linked to from an email notification.
194
- * Created a helper function `prepareUpload` as a part of this development. This function encodes the document that is to be uploaded with base64 and returns a dictionary with prepared document as a value (the way our API is prepared to receive it). It also checks if the provided file is not larger than 2MB. The function throws an error if the file is too big.
195
-
196
- ## [4.3.0] - 2018-09-04
197
-
198
- * Added `name` to the response for `getTemplateById()` and `getTemplateByIdAndVersion()`
199
- * These functions now return the name of the template as set in Notify
200
-
201
- ## [4.2.0] - 2018-07-24
202
-
203
- ### Changed
204
-
205
- * Added `created_by_name` to the response for `.getNotificationById()` and `.getNotifications()`:
206
- * If the notification was sent manually this will be the name of the sender. If the notification was sent through the API this will be `null`.
207
-
208
- ## [4.1.0] - 2017-11-23
209
-
210
- ### Changed
211
-
212
- * Added new method:
213
- * `getReceivedTexts` - get one page of text messages (250) per call
214
-
215
- ## [4.0.0] - 2017-11-07
216
-
217
- ### Changed
218
-
219
- * Updated `sendSms`, `sendEmail` and `sendLetter` to take an `options` object as a parameter.
220
- * `personalisation`, `reference`, `smsSenderId` and `emailReplyToId` now need to be passed to these functions inside `options`.
221
- * Removed the unused `Crypto` dependency
222
-
223
- ## [3.5.0] - 2017-11-01
224
-
225
- ### Changed
226
-
227
- * Updated `sendSms` method with optional argument:
228
- * `smsSenderId` - specify the identifier of the sms sender (optional)
229
-
230
- ## [3.4.0] - 2017-10-19
231
-
232
- ### Changed
233
-
234
- * Added new method:
235
- * `sendLetter` - send a letter
236
-
237
- ## [3.3.0] - 2017-10-13
238
-
239
- ### Changed
240
-
241
- * Updated `sendEmail` method with optional argument:
242
- * `emailReplyToId` - specify the identifier of the email reply-to address (optional)
243
-
244
- ## [3.2.0] - 2017-09-22
245
-
246
- ### Changed
247
-
248
- * Added new method:
249
- * `setProxy(proxyUrl)` - specify the URL of a proxy for the client to use (optional)
250
-
251
- ## [3.1.0] - 2017-05-10
252
-
253
- ### Changed
254
-
255
- * Added new methods for managing templates:
256
- * `getTemplateById` - retrieve a single template
257
- * `getTemplateByIdAndVersion` - retrieve a specific version for a desired template
258
- * `getAllTemplates` - retrieve all templates (can filter by type)
259
- * `previewTemplateById` - preview a template with personalisation applied
260
-
261
- * Update README to describe how to catch errors
262
-
263
- ## [3.0.0] - 2016-12-16
264
-
265
- ### Changed
266
-
267
- * Using v2 of the notification-api.
268
-
269
- * Update to `notifyClient.sendSms()`:
270
- * Added `reference`: an optional identifier you generate if you don’t want to use Notify’s `id`. It can be used to identify a single notification or a batch of notifications.
271
- * Updated method signature:
272
-
273
- ```javascript
274
- notifyClient.sendSms(templateId, phoneNumber, personalisation, reference);
275
- ```
276
- * Where `personalisation` and `reference` can be `undefined`.
277
-
278
- * Update to `notifyClient.sendEmail()`:
279
- * Added `reference`: an optional identifier you generate if you don’t want to use Notify’s `id`. It can be used to identify a single notification or a batch of notifications.
280
- * Updated method signature:
281
-
282
- ```javascript
283
- notifyClient.sendEmail(templateId, emailAddress, personalisation, reference);
284
- ```
285
- * Where `personalisation` and `reference` can be `undefined`.
286
- * `NotificationClient.getAllNotifications()`
287
- * Notifications can now be filtered by `reference` and `olderThanId`, see the README for details.
288
- * Updated method signature:
289
-
290
- ```javascript
291
- notifyClient.getNotifications(templateType, status, reference, olderThanId);
292
- ```
293
- * Each one of these parameters can be `undefined`
294
-
295
- # Prior versions
296
-
297
- Changelog not recorded - please see pull requests on github.
package/CONTRIBUTING.md DELETED
@@ -1,59 +0,0 @@
1
- # Contributing
2
-
3
- Pull requests welcome.
4
-
5
- ## Setting Up
6
-
7
- ### Docker container
8
-
9
- This app uses dependencies that are difficult to install locally. In order to make local development easy, we run app commands through a Docker container. Run the following to set this up:
10
-
11
- ```shell
12
- make bootstrap-with-docker
13
- ```
14
-
15
- ### `environment.sh`
16
-
17
- In the root directory of the repo, run:
18
-
19
- ```
20
- notify-pass credentials/client-integration-tests > environment.sh
21
- ```
22
-
23
- Unless you're part of the GOV.UK Notify team, you won't be able to run this command or the Integration Tests. However, the file still needs to exist - run `touch environment.sh` instead.
24
-
25
- ## Tests
26
-
27
- There are unit and integration tests that can be run to test functionality of the client.
28
-
29
- ### Unit tests
30
-
31
- To run the unit tests:
32
-
33
- ```
34
- make test-with-docker
35
- ```
36
-
37
- ### Integration Tests
38
-
39
- To run the integration tests:
40
-
41
- ```
42
- make integration-test-with-docker
43
- ```
44
-
45
- ## Working on the client locally
46
-
47
- ```
48
- npm install --save notifications-node-client
49
- ```
50
-
51
- ## Testing JavaScript examples in Markdown
52
-
53
- We automatically test that the JavaScript in the documentation examples matches [our linting standards](https://gds-way.cloudapps.digital/manuals/programming-languages/nodejs/#source-formatting-and-linting). This also catches some issues that could stop an example from running when copied.
54
-
55
- You can fix issues automatically by running:
56
-
57
- ```
58
- npm run test:markdown:standard -- --fix
59
- ```
package/Dockerfile DELETED
@@ -1,17 +0,0 @@
1
- FROM ghcr.io/alphagov/notify/node:18-slim
2
-
3
- ENV DEBIAN_FRONTEND=noninteractive
4
-
5
- RUN \
6
- echo "Install base packages" \
7
- && apt-get update \
8
- && apt-get install -y --no-install-recommends \
9
- awscli \
10
- make \
11
- gnupg \
12
- jq \
13
- && echo "Clean up" \
14
- && rm -rf /var/lib/apt/lists/* /tmp/*
15
-
16
- WORKDIR /var/project
17
- COPY . .
package/Makefile DELETED
@@ -1,42 +0,0 @@
1
- .DEFAULT_GOAL := help
2
- SHELL := /bin/bash
3
-
4
- .PHONY: help
5
- help:
6
- @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
7
-
8
- .PHONY: bootstrap
9
- bootstrap: ## Install build dependencies
10
- npm ci
11
-
12
- .PHONY: build
13
- build: bootstrap ## Build project (dummy task for CI)
14
-
15
- .PHONY: test
16
- test: ## Run tests
17
- npm run check:types
18
- npm test
19
-
20
- .PHONY: integration-test
21
- integration-test: ## Run integration tests
22
- npm test --integration
23
-
24
- .PHONY: bootstrap-with-docker
25
- bootstrap-with-docker: ## Prepare the Docker builder image
26
- docker build -t notifications-node-client .
27
- ./scripts/run_with_docker.sh make bootstrap
28
-
29
- .PHONY: test-with-docker
30
- test-with-docker: ## Run tests inside a Docker container
31
- ./scripts/run_with_docker.sh make test
32
-
33
- .PHONY: integration-test-with-docker
34
- integration-test-with-docker: ## Run integration tests inside a Docker container
35
- ./scripts/run_with_docker.sh make integration-test
36
-
37
- .PHONY: get-client-version
38
- get-client-version: ## Retrieve client version number from source code
39
- @node -p "require('./package.json').version"
40
-
41
- clean:
42
- rm -rf .cache venv
@@ -1,21 +0,0 @@
1
- DOCKER_IMAGE_NAME=notifications-node-client
2
-
3
- source environment.sh
4
-
5
- docker run \
6
- --rm \
7
- -v "`pwd`:/var/project" \
8
- -e NOTIFY_API_URL=${NOTIFY_API_URL} \
9
- -e API_KEY=${API_KEY} \
10
- -e FUNCTIONAL_TEST_NUMBER=${FUNCTIONAL_TEST_NUMBER} \
11
- -e FUNCTIONAL_TEST_EMAIL=${FUNCTIONAL_TEST_EMAIL} \
12
- -e EMAIL_TEMPLATE_ID=${EMAIL_TEMPLATE_ID} \
13
- -e SMS_TEMPLATE_ID=${SMS_TEMPLATE_ID} \
14
- -e LETTER_TEMPLATE_ID=${LETTER_TEMPLATE_ID} \
15
- -e EMAIL_REPLY_TO_ID=${EMAIL_REPLY_TO_ID} \
16
- -e SMS_SENDER_ID=${SMS_SENDER_ID} \
17
- -e API_SENDING_KEY=${API_SENDING_KEY} \
18
- -e INBOUND_SMS_QUERY_KEY=${INBOUND_SMS_QUERY_KEY} \
19
- -it \
20
- ${DOCKER_IMAGE_NAME} \
21
- ${@}
@@ -1,57 +0,0 @@
1
- var argv = require('optimist')
2
- .usage('Usage: $0' +
3
- ' -b [baseUrl]' +
4
- ' -s [notify secret]' +
5
- ' -t [templateId]' +
6
- ' -d [destination (email address or phone number, not needed for letters]' +
7
- ' -p [personalisation (required for letter {"address_line_1": "mrs test", "address_line_2": "1 test street", "postcode": "SW1 1AA"})]' +
8
- ' -m [type (email, sms or letter, default email)]')
9
- .demand(['s', 't'])
10
- .argv,
11
- NotifyClient = require('../client/notification').NotifyClient,
12
- notifyClient,
13
-
14
- baseUrl = argv.b || 'https://api.notifications.service.gov.uk',
15
- secret = argv.s,
16
- templateId = argv.t,
17
- destination = argv.d,
18
- personalisation = argv.p ? JSON.parse(argv.p) : null,
19
- type = argv.m || 'email';
20
-
21
- notifyClient = new NotifyClient(baseUrl, secret);
22
-
23
- switch(type) {
24
-
25
- case 'email':
26
- notifyClient.sendEmail(templateId, destination, personalisation)
27
- .then(function(response) {
28
- console.log('Notify response: ' + JSON.stringify(response));
29
- })
30
- .catch(function(error) {
31
- console.log('Error ' + error);
32
- });
33
- break;
34
-
35
- case 'sms':
36
- notifyClient.sendSms(templateId, String(destination), personalisation)
37
- .then(function(response) {
38
- console.log('Notify response: ' + JSON.stringify(response));
39
- })
40
- .catch(function(error) {
41
- console.log('Error ' + error);
42
- });
43
- break;
44
-
45
- case 'letter':
46
- notifyClient.sendLetter(templateId, personalisation)
47
- .then(function(response) {
48
- console.log('Notify response: ' + JSON.stringify(response));
49
- })
50
- .catch(function(error) {
51
- console.log('Error ' + error);
52
- });
53
- break;
54
-
55
- default:
56
- console.log('Unrecognised notification type');
57
- }