notifications-node-client 8.2.1 → 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.
- package/client/api_client.js +60 -67
- package/client/notification.js +289 -265
- package/package.json +13 -3
- package/tsconfig.json +18 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -18
- package/CHANGELOG.md +0 -292
- package/CONTRIBUTING.md +0 -59
- package/Dockerfile +0 -14
- package/Makefile +0 -41
- package/scripts/run_with_docker.sh +0 -21
- package/scripts/test_send.js +0 -57
- package/spec/api_client.js +0 -156
- package/spec/authentication.js +0 -32
- package/spec/integration/schemas/v1/GET_notifications_return.json +0 -37
- package/spec/integration/schemas/v1/POST_notification_return_email.json +0 -27
- package/spec/integration/schemas/v1/POST_notification_return_sms.json +0 -26
- package/spec/integration/schemas/v1/definitions.json +0 -12
- package/spec/integration/schemas/v1/email_notification.json +0 -106
- package/spec/integration/schemas/v1/sms_notification.json +0 -104
- package/spec/integration/schemas/v2/GET_notification_response.json +0 -50
- package/spec/integration/schemas/v2/GET_notifications_response.json +0 -29
- package/spec/integration/schemas/v2/GET_received_text_response.json +0 -23
- package/spec/integration/schemas/v2/GET_received_texts_response.json +0 -29
- package/spec/integration/schemas/v2/GET_template_by_id.json +0 -30
- package/spec/integration/schemas/v2/GET_templates_response.json +0 -15
- package/spec/integration/schemas/v2/POST_notification_email_response.json +0 -18
- package/spec/integration/schemas/v2/POST_notification_letter_response.json +0 -19
- package/spec/integration/schemas/v2/POST_notification_precompiled_letter_response.json +0 -19
- package/spec/integration/schemas/v2/POST_notification_sms_response.json +0 -18
- package/spec/integration/schemas/v2/POST_template_preview.json +0 -14
- package/spec/integration/schemas/v2/definitions.json +0 -51
- package/spec/integration/test.js +0 -415
- package/spec/integration/test_files/one_page_pdf.pdf +0 -0
- package/spec/notification.js +0 -633
- package/spec/test_files/simple.csv +0 -2
package/client/api_client.js
CHANGED
|
@@ -4,13 +4,12 @@ var defaultRestClient = require('axios').default,
|
|
|
4
4
|
version = require('../package.json').version;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param apiKeyId
|
|
10
|
-
*
|
|
7
|
+
* @param {string} apiKeyOrUrl - API key (1 arg), or base URL (2-3 args)
|
|
8
|
+
* @param {string} [serviceIdOrApiKey] - API key (2 args), or service ID (3 args)
|
|
9
|
+
* @param {string} [apiKeyId] - API key (3 args)
|
|
11
10
|
* @constructor
|
|
12
11
|
*/
|
|
13
|
-
function ApiClient() {
|
|
12
|
+
function ApiClient(apiKeyOrUrl, serviceIdOrApiKey, apiKeyId) {
|
|
14
13
|
|
|
15
14
|
this.proxy = null;
|
|
16
15
|
this.restClient = defaultRestClient;
|
|
@@ -56,67 +55,61 @@ function createToken(requestMethod, requestPath, apiKeyId, serviceId) {
|
|
|
56
55
|
return createGovukNotifyToken(requestMethod, requestPath, apiKeyId, serviceId);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* @param {object} an axios instance
|
|
116
|
-
*/
|
|
117
|
-
setClient: function(restClient){
|
|
118
|
-
this.restClient = restClient;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} path
|
|
60
|
+
* @param {import('axios').AxiosRequestConfig} [additionalOptions]
|
|
61
|
+
* @returns {Promise<import('axios').AxiosResponse>}
|
|
62
|
+
*/
|
|
63
|
+
ApiClient.prototype.get = function(path, additionalOptions) {
|
|
64
|
+
var options = {
|
|
65
|
+
method: 'get',
|
|
66
|
+
url: this.urlBase + path,
|
|
67
|
+
headers: {
|
|
68
|
+
'Authorization': 'Bearer ' + createToken('GET', path, this.apiKeyId, this.serviceId),
|
|
69
|
+
'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
Object.assign(options, additionalOptions)
|
|
73
|
+
if(this.proxy !== null) options.proxy = this.proxy;
|
|
74
|
+
|
|
75
|
+
return this.restClient(options);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} path
|
|
80
|
+
* @param {object} data
|
|
81
|
+
* @returns {Promise<import('axios').AxiosResponse>}
|
|
82
|
+
*/
|
|
83
|
+
ApiClient.prototype.post = function(path, data){
|
|
84
|
+
var options = {
|
|
85
|
+
method: 'post',
|
|
86
|
+
url: this.urlBase + path,
|
|
87
|
+
data: data,
|
|
88
|
+
headers: {
|
|
89
|
+
'Authorization': 'Bearer ' + createToken('GET', path, this.apiKeyId, this.serviceId),
|
|
90
|
+
'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if(this.proxy !== null) options.proxy = this.proxy;
|
|
95
|
+
|
|
96
|
+
return this.restClient(options);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {import('axios').AxiosProxyConfig} proxyConfig
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
ApiClient.prototype.setProxy = function(proxyConfig){
|
|
104
|
+
this.proxy = proxyConfig
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {import('axios').AxiosInstance} restClient
|
|
109
|
+
* @returns {void}
|
|
110
|
+
*/
|
|
111
|
+
ApiClient.prototype.setClient = function(restClient){
|
|
112
|
+
this.restClient = restClient;
|
|
113
|
+
};
|
|
121
114
|
|
|
122
115
|
module.exports = ApiClient;
|