notifications-node-client 8.1.0 → 8.2.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 8.2.1 - 2024-07-03
|
|
2
|
+
|
|
3
|
+
* Fix a bug where an internal API client function isn't being exposed in the library.
|
|
4
|
+
|
|
5
|
+
## 8.2.0 - 2024-05-17
|
|
6
|
+
|
|
7
|
+
* Add support for providing a custom underlying Axios client via `setClient`.
|
|
8
|
+
|
|
1
9
|
## 8.1.0 - 2024-05-09
|
|
2
10
|
|
|
3
11
|
* The `sendEmail` function can now be passed `oneClickUnsubscribeURL` as an optional argument.
|
package/client/api_client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var defaultRestClient = require('axios').default,
|
|
2
2
|
createGovukNotifyToken = require('../client/authentication.js'),
|
|
3
3
|
notifyProductionAPI = 'https://api.notifications.service.gov.uk',
|
|
4
4
|
version = require('../package.json').version;
|
|
@@ -13,6 +13,7 @@ var restClient = require('axios').default,
|
|
|
13
13
|
function ApiClient() {
|
|
14
14
|
|
|
15
15
|
this.proxy = null;
|
|
16
|
+
this.restClient = defaultRestClient;
|
|
16
17
|
|
|
17
18
|
if (arguments.length === 1) {
|
|
18
19
|
this.urlBase = notifyProductionAPI;
|
|
@@ -75,7 +76,7 @@ Object.assign(ApiClient.prototype, {
|
|
|
75
76
|
Object.assign(options, additionalOptions)
|
|
76
77
|
if(this.proxy !== null) options.proxy = this.proxy;
|
|
77
78
|
|
|
78
|
-
return restClient(options);
|
|
79
|
+
return this.restClient(options);
|
|
79
80
|
},
|
|
80
81
|
|
|
81
82
|
/**
|
|
@@ -98,7 +99,7 @@ Object.assign(ApiClient.prototype, {
|
|
|
98
99
|
|
|
99
100
|
if(this.proxy !== null) options.proxy = this.proxy;
|
|
100
101
|
|
|
101
|
-
return restClient(options);
|
|
102
|
+
return this.restClient(options);
|
|
102
103
|
},
|
|
103
104
|
|
|
104
105
|
/**
|
|
@@ -107,6 +108,14 @@ Object.assign(ApiClient.prototype, {
|
|
|
107
108
|
*/
|
|
108
109
|
setProxy: function(proxyConfig){
|
|
109
110
|
this.proxy = proxyConfig
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {object} an axios instance
|
|
116
|
+
*/
|
|
117
|
+
setClient: function(restClient){
|
|
118
|
+
this.restClient = restClient;
|
|
110
119
|
}
|
|
111
120
|
});
|
|
112
121
|
|
package/client/notification.js
CHANGED
|
@@ -352,6 +352,14 @@ Object.assign(NotifyClient.prototype, {
|
|
|
352
352
|
this.apiClient.setProxy(proxyConfig);
|
|
353
353
|
},
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param {object} an axios instance
|
|
358
|
+
*/
|
|
359
|
+
setClient: function(client) {
|
|
360
|
+
this.apiClient.setClient(client);
|
|
361
|
+
},
|
|
362
|
+
|
|
355
363
|
/**
|
|
356
364
|
*
|
|
357
365
|
* @param {Buffer} fileData
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notifications-node-client",
|
|
3
|
-
"version": "8.1
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"homepage": "https://docs.notifications.service.gov.uk/node.html",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,19 +20,20 @@
|
|
|
20
20
|
"author": "GDS developers",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"axios": "^1.7.2",
|
|
24
|
+
"jsonwebtoken": "^9.0.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"chai": "4.
|
|
27
|
+
"chai": "4.3.4",
|
|
28
28
|
"chai-as-promised": "7.1.1",
|
|
29
|
-
"chai-json-schema": "1.5.0",
|
|
30
29
|
"chai-bytes": "0.1.2",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
30
|
+
"chai-json-schema": "1.5.1",
|
|
31
|
+
"jsonschema": "1.4.1",
|
|
32
|
+
"mocha": "10.6.0",
|
|
33
|
+
"mockdate": "3.0.5",
|
|
34
34
|
"nock": "9.2.6",
|
|
35
35
|
"optimist": "0.6.1",
|
|
36
|
-
"
|
|
36
|
+
"sinon": "^18.0.0",
|
|
37
|
+
"standard-markdown": "7.1.0"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/spec/api_client.js
CHANGED
|
@@ -3,8 +3,9 @@ var expect = require('chai').expect,
|
|
|
3
3
|
ApiClient = require('../client/api_client.js'),
|
|
4
4
|
nock = require('nock'),
|
|
5
5
|
createGovukNotifyToken = require('../client/authentication.js'),
|
|
6
|
-
version = require('../package.json').version
|
|
7
|
-
|
|
6
|
+
version = require('../package.json').version,
|
|
7
|
+
axios = require('axios'),
|
|
8
|
+
sinon = require('sinon');
|
|
8
9
|
|
|
9
10
|
describe('api client', function () {
|
|
10
11
|
|
|
@@ -117,4 +118,39 @@ describe('api client', function () {
|
|
|
117
118
|
done();
|
|
118
119
|
});
|
|
119
120
|
});
|
|
121
|
+
|
|
122
|
+
it('should use the custom Axios client when set', function (done) {
|
|
123
|
+
var urlBase = 'https://api.notifications.service.gov.uk',
|
|
124
|
+
path = '/email',
|
|
125
|
+
body = {
|
|
126
|
+
'body': 'body text'
|
|
127
|
+
},
|
|
128
|
+
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
|
|
129
|
+
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
|
|
130
|
+
|
|
131
|
+
var customClientStub = sinon.stub().resolves({ data: body });
|
|
132
|
+
|
|
133
|
+
var apiClient = new ApiClient(serviceId, apiKeyId);
|
|
134
|
+
apiClient.setClient(customClientStub);
|
|
135
|
+
|
|
136
|
+
nock(urlBase, {
|
|
137
|
+
reqheaders: {
|
|
138
|
+
'Authorization': 'Bearer ' + createGovukNotifyToken('GET', path, apiKeyId, serviceId),
|
|
139
|
+
'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
.get(path)
|
|
143
|
+
.reply(200, body);
|
|
144
|
+
|
|
145
|
+
apiClient.get(path)
|
|
146
|
+
.then(function (response) {
|
|
147
|
+
expect(response.data).to.deep.equal(body);
|
|
148
|
+
expect(customClientStub.calledOnce).to.be.true;
|
|
149
|
+
expect(customClientStub.args[0][0].url).to.equal(urlBase + path);
|
|
150
|
+
expect(customClientStub.args[0][0].headers['Authorization']).to.equal('Bearer ' + createGovukNotifyToken('GET', path, apiKeyId, serviceId));
|
|
151
|
+
expect(customClientStub.args[0][0].headers['User-Agent']).to.equal('NOTIFY-API-NODE-CLIENT/' + version);
|
|
152
|
+
done();
|
|
153
|
+
})
|
|
154
|
+
.catch(done);
|
|
155
|
+
});
|
|
120
156
|
});
|
|
@@ -28,7 +28,19 @@
|
|
|
28
28
|
"scheduled_for": {"oneOf":[
|
|
29
29
|
{"$ref": "definitions.json#/datetime"},
|
|
30
30
|
{"type": "null"}
|
|
31
|
-
]}
|
|
31
|
+
]},
|
|
32
|
+
"cost_in_pounds": {"type": ["number", "null"]},
|
|
33
|
+
"is_cost_data_ready": {"type": "boolean"},
|
|
34
|
+
"cost_details": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"properties": {
|
|
37
|
+
"billable_sms_fragments": {"type": ["integer", "null"]},
|
|
38
|
+
"international_rate_multiplier": {"type": ["number", "null"]},
|
|
39
|
+
"sms_rate": {"type": ["number", "null"]},
|
|
40
|
+
"billable_sheets_of_paper": {"type": ["integer", "null"]},
|
|
41
|
+
"postage": {"type": ["string", "null"]}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
32
44
|
},
|
|
33
45
|
"required": [
|
|
34
46
|
"id", "reference", "email_address", "phone_number",
|