notifications-node-client 7.0.6 → 8.0.0

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.
@@ -9,7 +9,7 @@
9
9
  - [x] I’ve used the pull request template
10
10
  - [ ] I’ve written unit tests for these changes
11
11
  - [ ] I’ve updated the documentation in
12
- - `DOCUMENTATION.md`
12
+ - [notifications-tech-docs repository](https://github.com/alphagov/notifications-tech-docs/blob/main/source/documentation/client_docs/_node.md)
13
13
  - `CHANGELOG.md`
14
14
  - [ ] I’ve bumped the version number in
15
15
  - `package.json`
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 8.0.0 - 2023-12-27
2
+
3
+ * 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.
4
+ * `filename` (string) - specify the document's filename upon download
5
+ * `confirm_email_before_download` (boolean) - require the user to enter their email address before the file can be downloaded.
6
+ * `retention_period` (string) - how long Notify should make the file available to the user for.
7
+
1
8
  ## 7.0.6 - 2023-11-13
2
9
 
3
10
  * Bump axios from 1.2.6 to 1.6.1
@@ -356,26 +356,18 @@ Object.assign(NotifyClient.prototype, {
356
356
  prepareUpload: function(fileData, options) {
357
357
  let data = {
358
358
  file: _check_and_encode_file(fileData, 2),
359
- is_csv: false,
359
+ filename: null,
360
360
  confirm_email_before_download: null,
361
361
  retention_period: null,
362
362
  }
363
363
 
364
364
  if (options !== undefined) {
365
- if (typeof(options) === 'boolean') {
366
- data.is_csv = options
367
- }
368
- else {
369
- if (options.isCsv !== undefined) {
370
- data.is_csv = options.isCsv;
371
- }
372
-
373
- data.confirm_email_before_download = options.confirmEmailBeforeDownload !== undefined ? options.confirmEmailBeforeDownload : null;
374
- data.retention_period = options.retentionPeriod || null
375
- }
365
+ data.filename = options.filename || null;
366
+ data.confirm_email_before_download = options.confirmEmailBeforeDownload !== undefined ? options.confirmEmailBeforeDownload : null;
367
+ data.retention_period = options.retentionPeriod || null;
376
368
  }
377
369
 
378
- return data
370
+ return data;
379
371
  },
380
372
 
381
373
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifications-node-client",
3
- "version": "7.0.6",
3
+ "version": "8.0.0",
4
4
  "homepage": "https://docs.notifications.service.gov.uk/node.html",
5
5
  "repository": {
6
6
  "type": "git",
@@ -113,16 +113,15 @@ describe('notification api', () => {
113
113
  return notifyClient.sendEmail(templateId, email, options)
114
114
  .then((response) => {
115
115
  expect(response.status).to.equal(200);
116
- expect(response.config.data).to.include('"is_csv":false');
117
116
  });
118
117
  });
119
118
 
120
- it('should send an email with CSV document upload', () => {
119
+ it('should send an email with a custom filename', () => {
121
120
  let email = 'dom@example.com',
122
121
  templateId = '123',
123
122
  options = {
124
123
  personalisation: {documents:
125
- notifyClient.prepareUpload(Buffer.from("a,b"), true)
124
+ notifyClient.prepareUpload(Buffer.from("a,b"), {filename: 'report.csv'})
126
125
  },
127
126
  },
128
127
  data = {
@@ -138,32 +137,7 @@ describe('notification api', () => {
138
137
  return notifyClient.sendEmail(templateId, email, options)
139
138
  .then((response) => {
140
139
  expect(response.status).to.equal(200);
141
- expect(response.config.data).to.include('"is_csv":true');
142
- });
143
- });
144
-
145
- it('should send an email with non CSV document upload', () => {
146
- let email = 'dom@example.com',
147
- templateId = '123',
148
- options = {
149
- personalisation: {documents:
150
- notifyClient.prepareUpload(Buffer.from("%PDF-1.5 testpdf"), false)
151
- },
152
- },
153
- data = {
154
- template_id: templateId,
155
- email_address: email,
156
- personalisation: options.personalisation,
157
- };
158
-
159
- notifyAuthNock
160
- .post('/v2/notifications/email', data)
161
- .reply(200, {hooray: 'bkbbk'});
162
-
163
- return notifyClient.sendEmail(templateId, email, options)
164
- .then((response) => {
165
- expect(response.status).to.equal(200);
166
- expect(response.config.data).to.include('"is_csv":false');
140
+ expect(response.config.data).to.include('"filename":"report.csv"');
167
141
  });
168
142
  });
169
143
 
@@ -194,8 +168,8 @@ describe('notification api', () => {
194
168
  expect(typeof(file)).to.equal('object')
195
169
  expect(Buffer.isBuffer(file)).to.equal(true);
196
170
  expect(
197
- notifyClient.prepareUpload(file, true)
198
- ).contains({file: 'MSwyLDMKYSxiLGMK', is_csv: true})
171
+ notifyClient.prepareUpload(file)
172
+ ).contains({file: 'MSwyLDMKYSxiLGMK'})
199
173
  });
200
174
  it('should accept files as strings (from fs.readFile with an encoding)', () => {
201
175
  let fs = require('fs');
@@ -203,50 +177,36 @@ describe('notification api', () => {
203
177
  expect(typeof(file)).to.equal('string')
204
178
  expect(Buffer.isBuffer(file)).to.equal(false);
205
179
  expect(
206
- notifyClient.prepareUpload(file, true)
207
- ).contains({file: 'MSwyLDMKYSxiLGMK', is_csv: true})
208
- });
209
-
210
- it('should allow isCsv to be set with the old method (directly into options)', () => {
211
- let file = Buffer.alloc(2*1024*1024)
212
- expect(
213
- notifyClient.prepareUpload(file, true)
214
- ).contains({is_csv: true, confirm_email_before_download: null, retention_period: null})
215
- });
216
-
217
- it('should allow isCsv to be set as part of the options object', () => {
218
- let file = Buffer.alloc(2*1024*1024)
219
- expect(
220
- notifyClient.prepareUpload(file, {isCsv: true})
221
- ).contains({is_csv: true, confirm_email_before_download: null, retention_period: null})
222
- });
223
-
224
- it('should imply isCsv=false from empty options', () => {
225
- let file = Buffer.alloc(2*1024*1024)
226
- expect(
227
- notifyClient.prepareUpload(file, {})
228
- ).contains({is_csv: false, confirm_email_before_download: null, retention_period: null})
180
+ notifyClient.prepareUpload(file)
181
+ ).contains({file: 'MSwyLDMKYSxiLGMK'})
229
182
  });
230
183
 
231
184
  it('should allow send a file email confirmation to be disabled', () => {
232
185
  let file = Buffer.alloc(2*1024*1024)
233
186
  expect(
234
187
  notifyClient.prepareUpload(file, {confirmEmailBeforeDownload: false})
235
- ).contains({is_csv: false, confirm_email_before_download: false, retention_period: null})
188
+ ).contains({confirm_email_before_download: false, retention_period: null})
236
189
  });
237
190
 
238
191
  it('should allow send a file email confirmation to be set', () => {
239
192
  let file = Buffer.alloc(2*1024*1024)
240
193
  expect(
241
194
  notifyClient.prepareUpload(file, {confirmEmailBeforeDownload: true})
242
- ).contains({is_csv: false, confirm_email_before_download: true, retention_period: null})
195
+ ).contains({confirm_email_before_download: true, retention_period: null})
243
196
  });
244
197
 
245
198
  it('should allow custom retention periods to be set', () => {
246
199
  let file = Buffer.alloc(2*1024*1024)
247
200
  expect(
248
201
  notifyClient.prepareUpload(file, {retentionPeriod: "52 weeks"})
249
- ).contains({is_csv: false, confirm_email_before_download: null, retention_period: '52 weeks'})
202
+ ).contains({confirm_email_before_download: null, retention_period: '52 weeks'})
203
+ });
204
+
205
+ it('should allow custom filenames to be set', () => {
206
+ let file = Buffer.alloc(2*1024*1024)
207
+ expect(
208
+ notifyClient.prepareUpload(file, {filename: "report.csv"})
209
+ ).contains({confirm_email_before_download: null, filename: "report.csv"})
250
210
  });
251
211
  });
252
212