ffc-pay-event-publisher 1.0.0-alpha.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/.pre-commit-config.yaml +6 -0
- package/.secrets.baseline +67 -0
- package/Jenkinsfile +3 -0
- package/LICENCE +8 -0
- package/README.md +55 -0
- package/app/app-insights/index.js +5 -0
- package/app/app-insights/track-event.js +5 -0
- package/app/event-publisher/event-schema.js +29 -0
- package/app/event-publisher/index.js +5 -0
- package/app/event-publisher/publish-event.js +19 -0
- package/app/messaging/create-message.js +10 -0
- package/app/messaging/index.js +5 -0
- package/app/messaging/publish-event-request.js +10 -0
- package/app/messaging/send-message.js +11 -0
- package/index.js +5 -0
- package/jest.config.js +35 -0
- package/jsconfig.json +6 -0
- package/package.json +46 -0
- package/sonar-project.properties +3 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"custom_plugin_paths": [],
|
|
3
|
+
"exclude": {
|
|
4
|
+
"files": "package-lock.json",
|
|
5
|
+
"lines": null
|
|
6
|
+
},
|
|
7
|
+
"generated_at": "2020-08-16T12:22:01Z",
|
|
8
|
+
"plugins_used": [
|
|
9
|
+
{
|
|
10
|
+
"name": "AWSKeyDetector"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "ArtifactoryDetector"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"base64_limit": 4.5,
|
|
17
|
+
"name": "Base64HighEntropyString"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "BasicAuthDetector"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "CloudantDetector"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"hex_limit": 3,
|
|
27
|
+
"name": "HexHighEntropyString"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "IbmCloudIamDetector"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "IbmCosHmacDetector"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "JwtTokenDetector"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"keyword_exclude": null,
|
|
40
|
+
"name": "KeywordDetector"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "MailchimpDetector"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "PrivateKeyDetector"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "SlackDetector"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "SoftlayerDetector"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "StripeDetector"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "TwilioKeyDetector"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"results": {},
|
|
62
|
+
"version": "0.14.2",
|
|
63
|
+
"word_list": {
|
|
64
|
+
"file": null,
|
|
65
|
+
"hash": null
|
|
66
|
+
}
|
|
67
|
+
}
|
package/Jenkinsfile
ADDED
package/LICENCE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The Open Government Licence (OGL) Version 3
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Defra
|
|
4
|
+
|
|
5
|
+
This source code is licensed under the Open Government Licence v3.0. To view this
|
|
6
|
+
licence, visit www.nationalarchives.gov.uk/doc/open-government-licence/version/3
|
|
7
|
+
or write to the Information Policy Team, The National Archives, Kew, Richmond,
|
|
8
|
+
Surrey, TW9 4DU.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# ffc-pay-event-publisher
|
|
2
|
+
NPM module for publishing events
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
|
|
6
|
+
### Installation
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install --save ffc-pay-event-publisher
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Configuration
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
#### Example usage
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
const { PublishEvent } = require('ffc-protective-monitoring')
|
|
20
|
+
|
|
21
|
+
const protectiveMonitoring = new PublishEvent(PROTECTIVE_MONITORING_URL)
|
|
22
|
+
|
|
23
|
+
await protectiveMonitoring.sendEvent({
|
|
24
|
+
sessionid: 'e66d78f5-a58d-46f6-a9b4-f8c90e99b6dc',
|
|
25
|
+
datetime: '2020-10-09T12:51:41.381Z',
|
|
26
|
+
version: '1.1',
|
|
27
|
+
application: 'FI001',
|
|
28
|
+
component: '<internal app name>',
|
|
29
|
+
ip: '127.0.0.1',
|
|
30
|
+
pmccode: '0703',
|
|
31
|
+
priority: '0',
|
|
32
|
+
details: {
|
|
33
|
+
transactioncode: '2306',
|
|
34
|
+
message: 'User successfully downloaded a stored document',
|
|
35
|
+
additionalinfo: '<details or obfuscated location of document, etc.>'
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Licence
|
|
42
|
+
|
|
43
|
+
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
|
|
44
|
+
|
|
45
|
+
<http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3>
|
|
46
|
+
|
|
47
|
+
The following attribution statement MUST be cited in your products and applications when using this information.
|
|
48
|
+
|
|
49
|
+
> Contains public sector information licensed under the Open Government license v3
|
|
50
|
+
|
|
51
|
+
### About the licence
|
|
52
|
+
|
|
53
|
+
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
|
|
54
|
+
|
|
55
|
+
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const joi = require('joi')
|
|
2
|
+
|
|
3
|
+
const eventSchema = joi.object({
|
|
4
|
+
name: joi.string().required(),
|
|
5
|
+
properties: joi.object({
|
|
6
|
+
id: joi.string().required(),
|
|
7
|
+
checkpoint: joi.string().required(),
|
|
8
|
+
status: joi.string().required(),
|
|
9
|
+
action: joi.object({
|
|
10
|
+
type: joi.string().required(),
|
|
11
|
+
message: joi.string().required(),
|
|
12
|
+
timestamp: joi.date().required(),
|
|
13
|
+
data: joi.object()
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const validateEvent = (event) => {
|
|
19
|
+
const validate = eventSchema.validate(event)
|
|
20
|
+
|
|
21
|
+
if (validate.error) {
|
|
22
|
+
console.log('Event validation error', validate.error)
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = validateEvent
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const validateEvent = require('./event-schema')
|
|
2
|
+
const { trackEvent } = require('../app-insights')
|
|
3
|
+
const { publishEventRequest } = require('../event-publisher/messaging')
|
|
4
|
+
|
|
5
|
+
class PublishEvent {
|
|
6
|
+
constructor (config) {
|
|
7
|
+
this.appInsights = config.appInsights
|
|
8
|
+
this.config = config
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async sendEvent (eventMessage) {
|
|
12
|
+
if (validateEvent(eventMessage)) {
|
|
13
|
+
await publishEventRequest(eventMessage, this.config)
|
|
14
|
+
trackEvent(eventMessage)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = PublishEvent
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { MessageSender } = require('ffc-messaging')
|
|
2
|
+
const createMessage = require('./create-message')
|
|
3
|
+
|
|
4
|
+
const publishEventRequest = async (eventMessage, config) => {
|
|
5
|
+
const eventSender = new MessageSender(config)
|
|
6
|
+
const message = createMessage(eventMessage, 'uk.gov.pay.event.publisher')
|
|
7
|
+
await eventSender.sendMessage(message)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = publishEventRequest
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { MessageSender } = require('ffc-messaging')
|
|
2
|
+
const createMessage = require('./create-message')
|
|
3
|
+
|
|
4
|
+
const sendMessage = async (body, type, config, options) => {
|
|
5
|
+
const message = createMessage(body, type, options)
|
|
6
|
+
const sender = new MessageSender(config)
|
|
7
|
+
await sender.sendMessage(message)
|
|
8
|
+
await sender.closeConnection()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = sendMessage
|
package/index.js
ADDED
package/jest.config.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
collectCoverage: true,
|
|
3
|
+
collectCoverageFrom: [
|
|
4
|
+
'**/*.js',
|
|
5
|
+
'!**/*.test.js'
|
|
6
|
+
],
|
|
7
|
+
coverageDirectory: 'test-output',
|
|
8
|
+
coverageReporters: [
|
|
9
|
+
'text-summary',
|
|
10
|
+
'lcov'
|
|
11
|
+
],
|
|
12
|
+
coveragePathIgnorePatterns: [
|
|
13
|
+
'<rootDir>/node_modules/',
|
|
14
|
+
'<rootDir>/test-output/',
|
|
15
|
+
'<rootDir>/test/',
|
|
16
|
+
'<rootDir>/jest.config.js'
|
|
17
|
+
],
|
|
18
|
+
modulePathIgnorePatterns: [
|
|
19
|
+
'node_modules'
|
|
20
|
+
],
|
|
21
|
+
reporters: [
|
|
22
|
+
'default',
|
|
23
|
+
[
|
|
24
|
+
'jest-junit',
|
|
25
|
+
{
|
|
26
|
+
suiteName: 'jest tests',
|
|
27
|
+
outputDirectory: 'test-output',
|
|
28
|
+
outputName: 'junit.xml'
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
],
|
|
32
|
+
testEnvironment: 'node',
|
|
33
|
+
testPathIgnorePatterns: [],
|
|
34
|
+
verbose: true
|
|
35
|
+
}
|
package/jsconfig.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ffc-pay-event-publisher",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "Publish events",
|
|
5
|
+
"homepage": "https://github.com/DEFRA/ffc-protective-monitoring",
|
|
6
|
+
"main": "app/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --runInBand",
|
|
9
|
+
"test:watch": "jest --coverage=false --onlyChanged --watch --runInBand",
|
|
10
|
+
"start:watch": "nodemon --inspect=0.0.0.0 --ext js --legacy-watch app/index.js",
|
|
11
|
+
"test:debug": "node --inspect-brk=0.0.0.0 ./node_modules/jest/bin/jest.js --runInBand"
|
|
12
|
+
},
|
|
13
|
+
"author": "Defra",
|
|
14
|
+
"contributors": [
|
|
15
|
+
"Steve Dickinson steve.dickinson@defra.gov.uk",
|
|
16
|
+
"Simon Dunn simon.dunn1@defra.gov.uk"
|
|
17
|
+
],
|
|
18
|
+
"license": "OGL-UK-3.0",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@hapi/hapi": "^20.0.0",
|
|
21
|
+
"joi": "^17.4.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"jest": "^26.6.3",
|
|
25
|
+
"jest-junit": "^11.1.0",
|
|
26
|
+
"nodemon": "^2.0.4",
|
|
27
|
+
"standard": "^14.3.4"
|
|
28
|
+
},
|
|
29
|
+
"standard": {
|
|
30
|
+
"globals": [
|
|
31
|
+
"describe",
|
|
32
|
+
"beforeEach",
|
|
33
|
+
"expect",
|
|
34
|
+
"test",
|
|
35
|
+
"afterEach",
|
|
36
|
+
"jest",
|
|
37
|
+
"beforeAll",
|
|
38
|
+
"afterAll"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"nodemonConfig": {
|
|
42
|
+
"ignore": [
|
|
43
|
+
"**/test-output/**"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|