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.
Files changed (35) hide show
  1. package/client/api_client.js +60 -67
  2. package/client/notification.js +289 -265
  3. package/package.json +13 -3
  4. package/tsconfig.json +18 -0
  5. package/.github/PULL_REQUEST_TEMPLATE.md +0 -18
  6. package/CHANGELOG.md +0 -292
  7. package/CONTRIBUTING.md +0 -59
  8. package/Dockerfile +0 -14
  9. package/Makefile +0 -41
  10. package/scripts/run_with_docker.sh +0 -21
  11. package/scripts/test_send.js +0 -57
  12. package/spec/api_client.js +0 -156
  13. package/spec/authentication.js +0 -32
  14. package/spec/integration/schemas/v1/GET_notifications_return.json +0 -37
  15. package/spec/integration/schemas/v1/POST_notification_return_email.json +0 -27
  16. package/spec/integration/schemas/v1/POST_notification_return_sms.json +0 -26
  17. package/spec/integration/schemas/v1/definitions.json +0 -12
  18. package/spec/integration/schemas/v1/email_notification.json +0 -106
  19. package/spec/integration/schemas/v1/sms_notification.json +0 -104
  20. package/spec/integration/schemas/v2/GET_notification_response.json +0 -50
  21. package/spec/integration/schemas/v2/GET_notifications_response.json +0 -29
  22. package/spec/integration/schemas/v2/GET_received_text_response.json +0 -23
  23. package/spec/integration/schemas/v2/GET_received_texts_response.json +0 -29
  24. package/spec/integration/schemas/v2/GET_template_by_id.json +0 -30
  25. package/spec/integration/schemas/v2/GET_templates_response.json +0 -15
  26. package/spec/integration/schemas/v2/POST_notification_email_response.json +0 -18
  27. package/spec/integration/schemas/v2/POST_notification_letter_response.json +0 -19
  28. package/spec/integration/schemas/v2/POST_notification_precompiled_letter_response.json +0 -19
  29. package/spec/integration/schemas/v2/POST_notification_sms_response.json +0 -18
  30. package/spec/integration/schemas/v2/POST_template_preview.json +0 -14
  31. package/spec/integration/schemas/v2/definitions.json +0 -51
  32. package/spec/integration/test.js +0 -415
  33. package/spec/integration/test_files/one_page_pdf.pdf +0 -0
  34. package/spec/notification.js +0 -633
  35. package/spec/test_files/simple.csv +0 -2
@@ -4,13 +4,12 @@ var defaultRestClient = require('axios').default,
4
4
  version = require('../package.json').version;
5
5
 
6
6
  /**
7
- * @param urlBase
8
- * @param serviceId
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
- Object.assign(ApiClient.prototype, {
60
-
61
- /**
62
- *
63
- * @param {string} path
64
- *
65
- * @returns {Promise}
66
- */
67
- get: function(path, additionalOptions) {
68
- var options = {
69
- method: 'get',
70
- url: this.urlBase + path,
71
- headers: {
72
- 'Authorization': 'Bearer ' + createToken('GET', path, this.apiKeyId, this.serviceId),
73
- 'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
74
- }
75
- };
76
- Object.assign(options, additionalOptions)
77
- if(this.proxy !== null) options.proxy = this.proxy;
78
-
79
- return this.restClient(options);
80
- },
81
-
82
- /**
83
- *
84
- * @param {string} path
85
- * @param {object} data
86
- *
87
- * @returns {Promise}
88
- */
89
- post: function(path, data){
90
- var options = {
91
- method: 'post',
92
- url: this.urlBase + path,
93
- data: data,
94
- headers: {
95
- 'Authorization': 'Bearer ' + createToken('GET', path, this.apiKeyId, this.serviceId),
96
- 'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
97
- }
98
- };
99
-
100
- if(this.proxy !== null) options.proxy = this.proxy;
101
-
102
- return this.restClient(options);
103
- },
104
-
105
- /**
106
- *
107
- * @param {object} an axios proxy config
108
- */
109
- setProxy: function(proxyConfig){
110
- this.proxy = proxyConfig
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;