-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuspmp-close.js
42 lines (34 loc) · 1.08 KB
/
uspmp-close.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const UspMp = require('./uspmp-api')
module.exports = function(RED) {
function UspmpCloseNode(config) {
RED.nodes.createNode(this, config)
var node = this
node.config = config
// Retrieve the TLS config
const tlsConfig = RED.nodes.getNode(config.tlsConfig)
// Initialize
const uspmp = new UspMp({
httpsConfig: {
cert: tlsConfig.cert,
key: tlsConfig.key,
ca: tlsConfig.ca,
},
})
node.on('input', async function(msg, send, done) {
try {
const deliveryId = RED.util.getMessageProperty(msg, node.config.deliveryIdProperty || 'payload.id');
node.status({ fill: 'blue', shape: 'dot', text: 'requesting' })
const result = await uspmp.closeDelivery(deliveryId)
msg.payload = result
node.status({})
} catch (err) {
node.status({ fill: 'red', shape: 'ring', text: err.code ? `${err.code} (${err.status})` : 'error' })
done(err)
return
}
send(msg)
done()
})
}
RED.nodes.registerType('uspmp-close', UspmpCloseNode)
}