@yousolution/node-red-contrib-you-sap-service-layer 0.0.3

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.
@@ -0,0 +1,130 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('authenticateSap',{
3
+ category: 'Sap',
4
+ color: '#FFC300',
5
+ defaults: {
6
+ name: {value: ''},
7
+ host: {value: ''},
8
+ port: {value: ''},
9
+ version: {value: ''}
10
+ },
11
+ credentials: {
12
+ company: {type: "string"},
13
+ user: {type:"string"},
14
+ password: {type:"password"}
15
+ },
16
+ inputs:1,
17
+ outputs:1,
18
+ icon: 'font-awesome/fa-lock',
19
+ label: function() {
20
+ return this.name||"Sap authenticate";
21
+ }
22
+ });
23
+ </script>
24
+
25
+ <script type="text/html" data-template-name="authenticateSap">
26
+ <div class="form-row">
27
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
28
+ <input type="text" id="node-input-name" placeholder="Name">
29
+ </div>
30
+
31
+ <div class="form-row">
32
+ <label for="node-input-host"><i class="fa fa-cogs"></i> Host</label>
33
+ <input type="text" id="node-input-host" placeholder="Host">
34
+ </div>
35
+
36
+ <div class="form-row">
37
+ <label for="node-input-port"><i class="fa fa-cogs"></i> Port</label>
38
+ <input type="text" id="node-input-port" placeholder="Port">
39
+ </div>
40
+
41
+ <div class="form-row">
42
+ <label for="node-input-version"><i class="fa fa-cogs"></i> Version</label>
43
+ <select name="node-input-version" id="node-input-version">
44
+ <option value="v1">v1</option>
45
+ <option value="v2">v2</option>
46
+ </select>
47
+ </div>
48
+
49
+ <div class="form-row">
50
+ <label for="node-input-company"><i class="fa fa-tag"></i> Company</label>
51
+ <input type="text" id="node-input-company" placeholder="company">
52
+ </div>
53
+
54
+ <div class="form-row">
55
+ <label for="node-input-user"><i class="fa fa-tag"></i> User</label>
56
+ <input type="text" id="node-input-user" placeholder="user">
57
+ </div>
58
+
59
+ <div class="form-row">
60
+ <label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
61
+ <input type="password" id="node-input-password" placeholder="password">
62
+ </div>
63
+ </script>
64
+
65
+
66
+ <!-- Documentation -->
67
+ <script type="text/html" data-help-name="authenticateSap">
68
+ <p>Authenticate action</p>
69
+
70
+ <h3>Inputs</h3>
71
+ <dl class="message-properties">
72
+ <dt>Name
73
+ <span class="property-type">string</span>
74
+ </dt>
75
+ <dd> the node's name </dd>
76
+ <dt>Host
77
+ <span class="property-type">string</span>
78
+ </dt>
79
+ <dd> Service layer's hostname </dd>
80
+ <dt>Port
81
+ <span class="property-type">number</span>
82
+ </dt>
83
+ <dd> Service layer's port </dd>
84
+ <dt>Version
85
+ <span class="property-type">[v1,v2]</span>
86
+ </dt>
87
+ <dd> Service layer's version </dd>
88
+ <dt>Company
89
+ <span class="property-type">string</span>
90
+ </dt>
91
+ <dd> Company's name to connect </dd>
92
+ <dt>User
93
+ <span class="property-type">string</span>
94
+ </dt>
95
+ <dd>Username to connect to the company's database </dd>
96
+ <dt>Password
97
+ <span class="property-type">string</span>
98
+ </dt>
99
+ <dd>Password to connect to the company's database </dd>
100
+
101
+ </dl>
102
+
103
+ <h3>Outputs</h3>
104
+ <ol class="node-ports">
105
+ <li>Standard output
106
+ <dl class="message-properties">
107
+ <dt>payload <span class="property-type">string</span></dt>
108
+ <dd>the standard output of the command.</dd>
109
+ </dl>
110
+ </li>
111
+ </ol>
112
+
113
+ <h3>Details</h3>
114
+ <p>this node is used to authenticate to the service layer.
115
+ See the examples to understand how to use it.
116
+ </p>
117
+ <!-- <p><code>msg.payload</code> is used as the payload of the published message.
118
+ If it contains an Object it will be converted to a JSON string before being sent.
119
+ If it contains a binary Buffer the message will be published as-is.</p>
120
+ <p>The topic used can be configured in the node or, if left blank, can be set
121
+ by <code>msg.topic</code>.</p>
122
+ <p>Likewise the QoS and retain values can be configured in the node or, if left
123
+ blank, set by <code>msg.qos</code> and <code>msg.retain</code> respectively.</p> -->
124
+
125
+ <h3>References</h3>
126
+ <ul>
127
+ <li><a href="https://sap-samples.github.io/smb-summit-hackathon/b1sl.html" target="_black">Service layer API docs</a> - for more details </li>
128
+ <li><a href="https://github.com/yousolution-cloud/node-red-contrib-you-sap-service-layer">@yousolution-cloud/node-red-contrib-you-sap-service-layer</a> - the nodes github repository</li>
129
+ </ul>
130
+ </script>
@@ -0,0 +1,72 @@
1
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2
+ const Support = require('./support');
3
+
4
+ module.exports = function (RED) {
5
+ function AuthenticateSapNode(config) {
6
+ RED.nodes.createNode(this, config);
7
+ const node = this;
8
+
9
+ // reset status
10
+ node.status({});
11
+
12
+ const flowContext = node.context().flow;
13
+
14
+ flowContext.set(`_YOU_SapServiceLayer_${node.id}`, {
15
+ host: config.host,
16
+ port: config.port,
17
+ version: config.version,
18
+ credentials: {
19
+ CompanyDB: node.credentials.company,
20
+ UserName: node.credentials.user,
21
+ Password: node.credentials.password,
22
+ },
23
+ });
24
+
25
+ if (!node.credentials.user || !node.credentials.password || !node.credentials.company) {
26
+ node.status({ fill: 'gray', shape: 'ring', text: 'Missing credentials' });
27
+ }
28
+
29
+ node.on('input', async (msg, send, done) => {
30
+ // reset status
31
+ node.status({});
32
+
33
+ if (!node.credentials.user || !node.credentials.password || !node.credentials.company) {
34
+ node.status({ fill: 'red', shape: 'dot', text: 'Missing credentials' });
35
+ done(new Error('Missing credentials'));
36
+ return;
37
+ }
38
+
39
+ const headers = flowContext.get(`_YOU_SapServiceLayer_${node.id}.headers`);
40
+
41
+ msg._YOU_SapServiceLayer = {
42
+ idAuth: node.id,
43
+ };
44
+
45
+ if (!headers) {
46
+ try {
47
+ const result = await Support.login(node, node.id);
48
+ flowContext.set(`_YOU_SapServiceLayer_${node.id}.headers`, result.headers['set-cookie']);
49
+ } catch (error) {
50
+ msg.payload = error;
51
+ if (error.response && error.response.data) {
52
+ msg.statusCode = error.response.status;
53
+ msg.payload = error.response.data;
54
+ }
55
+ node.send(msg);
56
+ node.status({ fill: 'red', shape: 'dot', text: 'disconnected' });
57
+ done(error);
58
+ return;
59
+ }
60
+ }
61
+ node.send(msg);
62
+ node.status({ fill: 'green', shape: 'dot', text: 'connected' });
63
+ });
64
+ }
65
+ RED.nodes.registerType('authenticateSap', AuthenticateSapNode, {
66
+ credentials: {
67
+ company: { type: 'text' },
68
+ user: { type: 'text' },
69
+ password: { type: 'password' },
70
+ },
71
+ });
72
+ };
@@ -0,0 +1,98 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('closeSap',{
3
+ category: 'Sap',
4
+ color: '#FFC300',
5
+ defaults: {
6
+ name: {value: ''},
7
+ entity: {value: ''},
8
+ entityId: {value: ''}
9
+ },
10
+ inputs:1,
11
+ outputs:1,
12
+ icon: 'font-awesome/fa-times-circle-o',
13
+ label: function() {
14
+ return this.name||"Sap close";
15
+ },
16
+ oneditprepare: function() {
17
+ $("#node-input-entityId").typedInput({
18
+ type:"msg",
19
+ types:["msg"],
20
+ typeField: "#node-input-entityId-type",
21
+ value: 'entityId'
22
+ });
23
+ }
24
+ });
25
+ </script>
26
+
27
+ <script type="text/html" data-template-name="closeSap">
28
+ <div class="form-row">
29
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
30
+ <input type="text" id="node-input-name" placeholder="Name">
31
+ </div>
32
+
33
+ <div class="form-row">
34
+ <label for="node-input-type"><i class="fa fa-tag"></i> Entity</label>
35
+ <select name="node-input-entity" id="node-input-entity">
36
+ <option value="DeliveryNotes">DeliveryNotes</option>
37
+ <option value="Drafts">Drafts</option>
38
+ <option value="Orders">Orders</option>
39
+ <option value="PurchaseDeliveryNotes">PurchaseDeliveryNotes</option>
40
+ <option value="PurchaseOrders">PurchaseOrders</option>
41
+ </select>
42
+ </div>
43
+
44
+ <div class="form-row">
45
+ <label for="node-input-type"><i class="fa fa-comment"></i> entityId</label>
46
+ <input type="text" id="node-input-entityId">
47
+ <input type="hidden" id="node-input-entityId-type">
48
+ </div>
49
+ </script>
50
+
51
+ <!-- Documentation -->
52
+ <script type="text/html" data-help-name="closeSap">
53
+ <p>Close action</p>
54
+
55
+ <h3>Inputs</h3>
56
+ <dl class="message-properties">
57
+ <dt>Name
58
+ <span class="property-type">string</span>
59
+ </dt>
60
+ <dd> the node's name </dd>
61
+ <dt>Entity
62
+ <span class="property-type">string</span>
63
+ </dt>
64
+ <dd> the entity name of SAP </dd>
65
+ <dt>entityId
66
+ <span class="property-type">number | string</span>
67
+ </dt>
68
+ <dd> the id of the entity of SAP </dd>
69
+ </dl>
70
+
71
+ <h3>Outputs</h3>
72
+ <ol class="node-ports">
73
+ <li>Standard output
74
+ <dl class="message-properties">
75
+ <dt>payload <span class="property-type">string</span></dt>
76
+ <dd>the standard output of the command.</dd>
77
+ </dl>
78
+ </li>
79
+ </ol>
80
+
81
+ <h3>Details</h3>
82
+ <p>this node is used to close the entity of SAP.
83
+ See the examples to understand how to use it.
84
+ </p>
85
+ <!-- <p><code>msg.payload</code> is used as the payload of the published message.
86
+ If it contains an entity it will be converted to a JSON string before being sent.
87
+ If it contains a binary Buffer the message will be published as-is.</p>
88
+ <p>The topic used can be configured in the node or, if left blank, can be set
89
+ by <code>msg.topic</code>.</p>
90
+ <p>Likewise the QoS and retain values can be configured in the node or, if left
91
+ blank, set by <code>msg.qos</code> and <code>msg.retain</code> respectively.</p> -->
92
+
93
+ <h3>References</h3>
94
+ <ul>
95
+ <li><a href="https://sap-samples.github.io/smb-summit-hackathon/b1sl.html" target="_black">Service layer API docs</a> - for more details </li>
96
+ <li><a href="https://github.com/yousolution-cloud/node-red-contrib-you-sap-service-layer">@yousolution-cloud/node-red-contrib-you-sap-service-layer</a> - the nodes github repository</li>
97
+ </ul>
98
+ </script>
@@ -0,0 +1,32 @@
1
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2
+ const axios = require('axios');
3
+ const Support = require('./support');
4
+
5
+ module.exports = function (RED) {
6
+ function CloseSapNode(config) {
7
+ RED.nodes.createNode(this, config);
8
+ const node = this;
9
+
10
+ // reset status
11
+ node.status({});
12
+
13
+ node.on('input', async (msg, send, done) => {
14
+ // reset status
15
+ node.status({});
16
+
17
+ try {
18
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isClose: true };
19
+ const login = Support.login;
20
+ const result = await Support.sendRequest({ node, msg, config, axios, login, options });
21
+ msg.payload = result.data;
22
+ msg.statusCode = result.status;
23
+ node.status({ fill: 'green', shape: 'dot', text: 'success' });
24
+ node.send(msg);
25
+ } catch (error) {
26
+ node.status({ fill: 'red', shape: 'dot', text: 'Error' });
27
+ done(error);
28
+ }
29
+ });
30
+ }
31
+ RED.nodes.registerType('closeSap', CloseSapNode, {});
32
+ };