generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1f6894
commit a660d4e
Showing
52 changed files
with
1,892 additions
and
8,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/Yelp/detect-secrets | ||
rev: v0.14.2 | ||
rev: v1.4.0 | ||
hooks: | ||
- id: detect-secrets | ||
args: ['--baseline', '.secrets.baseline'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. | ||
version: v1.22.0 | ||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date | ||
version: v1.19.0 | ||
ignore: {} | ||
patch: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const Joi = require('joi') | ||
const { PRODUCTION } = require('../constants/environments') | ||
|
||
const schema = Joi.object({ | ||
messageQueue: { | ||
host: Joi.string(), | ||
username: Joi.string(), | ||
password: Joi.string(), | ||
useCredentialChain: Joi.bool().default(false), | ||
appInsights: Joi.object() | ||
}, | ||
dataTopic: { | ||
address: Joi.string() | ||
}, | ||
dataQueue: { | ||
address: Joi.string() | ||
} | ||
}) | ||
|
||
const config = { | ||
messageQueue: { | ||
host: process.env.MESSAGE_QUEUE_HOST, | ||
username: process.env.MESSAGE_QUEUE_USER, | ||
password: process.env.MESSAGE_QUEUE_PASSWORD, | ||
useCredentialChain: process.env.NODE_ENV === PRODUCTION, | ||
appInsights: process.env.NODE_ENV === PRODUCTION ? require('applicationinsights') : undefined | ||
}, | ||
dataTopic: { | ||
address: process.env.DATA_TOPIC_ADDRESS | ||
}, | ||
dataQueue: { | ||
address: process.env.DATARESPONSE_QUEUE_ADDRESS | ||
} | ||
} | ||
|
||
const result = schema.validate(config, { | ||
abortEarly: false | ||
}) | ||
|
||
if (result.error) { | ||
throw new Error(`The message config is invalid. ${result.error.message}`) | ||
} | ||
|
||
const dataTopic = { ...result.value.messageQueue, ...result.value.dataTopic } | ||
const dataQueue = { ...result.value.messageQueue, ...result.value.dataQueue } | ||
|
||
module.exports = { | ||
dataTopic, | ||
dataQueue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
FRN: 'frn', | ||
CORRELATION_ID: 'correlationId' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
DEVELOPMENT: 'development', | ||
TEST: 'test', | ||
PRODUCTION: 'production' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
SOURCE: 'ffc-pay-web' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
TYPE: 'uk.gov.defra.ffc.pay.data.request' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { SOURCE } = require('../constants/source') | ||
|
||
const createMessage = (body, type, options) => { | ||
return { | ||
body, | ||
type, | ||
source: SOURCE, | ||
...options | ||
} | ||
} | ||
|
||
module.exports = { | ||
createMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { sendMessage } = require('./send-message') | ||
const { receiveMessage } = require('./receive-message') | ||
|
||
module.exports = { | ||
sendMessage, | ||
receiveMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { MessageReceiver } = require('ffc-messaging') | ||
|
||
const receiveMessage = async (messageId, config) => { | ||
let result | ||
const receiver = new MessageReceiver(config) | ||
await receiver.acceptSession(messageId) | ||
const messages = await receiver.receiveMessages(1, { maxWaitTimeInMs: 50000 }) | ||
if (messages.length) { | ||
result = messages[0].body | ||
await receiver.completeMessage(messages[0]) | ||
} | ||
await receiver.closeConnection() | ||
return result | ||
} | ||
|
||
module.exports = { | ||
receiveMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { MessageSender } = require('ffc-messaging') | ||
const { createMessage } = require('./create-message') | ||
|
||
const sendMessage = async (body, type, config, options) => { | ||
const message = createMessage(body, type, options) | ||
const sender = new MessageSender(config) | ||
await sender.sendMessage(message) | ||
await sender.closeConnection() | ||
} | ||
|
||
module.exports = { | ||
sendMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { v4: uuidv4 } = require('uuid') | ||
const util = require('util') | ||
const { TYPE } = require('../constants/type') | ||
const config = require('../config') | ||
const { sendMessage, receiveMessage } = require('../messaging') | ||
|
||
const getData = async (category, value) => { | ||
const messageId = uuidv4() | ||
const request = { category, value } | ||
await sendMessage(request, TYPE, config.messageConfig.dataTopic, { messageId }) | ||
console.info('Data request sent:', util.inspect(request, false, null, true)) | ||
const response = await receiveMessage(messageId, config.messageConfig.dataQueue) | ||
if (response) { | ||
console.info('Data response received:', util.inspect(response, false, null, true)) | ||
return response.data | ||
} | ||
} | ||
|
||
module.exports = { | ||
getData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { CORRELATION_ID } = require('../constants/categories') | ||
const { getData } = require('./get-data') | ||
|
||
const getPaymentsByCorrelationId = async (correlationId) => { | ||
return getData(CORRELATION_ID, correlationId) | ||
} | ||
|
||
module.exports = { | ||
getPaymentsByCorrelationId | ||
} |
Oops, something went wrong.