notifications-node-client 8.0.0 → 8.1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 8.1.0 - 2024-05-09
2
+
3
+ * The `sendEmail` function can now be passed `oneClickUnsubscribeURL` as an optional argument.
4
+
1
5
  ## 8.0.0 - 2023-12-27
2
6
 
3
7
  * 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.
@@ -23,10 +23,11 @@ function NotifyClient() {
23
23
  * @param {Object} personalisation
24
24
  * @param {String} reference
25
25
  * @param {String} replyToId
26
+ * @param {String} oneClickUnsubscribeURL
26
27
  *
27
28
  * @returns {Object}
28
29
  */
29
- function createNotificationPayload(type, templateId, to, personalisation, reference, replyToId) {
30
+ function createNotificationPayload(type, templateId, to, personalisation, reference, replyToId, oneClickUnsubscribeURL) {
30
31
 
31
32
  var payload = {
32
33
  template_id: templateId
@@ -53,6 +54,10 @@ function createNotificationPayload(type, templateId, to, personalisation, refere
53
54
  payload.sms_sender_id = replyToId;
54
55
  }
55
56
 
57
+ if (oneClickUnsubscribeURL && type == 'email') {
58
+ payload.one_click_unsubscribe_url = oneClickUnsubscribeURL;
59
+ }
60
+
56
61
  return payload;
57
62
  }
58
63
 
@@ -144,16 +149,17 @@ Object.assign(NotifyClient.prototype, {
144
149
  */
145
150
  sendEmail: function (templateId, emailAddress, options) {
146
151
  options = options || {};
147
- var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId'], options)
152
+ var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId', 'oneClickUnsubscribeURL'], options)
148
153
  if (err) {
149
154
  return Promise.reject(err);
150
155
  }
151
156
  var personalisation = options.personalisation || undefined,
152
157
  reference = options.reference || undefined,
153
- emailReplyToId = options.emailReplyToId || undefined;
158
+ emailReplyToId = options.emailReplyToId || undefined,
159
+ oneClickUnsubscribeURL = options.oneClickUnsubscribeURL || undefined;
154
160
 
155
161
  return this.apiClient.post('/v2/notifications/email',
156
- createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId));
162
+ createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId, oneClickUnsubscribeURL));
157
163
  },
158
164
 
159
165
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifications-node-client",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "homepage": "https://docs.notifications.service.gov.uk/node.html",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,4 +36,3 @@
36
36
  "standard-markdown": "5.0.1"
37
37
  }
38
38
  }
39
-
@@ -25,7 +25,8 @@
25
25
  "properties": {
26
26
  "body": {"type": "string"},
27
27
  "from_email": {"type": "string", "format": "email_address"},
28
- "subject": {"type": "string"}
28
+ "subject": {"type": "string"},
29
+ "one_click_unsubscribe_url": {"type": ["string", "null"], "format": "uri"}
29
30
  },
30
31
  "required": ["body", "from_email", "subject"]
31
32
  },
@@ -36,6 +36,7 @@ describer('notification api with a live service', function () {
36
36
  let letterNotificationId;
37
37
  const personalisation = { name: 'Foo' };
38
38
  const clientRef = 'client-ref';
39
+ const oneClickUnsubscribeURL = 'https://www.example.com';
39
40
  const email = process.env.FUNCTIONAL_TEST_EMAIL;
40
41
  const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER;
41
42
  const letterContact = {
@@ -88,6 +89,22 @@ describer('notification api with a live service', function () {
88
89
  expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
89
90
  response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
90
91
  response.data.content.subject.should.equal('Functional Tests are good');
92
+ should.equal(response.data.content.one_click_unsubscribe_url, null);
93
+ response.data.reference.should.equal(clientRef);
94
+ emailNotificationId = response.data.id;
95
+ })
96
+ });
97
+
98
+ it('send email notification with unsubscribe link', () => {
99
+ var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
100
+ options = {personalisation: personalisation, reference: clientRef, oneClickUnsubscribeURL: oneClickUnsubscribeURL};
101
+
102
+ return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
103
+ response.status.should.equal(201);
104
+ expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
105
+ response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
106
+ response.data.content.subject.should.equal('Functional Tests are good');
107
+ response.data.content.one_click_unsubscribe_url.should.equal(oneClickUnsubscribeURL);
91
108
  response.data.reference.should.equal(clientRef);
92
109
  emailNotificationId = response.data.id;
93
110
  })
@@ -92,6 +92,31 @@ describe('notification api', () => {
92
92
  });
93
93
  });
94
94
 
95
+ it('should send an email with a one click unsubscribe URL', () => {
96
+
97
+ let email = 'me@example.com',
98
+ templateId = '123',
99
+ options = {
100
+ personalisation: {foo: 'bar'},
101
+ oneClickUnsubscribeURL: '456',
102
+ },
103
+ data = {
104
+ template_id: templateId,
105
+ email_address: email,
106
+ personalisation: options.personalisation,
107
+ one_click_unsubscribe_url: options.oneClickUnsubscribeURL
108
+ };
109
+
110
+ notifyAuthNock
111
+ .post('/v2/notifications/email', data)
112
+ .reply(200, {hooray: 'bkbbk'});
113
+
114
+ return notifyClient.sendEmail(templateId, email, options)
115
+ .then((response) => {
116
+ expect(response.status).to.equal(200);
117
+ });
118
+ });
119
+
95
120
  it('should send an email with document upload', () => {
96
121
  let email = 'dom@example.com',
97
122
  templateId = '123',