notifications-node-client 8.3.0 → 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 (34) hide show
  1. package/package.json +7 -2
  2. package/.dockerignore +0 -1
  3. package/.github/PULL_REQUEST_TEMPLATE.md +0 -18
  4. package/CHANGELOG.md +0 -297
  5. package/CONTRIBUTING.md +0 -59
  6. package/Dockerfile +0 -17
  7. package/Makefile +0 -42
  8. package/scripts/run_with_docker.sh +0 -21
  9. package/scripts/test_send.js +0 -57
  10. package/spec/api_client.js +0 -156
  11. package/spec/authentication.js +0 -32
  12. package/spec/integration/schemas/v1/GET_notifications_return.json +0 -37
  13. package/spec/integration/schemas/v1/POST_notification_return_email.json +0 -27
  14. package/spec/integration/schemas/v1/POST_notification_return_sms.json +0 -26
  15. package/spec/integration/schemas/v1/definitions.json +0 -12
  16. package/spec/integration/schemas/v1/email_notification.json +0 -106
  17. package/spec/integration/schemas/v1/sms_notification.json +0 -104
  18. package/spec/integration/schemas/v2/GET_notification_response.json +0 -50
  19. package/spec/integration/schemas/v2/GET_notifications_response.json +0 -29
  20. package/spec/integration/schemas/v2/GET_received_text_response.json +0 -23
  21. package/spec/integration/schemas/v2/GET_received_texts_response.json +0 -29
  22. package/spec/integration/schemas/v2/GET_template_by_id.json +0 -30
  23. package/spec/integration/schemas/v2/GET_templates_response.json +0 -15
  24. package/spec/integration/schemas/v2/POST_notification_email_response.json +0 -18
  25. package/spec/integration/schemas/v2/POST_notification_letter_response.json +0 -19
  26. package/spec/integration/schemas/v2/POST_notification_precompiled_letter_response.json +0 -19
  27. package/spec/integration/schemas/v2/POST_notification_sms_response.json +0 -18
  28. package/spec/integration/schemas/v2/POST_template_preview.json +0 -14
  29. package/spec/integration/schemas/v2/definitions.json +0 -51
  30. package/spec/integration/test.js +0 -415
  31. package/spec/integration/test_files/one_page_pdf.pdf +0 -0
  32. package/spec/notification.js +0 -633
  33. package/spec/test_files/simple.csv +0 -2
  34. package/spec/types-test.ts +0 -153
