@defra-fish/connectors-lib 1.64.0-rc.2 → 1.64.0-rc.20
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/package.json +13 -13
- package/src/__tests__/sales-api-connector.spec.js +34 -0
- package/src/airbrake.js +3 -1
- package/src/aws.js +3 -2
- package/src/sales-api-connector.js +23 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/connectors-lib",
|
|
3
|
-
"version": "1.64.0-rc.
|
|
3
|
+
"version": "1.64.0-rc.20",
|
|
4
4
|
"description": "Shared connectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@airbrake/node": "
|
|
38
|
-
"@aws-sdk/client-dynamodb": "
|
|
39
|
-
"@aws-sdk/client-s3": "
|
|
40
|
-
"@aws-sdk/client-secrets-manager": "
|
|
41
|
-
"@aws-sdk/client-sqs": "
|
|
42
|
-
"@aws-sdk/lib-dynamodb": "
|
|
43
|
-
"debug": "
|
|
44
|
-
"http-status-codes": "
|
|
45
|
-
"ioredis": "
|
|
46
|
-
"node-fetch": "
|
|
47
|
-
"redlock": "
|
|
37
|
+
"@airbrake/node": "2.1.7",
|
|
38
|
+
"@aws-sdk/client-dynamodb": "3.777.0",
|
|
39
|
+
"@aws-sdk/client-s3": "3.779.0",
|
|
40
|
+
"@aws-sdk/client-secrets-manager": "3.777.0",
|
|
41
|
+
"@aws-sdk/client-sqs": "3.777.0",
|
|
42
|
+
"@aws-sdk/lib-dynamodb": "3.778.0",
|
|
43
|
+
"debug": "4.3.3",
|
|
44
|
+
"http-status-codes": "2.3.0",
|
|
45
|
+
"ioredis": "4.28.5",
|
|
46
|
+
"node-fetch": "2.7.0",
|
|
47
|
+
"redlock": "4.2.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "853e2b2a4d2e9ce0160d941b3e108e972a108ae5"
|
|
50
50
|
}
|
|
@@ -822,3 +822,37 @@ describe('sales-api-connector', () => {
|
|
|
822
822
|
})
|
|
823
823
|
})
|
|
824
824
|
})
|
|
825
|
+
|
|
826
|
+
describe('rcp authentication', () => {
|
|
827
|
+
it('returns parsed JSON with successful fetch', async () => {
|
|
828
|
+
const expectedResponse = { woo: 'hoo' }
|
|
829
|
+
fetch.mockReturnValueOnce({ ok: true, status: 200, statusText: 'OK', text: async () => JSON.stringify(expectedResponse) })
|
|
830
|
+
const response = await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
|
|
831
|
+
expect(response).toEqual(expectedResponse)
|
|
832
|
+
})
|
|
833
|
+
|
|
834
|
+
it('calls fetch with the RCP authenticate URL and query params', async () => {
|
|
835
|
+
const expectedResponse = { woo: 'hoo' }
|
|
836
|
+
fetch.mockReturnValueOnce({ ok: true, status: 200, statusText: 'OK', text: async () => JSON.stringify(expectedResponse) })
|
|
837
|
+
await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
|
|
838
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
839
|
+
'http://0.0.0.0:4000/authenticate/rcp/AAAAAA?licenseeBirthDate=1980-03-02&licenseePostcode=BS9%204PT',
|
|
840
|
+
{
|
|
841
|
+
method: 'get',
|
|
842
|
+
headers: expect.any(Object),
|
|
843
|
+
timeout: 20000
|
|
844
|
+
}
|
|
845
|
+
)
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
it('returns null when the sales API responds with a non-2xx status', async () => {
|
|
849
|
+
fetch.mockReturnValueOnce({
|
|
850
|
+
ok: false,
|
|
851
|
+
status: 400,
|
|
852
|
+
statusText: 'Bad Request',
|
|
853
|
+
text: async () => 'Bad Request'
|
|
854
|
+
})
|
|
855
|
+
const response = await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
|
|
856
|
+
expect(response).toBeNull()
|
|
857
|
+
})
|
|
858
|
+
})
|
package/src/airbrake.js
CHANGED
|
@@ -21,7 +21,9 @@ export const initialise = () => {
|
|
|
21
21
|
projectKey: process.env.AIRBRAKE_PROJECT_KEY,
|
|
22
22
|
host: process.env.AIRBRAKE_HOST,
|
|
23
23
|
environment: process.env.NODE_ENV,
|
|
24
|
-
performanceStats: false
|
|
24
|
+
performanceStats: false,
|
|
25
|
+
errorNotifications: true,
|
|
26
|
+
remoteConfig: false
|
|
25
27
|
})
|
|
26
28
|
|
|
27
29
|
// Proxy the console.warn and console.error methods, notifying airbrake/errbit asynchronously
|
package/src/aws.js
CHANGED
|
@@ -2,7 +2,7 @@ import Config from './config.js'
|
|
|
2
2
|
import { createDocumentClient } from './documentclient-decorator.js'
|
|
3
3
|
import { DynamoDB } from '@aws-sdk/client-dynamodb'
|
|
4
4
|
import { SQS } from '@aws-sdk/client-sqs'
|
|
5
|
-
import { S3Client, ListObjectsV2Command } from '@aws-sdk/client-s3'
|
|
5
|
+
import { S3Client, ListObjectsV2Command, GetObjectCommand } from '@aws-sdk/client-s3'
|
|
6
6
|
import { SecretsManager } from '@aws-sdk/client-secrets-manager'
|
|
7
7
|
|
|
8
8
|
export default function () {
|
|
@@ -40,6 +40,7 @@ export default function () {
|
|
|
40
40
|
endpoint: Config.aws.secretsManager.endpoint
|
|
41
41
|
})
|
|
42
42
|
}),
|
|
43
|
-
ListObjectsV2Command
|
|
43
|
+
ListObjectsV2Command,
|
|
44
|
+
GetObjectCommand
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch'
|
|
2
|
-
import querystring from 'querystring'
|
|
2
|
+
import querystring from 'node:querystring'
|
|
3
3
|
import db from 'debug'
|
|
4
4
|
const SALES_API_URL_DEFAULT = 'http://0.0.0.0:4000'
|
|
5
5
|
const SALES_API_TIMEOUT_MS_DEFAULT = 20000
|
|
@@ -27,7 +27,7 @@ export const call = async (url, method = 'get', payload = null) => {
|
|
|
27
27
|
ok: response.ok,
|
|
28
28
|
status: response.status,
|
|
29
29
|
statusText: response.statusText,
|
|
30
|
-
body: response.status
|
|
30
|
+
body: response.status === 204 ? undefined : await parseResponseBody(response)
|
|
31
31
|
}
|
|
32
32
|
debug(
|
|
33
33
|
'Request sent (%s): %s %s with payload %o. Response received (%s): %o',
|
|
@@ -269,6 +269,27 @@ export const authenticate = async (referenceNumber, birthDate, postcode) =>
|
|
|
269
269
|
)
|
|
270
270
|
)
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Support for cancelling recurring payment authentication
|
|
274
|
+
* @param referenceNumber
|
|
275
|
+
* @param birthDate
|
|
276
|
+
* @param postcode
|
|
277
|
+
* @returns {Promise<*>}
|
|
278
|
+
*/
|
|
279
|
+
export const authenticateRecurringPayment = (referenceNumber, birthDate, postcode) =>
|
|
280
|
+
exec2xxOrNull(
|
|
281
|
+
call(
|
|
282
|
+
new URL(
|
|
283
|
+
`/authenticate/rcp/${referenceNumber}?${querystring.stringify({
|
|
284
|
+
licenseeBirthDate: birthDate,
|
|
285
|
+
licenseePostcode: postcode
|
|
286
|
+
})}`,
|
|
287
|
+
urlBase
|
|
288
|
+
),
|
|
289
|
+
'get'
|
|
290
|
+
)
|
|
291
|
+
)
|
|
292
|
+
|
|
272
293
|
/**
|
|
273
294
|
* Helper to check if an HTTP status code is classed as a system error
|
|
274
295
|
*
|