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/notification.js
CHANGED
|
@@ -1,14 +1,72 @@
|
|
|
1
1
|
var ApiClient = require('./api_client');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
4
|
+
* @typedef {"sms" | "letter" | "email"} NotificationType
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {"first" | "second" | "economy" | "europe" | "rest-of-world"} PostageType
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} TemplateRef
|
|
13
|
+
* @property {string} id
|
|
14
|
+
* @property {number} version
|
|
15
|
+
* @property {string} uri
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} NotificationResponse
|
|
20
|
+
* @property {string} id
|
|
21
|
+
* @property {string} [reference]
|
|
22
|
+
* @property {NotificationType} type
|
|
23
|
+
* @property {string} status
|
|
24
|
+
* @property {{id: string, name: string, version: number}} template
|
|
25
|
+
* @property {string} body
|
|
26
|
+
* @property {string} created_at
|
|
27
|
+
* @property {string} [created_by_name]
|
|
28
|
+
* @property {string} [sent_at]
|
|
29
|
+
* @property {string} [completed_at]
|
|
30
|
+
* @property {string} [scheduled_for]
|
|
31
|
+
* @property {string} [one_click_unsubscribe]
|
|
32
|
+
* @property {boolean} is_cost_data_ready
|
|
33
|
+
* @property {number} [cost_in_pounds]
|
|
34
|
+
* @property {{billable_sheets_of_paper?: number, postage?: string} | {billable_sms_fragments?: number, international_rate_multiplier?: number, sms_rate?: number}} [cost_details]
|
|
35
|
+
* @property {string} [email_address]
|
|
36
|
+
* @property {string} [phone_number]
|
|
37
|
+
* @property {string} [subject]
|
|
38
|
+
* @property {string} [line_1]
|
|
39
|
+
* @property {string} [line_2]
|
|
40
|
+
* @property {string} [line_3]
|
|
41
|
+
* @property {string} [line_4]
|
|
42
|
+
* @property {string} [line_5]
|
|
43
|
+
* @property {string} [line_6]
|
|
44
|
+
* @property {string} [line_7]
|
|
45
|
+
* @property {PostageType} [postage]
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {Object} TemplateData
|
|
50
|
+
* @property {string} id
|
|
51
|
+
* @property {string} name
|
|
52
|
+
* @property {NotificationType} type
|
|
53
|
+
* @property {string} created_at
|
|
54
|
+
* @property {string | null} updated_at
|
|
55
|
+
* @property {string} created_by
|
|
56
|
+
* @property {number} version
|
|
57
|
+
* @property {string} body
|
|
58
|
+
* @property {string} [subject]
|
|
59
|
+
* @property {string} [letter_contact_block]
|
|
60
|
+
* @property {PostageType} [postage]
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} apiKeyOrUrl - API key (1 arg), or base URL (2-3 args)
|
|
65
|
+
* @param {string} [serviceIdOrApiKey] - API key (2 args), or service ID (3 args)
|
|
66
|
+
* @param {string} [apiKeyId] - API key (3 args)
|
|
9
67
|
* @constructor
|
|
10
68
|
*/
|
|
11
|
-
function NotifyClient() {
|
|
69
|
+
function NotifyClient(apiKeyOrUrl, serviceIdOrApiKey, apiKeyId) {
|
|
12
70
|
this.apiClient = new (Function.prototype.bind.apply(
|
|
13
71
|
ApiClient,
|
|
14
72
|
[null].concat(Array.prototype.slice.call(arguments))
|
|
@@ -126,265 +184,231 @@ function _check_and_encode_file(file, size_limit) {
|
|
|
126
184
|
return file.toString('base64')
|
|
127
185
|
}
|
|
128
186
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
*
|
|
357
|
-
* @param {object} an axios instance
|
|
358
|
-
*/
|
|
359
|
-
setClient: function(client) {
|
|
360
|
-
this.apiClient.setClient(client);
|
|
361
|
-
},
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
*
|
|
365
|
-
* @param {Buffer} fileData
|
|
366
|
-
* @param {object} options
|
|
367
|
-
*
|
|
368
|
-
* @returns {Dictionary}
|
|
369
|
-
*/
|
|
370
|
-
prepareUpload: function(fileData, options) {
|
|
371
|
-
let data = {
|
|
372
|
-
file: _check_and_encode_file(fileData, 2),
|
|
373
|
-
filename: null,
|
|
374
|
-
confirm_email_before_download: null,
|
|
375
|
-
retention_period: null,
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
if (options !== undefined) {
|
|
379
|
-
data.filename = options.filename || null;
|
|
380
|
-
data.confirm_email_before_download = options.confirmEmailBeforeDownload !== undefined ? options.confirmEmailBeforeDownload : null;
|
|
381
|
-
data.retention_period = options.retentionPeriod || null;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return data;
|
|
385
|
-
},
|
|
386
|
-
|
|
387
|
-
});
|
|
187
|
+
/**
|
|
188
|
+
* @param {string} templateId
|
|
189
|
+
* @param {string} emailAddress
|
|
190
|
+
* @param {{personalisation?: Object, reference?: string, emailReplyToId?: string, oneClickUnsubscribeURL?: string}} [options]
|
|
191
|
+
* @returns {Promise<import('axios').AxiosResponse<{id: string, reference?: string, content: {body: string, subject: string, from_email: string, one_click_unsubscribe_url?: string}, uri: string, template: TemplateRef}>>}
|
|
192
|
+
*/
|
|
193
|
+
NotifyClient.prototype.sendEmail = function (templateId, emailAddress, options) {
|
|
194
|
+
options = options || {};
|
|
195
|
+
var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId', 'oneClickUnsubscribeURL'], options)
|
|
196
|
+
if (err) {
|
|
197
|
+
return Promise.reject(err);
|
|
198
|
+
}
|
|
199
|
+
var personalisation = options.personalisation || undefined,
|
|
200
|
+
reference = options.reference || undefined,
|
|
201
|
+
emailReplyToId = options.emailReplyToId || undefined,
|
|
202
|
+
oneClickUnsubscribeURL = options.oneClickUnsubscribeURL || undefined;
|
|
203
|
+
|
|
204
|
+
return this.apiClient.post('/v2/notifications/email',
|
|
205
|
+
createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId, oneClickUnsubscribeURL));
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @param {string} templateId
|
|
210
|
+
* @param {string} phoneNumber
|
|
211
|
+
* @param {{personalisation?: Object, reference?: string, smsSenderId?: string}} [options]
|
|
212
|
+
* @returns {Promise<import('axios').AxiosResponse<{id: string, reference?: string, content: {body: string, from_number: string}, uri: string, template: TemplateRef}>>}
|
|
213
|
+
*/
|
|
214
|
+
NotifyClient.prototype.sendSms = function (templateId, phoneNumber, options) {
|
|
215
|
+
options = options || {};
|
|
216
|
+
var err = checkOptionsKeys(['personalisation', 'reference', 'smsSenderId'], options)
|
|
217
|
+
if (err) {
|
|
218
|
+
return Promise.reject(err);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var personalisation = options.personalisation || undefined;
|
|
222
|
+
var reference = options.reference || undefined;
|
|
223
|
+
var smsSenderId = options.smsSenderId || undefined;
|
|
224
|
+
|
|
225
|
+
return this.apiClient.post('/v2/notifications/sms',
|
|
226
|
+
createNotificationPayload('sms', templateId, phoneNumber, personalisation, reference, smsSenderId));
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {string} templateId
|
|
231
|
+
* @param {{personalisation?: Object, reference?: string}} [options]
|
|
232
|
+
* @returns {Promise<import('axios').AxiosResponse<{id: string, reference?: string, content: {body: string, subject: string}, uri: string, template: TemplateRef, scheduled_for: string | null}>>}
|
|
233
|
+
*/
|
|
234
|
+
NotifyClient.prototype.sendLetter = function (templateId, options) {
|
|
235
|
+
options = options || {};
|
|
236
|
+
var err = checkOptionsKeys(['personalisation', 'reference'], options)
|
|
237
|
+
if (err) {
|
|
238
|
+
return Promise.reject(err);
|
|
239
|
+
}
|
|
240
|
+
var personalisation = options.personalisation || undefined;
|
|
241
|
+
var reference = options.reference || undefined;
|
|
242
|
+
|
|
243
|
+
return this.apiClient.post('/v2/notifications/letter',
|
|
244
|
+
createNotificationPayload('letter', templateId, undefined, personalisation, reference));
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @param {string} reference
|
|
249
|
+
* @param {Buffer | string} pdf_file
|
|
250
|
+
* @param {"first" | "second" | "economy" | "europe" | "rest-of-world"} [postage]
|
|
251
|
+
* @returns {Promise<import('axios').AxiosResponse<{id: string, reference: string, postage: PostageType}>>}
|
|
252
|
+
*/
|
|
253
|
+
NotifyClient.prototype.sendPrecompiledLetter = function(reference, pdf_file, postage) {
|
|
254
|
+
var postage = postage || undefined
|
|
255
|
+
var content = _check_and_encode_file(pdf_file, 5)
|
|
256
|
+
var notification = {
|
|
257
|
+
"reference": reference,
|
|
258
|
+
"content": content
|
|
259
|
+
}
|
|
260
|
+
if (postage != undefined) {
|
|
261
|
+
notification["postage"] = postage
|
|
262
|
+
}
|
|
263
|
+
return this.apiClient.post('/v2/notifications/letter', notification);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @param {string} notificationId
|
|
268
|
+
* @returns {Promise<import('axios').AxiosResponse<NotificationResponse>>}
|
|
269
|
+
*/
|
|
270
|
+
NotifyClient.prototype.getNotificationById = function(notificationId) {
|
|
271
|
+
return this.apiClient.get('/v2/notifications/' + notificationId);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @param {string} [templateType]
|
|
276
|
+
* @param {string} [status]
|
|
277
|
+
* @param {string} [reference]
|
|
278
|
+
* @param {string} [olderThanId]
|
|
279
|
+
* @returns {Promise<import('axios').AxiosResponse<{notifications: NotificationResponse[], links: {current: string, next: string}}>>}
|
|
280
|
+
*/
|
|
281
|
+
NotifyClient.prototype.getNotifications = function(templateType, status, reference, olderThanId) {
|
|
282
|
+
return this.apiClient.get('/v2/notifications' + buildGetAllNotificationsQuery(templateType, status, reference, olderThanId));
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @param {string} notificationId
|
|
287
|
+
* @returns {Promise<Buffer>}
|
|
288
|
+
*/
|
|
289
|
+
NotifyClient.prototype.getPdfForLetterNotification = function(notificationId) {
|
|
290
|
+
const url = '/v2/notifications/' + notificationId + '/pdf'
|
|
291
|
+
|
|
292
|
+
// Unlike other requests, we expect a successful response as an arraybuffer and an error as JSON
|
|
293
|
+
// Axios does not support flexible response types so we will need to handle the error case ourselves below
|
|
294
|
+
return this.apiClient.get(url, { responseType: 'arraybuffer' })
|
|
295
|
+
.then(function(response) {
|
|
296
|
+
var pdf = Buffer.from(response.data, "base64")
|
|
297
|
+
return pdf
|
|
298
|
+
})
|
|
299
|
+
.catch(function(error) {
|
|
300
|
+
// If we receive an error, as the response is an arraybuffer rather than our usual JSON
|
|
301
|
+
// we need to convert it to JSON to be read by the user
|
|
302
|
+
string_of_error_body = new TextDecoder().decode(error.response.data);
|
|
303
|
+
|
|
304
|
+
// Then we replace the error data with the JSON error rather than the arraybuffer of the error
|
|
305
|
+
error.response.data = JSON.parse(string_of_error_body);
|
|
306
|
+
|
|
307
|
+
// and rethrow to let the user handle the error
|
|
308
|
+
throw error
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @param {string} templateId
|
|
314
|
+
* @returns {Promise<import('axios').AxiosResponse<TemplateData>>}
|
|
315
|
+
*/
|
|
316
|
+
NotifyClient.prototype.getTemplateById = function(templateId) {
|
|
317
|
+
return this.apiClient.get('/v2/template/' + templateId);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @param {string} templateId
|
|
322
|
+
* @param {number} version
|
|
323
|
+
* @returns {Promise<import('axios').AxiosResponse<TemplateData>>}
|
|
324
|
+
*/
|
|
325
|
+
NotifyClient.prototype.getTemplateByIdAndVersion = function(templateId, version) {
|
|
326
|
+
return this.apiClient.get('/v2/template/' + templateId + '/version/' + version);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* @param {NotificationType} [templateType]
|
|
331
|
+
* @returns {Promise<import('axios').AxiosResponse<{templates: TemplateData[]}>>}
|
|
332
|
+
*/
|
|
333
|
+
NotifyClient.prototype.getAllTemplates = function(templateType) {
|
|
334
|
+
let templateQuery = ''
|
|
335
|
+
|
|
336
|
+
if (templateType) {
|
|
337
|
+
templateQuery = '?type=' + templateType;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return this.apiClient.get('/v2/templates' + templateQuery);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @param {string} templateId
|
|
345
|
+
* @param {Object} [personalisation]
|
|
346
|
+
* @returns {Promise<import('axios').AxiosResponse<{id: string, type: NotificationType, version: number, body: string, html?: string, subject?: string, postage?: PostageType}>>}
|
|
347
|
+
*/
|
|
348
|
+
NotifyClient.prototype.previewTemplateById = function(templateId, personalisation) {
|
|
349
|
+
|
|
350
|
+
let payload = {}
|
|
351
|
+
|
|
352
|
+
if (personalisation) {
|
|
353
|
+
payload.personalisation = personalisation;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return this.apiClient.post('/v2/template/' + templateId + '/preview', payload);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @param {string} [olderThan]
|
|
361
|
+
* @returns {Promise<import('axios').AxiosResponse<{received_text_messages: Array<{id: string, user_number: string, notify_number: string, created_at: string, service_id: string, content: string}>, links: {current: string, next: string}}>>}
|
|
362
|
+
*/
|
|
363
|
+
NotifyClient.prototype.getReceivedTexts = function(olderThan){
|
|
364
|
+
let queryString;
|
|
365
|
+
|
|
366
|
+
if (olderThan) {
|
|
367
|
+
queryString = '?older_than=' + olderThan;
|
|
368
|
+
} else {
|
|
369
|
+
queryString = '';
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return this.apiClient.get('/v2/received-text-messages' + queryString);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @param {import('axios').AxiosProxyConfig} proxyConfig
|
|
377
|
+
* @returns {void}
|
|
378
|
+
*/
|
|
379
|
+
NotifyClient.prototype.setProxy = function(proxyConfig) {
|
|
380
|
+
this.apiClient.setProxy(proxyConfig);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @param {import('axios').AxiosInstance} client
|
|
385
|
+
* @returns {void}
|
|
386
|
+
*/
|
|
387
|
+
NotifyClient.prototype.setClient = function(client) {
|
|
388
|
+
this.apiClient.setClient(client);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @param {Buffer | string} fileData
|
|
393
|
+
* @param {{filename?: string, confirmEmailBeforeDownload?: boolean, retentionPeriod?: string}} [options]
|
|
394
|
+
* @returns {{file: string, filename: string | null, confirm_email_before_download: boolean | null, retention_period: string | null}}
|
|
395
|
+
*/
|
|
396
|
+
NotifyClient.prototype.prepareUpload = function(fileData, options) {
|
|
397
|
+
let data = {
|
|
398
|
+
file: _check_and_encode_file(fileData, 2),
|
|
399
|
+
filename: null,
|
|
400
|
+
confirm_email_before_download: null,
|
|
401
|
+
retention_period: null,
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (options !== undefined) {
|
|
405
|
+
data.filename = options.filename || null;
|
|
406
|
+
data.confirm_email_before_download = options.confirmEmailBeforeDownload !== undefined ? options.confirmEmailBeforeDownload : null;
|
|
407
|
+
data.retention_period = options.retentionPeriod || null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return data;
|
|
411
|
+
};
|
|
388
412
|
|
|
389
413
|
module.exports = {
|
|
390
414
|
NotifyClient: NotifyClient
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notifications-node-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.1",
|
|
4
4
|
"homepage": "https://docs.notifications.service.gov.uk/node.html",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "GOV.UK Notify Node.js client ",
|
|
10
10
|
"main": "index.js",
|
|
11
|
+
"types": "types/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"client",
|
|
14
|
+
"types",
|
|
15
|
+
"tsconfig.json"
|
|
16
|
+
],
|
|
11
17
|
"scripts": {
|
|
12
18
|
"test": "mocha \"spec/**/*.js\" && npm run test:markdown:standard",
|
|
13
19
|
"test:markdown:standard": "standard-markdown DOCUMENTATION.md",
|
|
14
|
-
"integration": "mocha spec/integration/test.js"
|
|
20
|
+
"integration": "mocha spec/integration/test.js",
|
|
21
|
+
"build:types": "tsc",
|
|
22
|
+
"check:types": "tsc --noEmit ./spec/types-test.ts"
|
|
15
23
|
},
|
|
16
24
|
"engines": {
|
|
17
25
|
"npm": ">=6.14.13",
|
|
@@ -24,6 +32,7 @@
|
|
|
24
32
|
"jsonwebtoken": "^9.0.2"
|
|
25
33
|
},
|
|
26
34
|
"devDependencies": {
|
|
35
|
+
"@types/node": "^25.3.0",
|
|
27
36
|
"chai": "4.3.4",
|
|
28
37
|
"chai-as-promised": "7.1.1",
|
|
29
38
|
"chai-bytes": "0.1.2",
|
|
@@ -34,6 +43,7 @@
|
|
|
34
43
|
"nock": "9.2.6",
|
|
35
44
|
"optimist": "0.6.1",
|
|
36
45
|
"sinon": "^18.0.0",
|
|
37
|
-
"standard-markdown": "7.1.0"
|
|
46
|
+
"standard-markdown": "7.1.0",
|
|
47
|
+
"typescript": "^5.9.0"
|
|
38
48
|
}
|
|
39
49
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": false,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"emitDeclarationOnly": true,
|
|
7
|
+
"declarationDir": "types",
|
|
8
|
+
"strict": false,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"target": "es2015",
|
|
14
|
+
"module": "commonjs"
|
|
15
|
+
},
|
|
16
|
+
"include": ["client/notification.js", "index.js"],
|
|
17
|
+
"exclude": ["node_modules", "spec"]
|
|
18
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<!--Thanks for contributing to GOV.UK Notify. Using this template to write your pull request message will help get it merged as soon as possible. -->
|
|
2
|
-
|
|
3
|
-
## What problem does the pull request solve?
|
|
4
|
-
<!--- Describe why you’re making this change -->
|
|
5
|
-
|
|
6
|
-
## Checklist
|
|
7
|
-
|
|
8
|
-
<!--- All of the following are normally needed. Don’t worry if you haven’t done them or don’t know how – someone from the Notify team will be able to help. -->
|
|
9
|
-
- [x] I’ve used the pull request template
|
|
10
|
-
- [ ] I’ve written unit tests for these changes
|
|
11
|
-
- [ ] I’ve updated the documentation in
|
|
12
|
-
- [notifications-tech-docs repository](https://github.com/alphagov/notifications-tech-docs/blob/main/source/documentation/client_docs/_node.md)
|
|
13
|
-
- `CHANGELOG.md`
|
|
14
|
-
- [ ] I’ve bumped the version number in
|
|
15
|
-
- `package.json`
|
|
16
|
-
- [ ] I've added new environment variables in
|
|
17
|
-
- `CONTRIBUTING.md`
|
|
18
|
-
- `notifications-node-client/scripts/generate_docker_env.sh`
|