@@ -1,156 +0,0 @@
1
- var expect = require('chai').expect,
2
- MockDate = require('mockdate'),
3
- ApiClient = require('../client/api_client.js'),
4
- nock = require('nock'),
5
- createGovukNotifyToken = require('../client/authentication.js'),
6
- version = require('../package.json').version,
7
- axios = require('axios'),
8
- sinon = require('sinon');
9
-
10
- describe('api client', function () {
11
-
12
- beforeEach(function() {
13
- MockDate.set(1234567890000);
14
- });
15
-
16
- afterEach(function() {
17
- MockDate.reset();
18
- });
19
-
20
- it('should make a get request with correct headers', function (done) {
21
-
22
- var urlBase = 'https://api.notifications.service.gov.uk',
23
- path = '/email',
24
- body = {
25
- 'body': 'body text'
26
- },
27
- serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
28
- apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
29
-
30
- [
31
- new ApiClient(serviceId, apiKeyId),
32
- new ApiClient(urlBase, serviceId, apiKeyId),
33
- new ApiClient(urlBase, 'key_name' + '-' + serviceId + '-' + apiKeyId),
34
- new ApiClient('key_name' + ':' + serviceId + ':' + apiKeyId),
35
- ].forEach(function(client, index, clients) {
36
-
37
- nock(urlBase, {
38
- reqheaders: {
39
- 'Authorization': 'Bearer ' + createGovukNotifyToken('GET', path, apiKeyId, serviceId),
40
- 'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
41
- }
42
- })
43
- .get(path)
44
- .reply(200, body);
45
-
46
- client.get(path)
47
- .then(function (response) {
48
- expect(response.data).to.deep.equal(body);
49
- if (index == clients.length - 1) done();
50
- });
51
-
52
- });
53
-
54
- });
55
-
56
- it('should make a post request with correct headers', function (done) {
57
-
58
- var urlBase = 'http://localhost',
59
- path = '/email',
60
- data = {
61
- 'data': 'qwjjs'
62
- },
63
- serviceId = 123,
64
- apiKeyId = 'SECRET',
65
- apiClient = new ApiClient(urlBase, serviceId, apiKeyId);
66
-
67
- nock(urlBase, {
68
- reqheaders: {
69
- 'Authorization': 'Bearer ' + createGovukNotifyToken('POST', path, apiKeyId, serviceId),
70
- 'User-Agent': 'NOTIFY-API-NODE-CLIENT/' + version
71
- }
72
- })
73
- .post(path, data)
74
- .reply(200, {"hooray": "bkbbk"});
75
-
76
- apiClient = new ApiClient(urlBase, serviceId, apiKeyId);
77
- apiClient.post(path, data)
78
- .then(function (response) {
79
- expect(response.status).to.equal(200);
80
- done();
81
- });
82
- });
83
-
84
- it('should direct get requests through the proxy when set', function (done) {
85
- var urlBase = 'https://api.notifications.service.gov.uk',
86
- proxyConfig = { host: 'addressofmyproxy.test', protocol: 'http'},
87
- path = '/email',
88
- apiClient = new ApiClient(urlBase, 'apiKey');
89
-
90
- nock("http://" + proxyConfig.host)
91
- .get(urlBase + path)
92
- .reply(200, 'test');
93
-
94
- apiClient.setProxy(proxyConfig);
95
- apiClient.get(path)
96
- .then(function (response) {
97
- expect(response.status).to.equal(200);
98
- expect(response.config.proxy).to.eql(proxyConfig);
99
- done();
100
- });
101
- });
102
-
103
- it('should direct post requests through the proxy when set', function (done) {
104
- var urlBase = 'https://api.notifications.service.gov.uk',
105
- proxyConfig = { host: 'addressofmyproxy.test', protocol: 'http'},
106
- path = '/email',
107
- apiClient = new ApiClient(urlBase, 'apiKey');
108
-
109
- nock("http://" + proxyConfig.host)
110
- .post(urlBase + path)
111
- .reply(200, 'test');
112
-
113
- apiClient.setProxy(proxyConfig);
114
- apiClient.post(path)
115
- .then(function (response) {
116
- expect(response.status).to.equal(200);
117
- expect(response.config.proxy).to.eql(proxyConfig);
118
- done();
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
- });
156
- });
@@ -1,32 +0,0 @@
1
- var expect = require('chai').expect,
2
- MockDate = require('mockdate'),
3
- jwt = require('jsonwebtoken'),
4
- createGovukNotifyToken = require('../client/authentication.js');
5
-
6
-
7
- describe('Authentication', function() {
8
-
9
- beforeEach(function() {
10
- MockDate.set(1234567890000);
11
- });
12
-
13
- afterEach(function() {
14
- MockDate.reset();
15
- });
16
-
17
- describe('tokens', function() {
18
-
19
- it('can be generated and decoded', function() {
20
-
21
- var token = createGovukNotifyToken("POST", "/v2/notifications/sms", "SECRET", 123),
22
- decoded = jwt.verify(token, 'SECRET');
23
-
24
- expect(token).to.equal('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOjEyMywiaWF0IjoxMjM0NTY3ODkwfQ.18aBKSLffjbX_TLmosB_qYgW9EkWIQpBgWy7GpiKg6o');
25
- expect(decoded.iss).to.equal(123);
26
- expect(decoded.iat).to.equal(1234567890);
27
-
28
- });
29
-
30
- });
31
-
32
- });
@@ -1,37 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "GET notification return schema - for sms notifications",
4
- "type" : "object",
5
- "properties": {
6
- "notifications": {
7
- "type": "array",
8
- "items": {
9
- "oneOf": [
10
- {"$ref": "sms_notification.json"},
11
- {"$ref": "email_notification.json"}
12
- ]
13
- }
14
- },
15
- "links": {
16
- "type": "object",
17
- "properties" : {
18
- "prev" : {
19
- "type" : "string"
20
- },
21
- "next" : {
22
- "type" : "string"
23
- },
24
- "last": {
25
- "type" : "string"
26
- }
27
- },
28
- "additionalProperties": false
29
- },
30
- "page_size": {"type": "number"},
31
- "total": {"type": "number"}
32
- },
33
- "additionalProperties": false,
34
- "required": [
35
- "notifications", "links", "page_size", "total"
36
- ]
37
- }
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "POST notification return schema - for email notifications",
4
- "type" : "object",
5
- "properties": {
6
- "data": {
7
- "type": "object",
8
- "properties": {
9
- "notification": {
10
- "type": "object",
11
- "properties": {
12
- "id": {"$ref": "definitions.json#/uuid"}
13
- },
14
- "additionalProperties": false,
15
- "required": ["id"]
16
- },
17
- "body": {"type": "string"},
18
- "template_version": {"type": "number"},
19
- "subject": {"type": "string"}
20
- },
21
- "additionalProperties": false,
22
- "required": ["notification", "body", "template_version", "subject"]
23
- }
24
- },
25
- "additionalProperties": false,
26
- "required": ["data"]
27
- }
@@ -1,26 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "POST notification return schema - for sms notifications",
4
- "type" : "object",
5
- "properties": {
6
- "data": {
7
- "type": "object",
8
- "properties": {
9
- "notification": {
10
- "type": "object",
11
- "properties": {
12
- "id": {"$ref": "definitions.json#/uuid"}
13
- },
14
- "additionalProperties": false,
15
- "required": ["id"]
16
- },
17
- "body": {"type": "string"},
18
- "template_version": {"type": "number"}
19
- },
20
- "additionalProperties": false,
21
- "required": ["notification", "body", "template_version"]
22
- }
23
- },
24
- "additionalProperties": false,
25
- "required": ["data"]
26
- }
@@ -1,12 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "Common definitions - usage example: {'$ref': 'definitions.json#/uuid'} (swap quotes for double quotes)",
4
- "uuid": {
5
- "type": "string",
6
- "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
7
- },
8
- "datetime": {
9
- "type": "string",
10
- "format": "date-time"
11
- }
12
- }
@@ -1,106 +0,0 @@
1
- {
2
- "description": "Single email notification schema - as returned by GET /notification and GET /notification/{}",
3
- "type": "object",
4
- "properties": {
5
- "id": {"$ref": "definitions.json#/uuid"},
6
- "to": {"type": "string", "format": "email"},
7
- "job_row_number": {"oneOf":[
8
- {"type": "number"},
9
- {"type": "null"}
10
- ]},
11
- "template_version": {"type": "number"},
12
- "billable_units": {"type": "number"},
13
- "notification_type": {
14
- "type": "string",
15
- "enum": ["email"]
16
- },
17
- "created_at": {"$ref": "definitions.json#/datetime"},
18
- "sent_at": {"oneOf":[
19
- {"$ref": "definitions.json#/datetime"},
20
- {"type": "null"}
21
- ]},
22
- "sent_by": {"oneOf":[
23
- {"type": "string"},
24
- {"type": "null"}
25
- ]},
26
- "updated_at": {"oneOf":[
27
- {"$ref": "definitions.json#/datetime"},
28
- {"type": "null"}
29
- ]},
30
- "status": {
31
- "type": "string",
32
- "enum": [
33
- "created",
34
- "sending",
35
- "delivered",
36
- "pending",
37
- "failed",
38
- "technical-failure",
39
- "temporary-failure",
40
- "permanent-failure"
41
- ]
42
- },
43
- "reference": {"oneOf":[
44
- {"type": "string"},
45
- {"type": "null"}
46
- ]},
47
- "template": {
48
- "type": "object",
49
- "properties": {
50
- "id": {"$ref": "definitions.json#/uuid"},
51
- "name": {"type": "string"},
52
- "template_type": {
53
- "type": "string",
54
- "enum": ["email"]
55
- },
56
- "version": {"type": "number"}
57
- },
58
- "additionalProperties": false,
59
- "required": ["id", "name", "template_type", "version"]
60
- },
61
- "service": {"$ref": "definitions.json#/uuid"},
62
- "job": {
63
- "oneOf": [
64
- {
65
- "type": "object",
66
- "properties": {
67
- "id": {"$ref": "definitions.json#/uuid"},
68
- "original_file_name": {"type": "string"}
69
- },
70
- "additionalProperties": false,
71
- "required": ["id", "original_file_name"]
72
- },
73
- {"type": "null"}
74
- ]
75
- },
76
- "api_key": {"oneOf":[
77
- {"$ref": "definitions.json#/uuid"},
78
- {"type": "null"}
79
- ]},
80
- "body": {"type": "string"},
81
- "content_char_count": {"type": "null"},
82
- "subject": {"type": "string"}
83
- },
84
- "additionalProperties": false,
85
- "required": [
86
- "id",
87
- "to",
88
- "job_row_number",
89
- "template_version",
90
- "billable_units",
91
- "notification_type",
92
- "created_at",
93
- "sent_at",
94
- "sent_by",
95
- "updated_at",
96
- "status",
97
- "reference",
98
- "template",
99
- "service",
100
- "job",
101
- "api_key",
102
- "body",
103
- "content_char_count",
104
- "subject"
105
- ]
106
- }
@@ -1,104 +0,0 @@
1
- {
2
- "description": "Single sms notification schema - as returned by GET /notification and GET /notification/{}",
3
- "type": "object",
4
- "properties": {
5
- "id": {"$ref": "definitions.json#/uuid"},
6
- "to": {"type": "string"},
7
- "job_row_number": {"oneOf":[
8
- {"type": "number"},
9
- {"type": "null"}
10
- ]},
11
- "template_version": {"type": "number"},
12
- "billable_units": {"type": "number"},
13
- "notification_type": {
14
- "type": "string",
15
- "enum": ["sms"]
16
- },
17
- "created_at": {"$ref": "definitions.json#/datetime"},
18
- "sent_at": {"oneOf":[
19
- {"$ref": "definitions.json#/datetime"},
20
- {"type": "null"}
21
- ]},
22
- "sent_by": {"oneOf":[
23
- {"type": "string"},
24
- {"type": "null"}
25
- ]},
26
- "updated_at": {"oneOf":[
27
- {"$ref": "definitions.json#/datetime"},
28
- {"type": "null"}
29
- ]},
30
- "status": {
31
- "type": "string",
32
- "enum": [
33
- "created",
34
- "sending",
35
- "delivered",
36
- "pending",
37
- "failed",
38
- "technical-failure",
39
- "temporary-failure",
40
- "permanent-failure"
41
- ]
42
- },
43
- "reference": {"oneOf":[
44
- {"type": "string"},
45
- {"type": "null"}
46
- ]},
47
- "template": {
48
- "type": "object",
49
- "properties": {
50
- "id": {"$ref": "definitions.json#/uuid"},
51
- "name": {"type": "string"},
52
- "template_type": {
53
- "type": "string",
54
- "enum": ["sms"]
55
- },
56
- "version": {"type": "number"}
57
- },
58
- "additionalProperties": false,
59
- "required": ["id", "name", "template_type", "version"]
60
- },
61
- "service": {"$ref": "definitions.json#/uuid"},
62
- "job": {
63
- "oneOf": [
64
- {
65
- "type": "object",
66
- "properties": {
67
- "id": {"$ref": "definitions.json#/uuid"},
68
- "original_file_name": {"type": "string"}
69
- },
70
- "additionalProperties": false,
71
- "required": ["id", "original_file_name"]
72
- },
73
- {"type": "null"}
74
- ]
75
- },
76
- "api_key": {"oneOf":[
77
- {"$ref": "definitions.json#/uuid"},
78
- {"type": "null"}
79
- ]},
80
- "body": {"type": "string"},
81
- "content_char_count": {"type": "number"}
82
- },
83
- "additionalProperties": false,
84
- "required": [
85
- "id",
86
- "to",
87
- "job_row_number",
88
- "template_version",
89
- "billable_units",
90
- "notification_type",
91
- "created_at",
92
- "sent_at",
93
- "sent_by",
94
- "updated_at",
95
- "status",
96
- "reference",
97
- "template",
98
- "service",
99
- "job",
100
- "api_key",
101
- "body",
102
- "content_char_count"
103
- ]
104
- }
@@ -1,50 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema#",
3
- "description": "GET notification response schema",
4
- "type": "object",
5
- "title": "response v2/notification",
6
- "properties": {
7
- "id": {"$ref": "definitions.json#/uuid"},
8
- "reference": {"type": ["string", "null"]},
9
- "email_address": {"type": ["string", "null"]},
10
- "phone_number": {"type": ["string", "null"]},
11
- "line_1": {"type": ["string", "null"]},
12
- "line_2": {"type": ["string", "null"]},
13
- "line_3": {"type": ["string", "null"]},
14
- "line_4": {"type": ["string", "null"]},
15
- "line_5": {"type": ["string", "null"]},
16
- "line_6": {"type": ["string", "null"]},
17
- "postcode": {"type": ["string", "null"]},
18
- "postage": {"type": ["string", "null"]},
19
- "type": {"enum": ["sms", "letter", "email"]},
20
- "status": {"type": "string"},
21
- "template": {"$ref": "definitions.json#/template"},
22
- "body": {"type": "string"},
23
- "subject": {"type": ["string", "null"]},
24
- "created_at": {"type": "string"},
25
- "created_by_name": {"type": ["string", "null"]},
26
- "sent_at": {"type": ["string", "null"]},
27
- "completed_at": {"type": ["string", "null"]},
28
- "scheduled_for": {"oneOf":[
29
- {"$ref": "definitions.json#/datetime"},
30
- {"type": "null"}
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
- }
44
- },
45
- "required": [
46
- "id", "reference", "email_address", "phone_number",
47
- "line_1", "line_2", "line_3", "line_4", "line_5", "line_6", "postcode",
48
- "type", "status", "template", "created_at", "created_by_name", "sent_at", "completed_at"
49
- ]
50
- }
@@ -1,29 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema#",
3
- "description": "GET list of notifications response schema",
4
- "type": "object",
5
- "properties": {
6
- "notifications": {
7
- "type": "array",
8
- "items": {
9
- "type": "object",
10
- "$ref": "notification.json"
11
- }
12
- },
13
- "links": {
14
- "type": "object",
15
- "properties": {
16
- "current": {
17
- "type": "string"
18
- },
19
- "next": {
20
- "type": "string"
21
- }
22
- },
23
- "additionalProperties": false,
24
- "required": ["current"]
25
- }
26
- },
27
- "additionalProperties": false,
28
- "required": ["notifications", "links"]
29
- }
@@ -1,23 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "GET inbound sms schema response",
4
- "type": "object",
5
- "title": "GET response v2/inbound_sms",
6
- "properties": {
7
- "user_number": {"type": "string"},
8
- "created_at": {
9
- "format": "date-time",
10
- "type": "string",
11
- "description": "Date+time created at"
12
- },
13
- "service_id": {"$ref": "definitions.json#/uuid"},
14
- "id": {"$ref": "definitions.json#/uuid"},
15
- "notify_number": {"type": "string"},
16
- "content": {"type": "string"}
17
- },
18
- "required": [
19
- "id", "user_number", "created_at", "service_id",
20
- "notify_number", "content"
21
- ],
22
- "additionalProperties": false
23
- }
@@ -1,29 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "GET list of inbound sms response schema",
4
- "type": "object",
5
- "properties": {
6
- "received_text_messages": {
7
- "type": "array",
8
- "items": {
9
- "type": "object",
10
- "$ref": "receivedText.json"
11
- }
12
- },
13
- "links": {
14
- "type": "object",
15
- "properties": {
16
- "current": {
17
- "type": "string"
18
- },
19
- "next": {
20
- "type": "string"
21
- }
22
- },
23
- "additionalProperties": false,
24
- "required": ["current"]
25
- }
26
- },
27
- "required": ["received_text_messages", "links"],
28
- "additionalProperties": false
29
- }
@@ -1,30 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "description": "GET template by id schema response",
4
- "type": "object",
5
- "title": "reponse v2/template",
6
- "properties": {
7
- "id": {"$ref": "definitions.json#/uuid"},
8
- "name": {"type": "string"},
9
- "type": {"enum": ["sms", "email", "letter"] },
10
- "created_at": {
11
- "format": "date-time",
12
- "type": "string",
13
- "description": "Date+time created"
14
- },
15
- "updated_at": {
16
- "format": "date-time",
17
- "type": ["string", "null"],
18
- "description": "Date+time updated"
19
- },
20
- "created_by": {"type": "string"},
21
- "version": {"type": "integer"},
22
- "body": {"type": "string"},
23
- "subject": {"type": ["string", "null"]},
24
- "letter_contact_block": {"type": ["string", "null"]}
25
- },
26
- "required": [
27
- "id", "name", "type", "created_at", "updated_at", "version", "created_by",
28
- "body", "letter_contact_block"
29
- ]
30
- }