@yousolution/node-red-contrib-you-sap-service-layer 0.1.1 → 0.2.2

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.
@@ -1,88 +1,94 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('patchSap',{
2
+ RED.nodes.registerType('patchSap', {
3
3
  category: 'Sap',
4
4
  color: '#FFC300',
5
5
  defaults: {
6
- name: {value: ''},
7
- method: {value: 'PATCH'},
8
- entity: {value: ''},
9
- udo: {value: ''},
10
- udt: {value: ''},
11
- entityId: {value: ''},
12
- docEntry: {value: ''},
13
- code: {value: ''},
14
- headers: {value: ''},
15
- bodyPatch: {value: ''}
6
+ name: { value: '' },
7
+ method: { value: 'PATCH' },
8
+ entity: { value: '' },
9
+ udo: { value: '' },
10
+ udt: { value: '' },
11
+ entityId: { value: '' },
12
+ docEntry: {
13
+ value: '',
14
+ validate: (v) => true,
15
+ },
16
+ code: {
17
+ value: '',
18
+ validate: (v) => true,
19
+ },
20
+ headers: { value: '' },
21
+ bodyPatch: { value: '' },
16
22
  },
17
- inputs:1,
18
- outputs:1,
23
+ inputs: 1,
24
+ outputs: 1,
19
25
  icon: 'font-awesome/fa-pencil-square',
20
- label: function() {
21
- return this.name||"Sap patch";
26
+ label: function () {
27
+ return this.name || 'Sap patch';
22
28
  },
23
- oneditprepare: function() {
24
- $("#node-input-entityId").typedInput({
25
- type:"msg",
26
- types:["msg"],
27
- typeField: "#node-input-entityId-type",
28
- value: 'entityId'
29
+ oneditprepare: function () {
30
+ $('#node-input-entityId').typedInput({
31
+ type: 'msg',
32
+ types: ['msg'],
33
+ typeField: '#node-input-entityId-type',
34
+ value: 'entityId',
29
35
  });
30
36
 
31
- $("#node-input-docEntry").typedInput({
32
- type:"msg",
33
- types:["msg"],
34
- typeField: "#node-input-docEntry-type",
35
- value: 'docEntry'
37
+ $('#node-input-docEntry').typedInput({
38
+ type: 'msg',
39
+ types: ['msg'],
40
+ typeField: '#node-input-docEntry-type',
41
+ value: 'docEntry',
36
42
  });
37
43
 
38
- $("#node-input-code").typedInput({
39
- type:"msg",
40
- types:["msg"],
41
- typeField: "#node-input-code-type",
42
- value: 'code'
44
+ $('#node-input-code').typedInput({
45
+ type: 'msg',
46
+ types: ['msg'],
47
+ typeField: '#node-input-code-type',
48
+ value: 'code',
43
49
  });
44
50
 
45
- $("#node-input-headers").typedInput({
46
- type:"msg",
47
- types:["msg"],
48
- typeField: "#node-input-headers-type",
49
- value: 'headers'
51
+ $('#node-input-headers').typedInput({
52
+ type: 'msg',
53
+ types: ['msg'],
54
+ typeField: '#node-input-headers-type',
55
+ value: 'headers',
50
56
  });
51
57
 
52
- $("#node-input-bodyPatch").typedInput({
53
- type:"msg",
54
- types:["msg"],
55
- typeField: "#node-input-bodyPatch-type",
56
- value: 'bodyPatch'
58
+ $('#node-input-bodyPatch').typedInput({
59
+ type: 'msg',
60
+ types: ['msg'],
61
+ typeField: '#node-input-bodyPatch-type',
62
+ value: 'bodyPatch',
57
63
  });
58
64
 
59
- jQuery("#node-input-entity").change(function() {
65
+ jQuery('#node-input-entity').change(function () {
60
66
  jQuery('#container-udo').hide();
61
67
  jQuery('#container-docEntry').hide();
62
68
  jQuery('#container-udt').hide();
63
69
  jQuery('#container-code').hide();
64
70
  jQuery('#container-entityId').hide();
65
71
 
66
- if (jQuery(this).val() === 'UDO'){
72
+ if (jQuery(this).val() === 'UDO') {
67
73
  jQuery('#container-udo').show();
68
74
  jQuery('#container-docEntry').show();
69
- }
70
- if (jQuery(this).val() === 'UDT'){
75
+ }
76
+ if (jQuery(this).val() === 'UDT') {
71
77
  jQuery('#container-udt').show();
72
78
  jQuery('#container-code').show();
73
- }
74
- if(jQuery(this).val() !== 'UDO' && jQuery(this).val() !== 'UDT') {
79
+ }
80
+ if (jQuery(this).val() !== 'UDO' && jQuery(this).val() !== 'UDT') {
75
81
  jQuery('#container-entityId').show();
76
82
  }
77
83
  });
78
- }
84
+ },
79
85
  });
80
86
  </script>
81
-
87
+
82
88
  <script type="text/html" data-template-name="patchSap">
83
89
  <div class="form-row">
84
90
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
85
- <input type="text" id="node-input-name" placeholder="Name">
91
+ <input type="text" id="node-input-name" placeholder="Name" />
86
92
  </div>
87
93
 
88
94
  <div class="form-row">
@@ -339,96 +345,80 @@
339
345
  </select>
340
346
  </div>
341
347
 
342
- <div class="form-row" style="display:none" id="container-UDO">
348
+ <div class="form-row" style="display:none" id="container-udo">
343
349
  <label for="node-input-udo"><i class="fa fa-tag"></i> UDO</label>
344
- <input type="text" id="node-input-udo" placeholder="UDO Name">
350
+ <input type="text" id="node-input-udo" placeholder="UDO Name" />
345
351
  </div>
346
352
 
347
- <div class="form-row" style="display:none" id="container-UDT">
353
+ <div class="form-row" style="display:none" id="container-udt">
348
354
  <label for="node-input-udt"><i class="fa fa-tag"></i> UDT</label>
349
- <input type="text" id="node-input-udt" placeholder="UDT Name">
355
+ <input type="text" id="node-input-udt" placeholder="UDT Name" />
350
356
  </div>
351
357
 
352
358
  <div class="form-row" style="display:none" id="container-entityId">
353
359
  <label for="node-input-type"><i class="fa fa-key"></i> EntityId</label>
354
- <input type="text" id="node-input-entityId">
355
- <input type="hidden" id="node-input-entityId-type">
360
+ <input type="text" id="node-input-entityId" />
361
+ <input type="hidden" id="node-input-entityId-type" />
356
362
  </div>
357
363
 
358
364
  <div class="form-row" style="display:none" id="container-docEntry">
359
365
  <label for="node-input-type"><i class="fa fa-gears"></i> DocEntry</label>
360
- <input type="text" id="node-input-docEntry">
361
- <input type="hidden" id="node-input-docEntry-type">
366
+ <input type="text" id="node-input-docEntry" placeholder="DocEntry" />
367
+ <input type="hidden" id="node-input-docEntry-type" />
362
368
  </div>
363
369
 
364
370
  <div class="form-row" style="display:none" id="container-code">
365
371
  <label for="node-input-type"><i class="fa fa-gears"></i> Code</label>
366
- <input type="text" id="node-input-code">
367
- <input type="hidden" id="node-input-code-type">
372
+ <input type="text" id="node-input-code" />
373
+ <input type="hidden" id="node-input-code-type" />
368
374
  </div>
369
375
 
370
376
  <div class="form-row">
371
377
  <label for="node-input-type"><i class="fa fa-gears"></i> Headers</label>
372
- <input type="text" id="node-input-headers">
373
- <input type="hidden" id="node-input-headers-type">
378
+ <input type="text" id="node-input-headers" />
379
+ <input type="hidden" id="node-input-headers-type" />
374
380
  </div>
375
-
381
+
376
382
  <div class="form-row">
377
383
  <label for="node-input-type"><i class="fa fa-gears"></i> BodyPatch</label>
378
- <input type="text" id="node-input-bodyPatch">
379
- <input type="hidden" id="node-input-bodyPatch-type">
384
+ <input type="text" id="node-input-bodyPatch" />
385
+ <input type="hidden" id="node-input-bodyPatch-type" />
380
386
  </div>
381
387
  </script>
382
-
388
+
383
389
  <!-- Documentation -->
384
390
  <script type="text/html" data-help-name="patchSap">
385
391
  <p>Patch action</p>
386
-
392
+
387
393
  <h3>Inputs</h3>
388
394
  <dl class="message-properties">
389
- <dt>Name
390
- <span class="property-type">string</span>
391
- </dt>
392
- <dd> the node's name </dd>
393
- <dt>Entity
394
- <span class="property-type">string</span>
395
- </dt>
396
- <dd> the entity name of SAP </dd>
397
- <dt>entityId
398
- <span class="property-type">number | string</span>
399
- </dt>
400
- <dd> the id of the entity of SAP </dd>
401
- <dt>bodyPatch
402
- <span class="property-type">object</span>
403
- </dt>
404
- <dd> data to update to the entity </dd>
395
+ <dt>payload <span class="property-type">string</span></dt>
396
+ <dd>the standard output of the command.</dd>
405
397
  </dl>
406
-
407
- <h3>Outputs</h3>
408
- <ol class="node-ports">
409
- <li>Standard output
410
- <dl class="message-properties">
411
- <dt>payload <span class="property-type">string</span></dt>
412
- <dd>the standard output of the command.</dd>
413
- </dl>
414
- </li>
415
- </ol>
416
-
398
+ </li>
399
+ </ol>
400
+
417
401
  <h3>Details</h3>
418
- <p>this node is used to update the entity of SAP.
419
- See the examples to understand how to use it.
420
- </p>
421
- <!-- <p><code>msg.payload</code> is used as the payload of the published message.
402
+ <p>this node is used to update the entity of SAP. See the examples to understand how to use it.</p>
403
+ <!-- <p><code>msg.payload</code> is used as the payload of the published message.
422
404
  If it contains an Object it will be converted to a JSON string before being sent.
423
405
  If it contains a binary Buffer the message will be published as-is.</p>
424
406
  <p>The topic used can be configured in the node or, if left blank, can be set
425
407
  by <code>msg.topic</code>.</p>
426
408
  <p>Likewise the QoS and retain values can be configured in the node or, if left
427
409
  blank, set by <code>msg.qos</code> and <code>msg.retain</code> respectively.</p> -->
428
-
410
+
429
411
  <h3>References</h3>
430
- <ul>
431
- <li><a href="https://sap-samples.github.io/smb-summit-hackathon/b1sl.html" target="_black">Service layer API docs</a> - for more details </li>
432
- <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>
433
- </ul>
434
- </script>
412
+ <ul>
413
+ <li>
414
+ <a href="https://sap-samples.github.io/smb-summit-hackathon/b1sl.html" target="_black">Service layer API docs</a>
415
+ - for more details
416
+ </li>
417
+ <li>
418
+ <a href="https://github.com/yousolution-cloud/node-red-contrib-you-sap-service-layer"
419
+ >@yousolution-cloud/node-red-contrib-you-sap-service-layer</a
420
+ >
421
+ - the nodes github repository
422
+ </li>
423
+ </ul>
424
+ </script>
package/nodes/patchSap.js CHANGED
@@ -1,6 +1,7 @@
1
1
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2
2
  const axios = require('axios');
3
3
  const Support = require('./support');
4
+ const { VerifyErrorSL } = require('./manageErrors');
4
5
 
5
6
  module.exports = function (RED) {
6
7
  function PatchSapNode(config) {
@@ -23,10 +24,12 @@ module.exports = function (RED) {
23
24
  const options = { method: 'PATCH', hasRawQuery: false, hasEntityId: true, data: data };
24
25
  const login = Support.login;
25
26
  const result = await Support.sendRequest({ node, msg, config, axios, login, options });
26
- msg.payload = result.data;
27
+ msg.payload = VerifyErrorSL(node, msg, result.data, true);//result.data;
27
28
  msg.statusCode = result.status;
28
- node.status({ fill: 'green', shape: 'dot', text: 'success' });
29
- node.send(msg);
29
+ if(result.status <= 205) {
30
+ node.status({ fill: 'green', shape: 'dot', text: 'success' });
31
+ node.send(msg);
32
+ }
30
33
  } catch (error) {
31
34
  node.status({ fill: 'red', shape: 'dot', text: 'Error' });
32
35
  done(error);
@@ -1,6 +1,7 @@
1
1
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2
2
  const axios = require('axios');
3
3
  const Support = require('./support');
4
+ const { VerifyErrorSL } = require('./manageErrors');
4
5
  const services = require('../resources/services.json');
5
6
 
6
7
  module.exports = function (RED) {
@@ -15,18 +16,15 @@ module.exports = function (RED) {
15
16
  node.status({});
16
17
  try {
17
18
  const data = msg[config.bodyPost];
18
- // if (!data) {
19
- // node.status({ fill: 'red', shape: 'dot', text: 'bodyPost must have value' });
20
- // done(new Error('bodyPost must have value'));
21
- // return;
22
- // }
23
19
  const options = { method: 'POST', hasRawQuery: false, isService: true, data: data };
24
20
  const login = Support.login;
25
21
  const result = await Support.sendRequest({ node, msg, config, axios, login, options });
26
- msg.payload = result;
22
+ msg.payload = VerifyErrorSL(node, msg, result.data);//result.data;
27
23
  msg.statusCode = result.status;
28
- node.status({ fill: 'green', shape: 'dot', text: 'success' });
29
- node.send(msg);
24
+ if(msg.payload) {
25
+ node.status({ fill: 'green', shape: 'dot', text: 'success' });
26
+ node.send(msg);
27
+ }
30
28
  } catch (error) {
31
29
  node.status({ fill: 'red', shape: 'dot', text: 'Error' });
32
30
  done(error);
package/nodes/support.js CHANGED
@@ -7,6 +7,7 @@ const thickIdApi = [
7
7
  'AssetClasses',
8
8
  'AssetDepreciationGroups',
9
9
  'AssetGroups',
10
+ 'AlternateCatNum',
10
11
  'BankChargesAllocationCodes',
11
12
  'BusinessPartners',
12
13
  'CampaignResponseType',
@@ -83,12 +84,7 @@ async function login(node, idAuth) {
83
84
  'Content-Length': dataString.length,
84
85
  },
85
86
  };
86
-
87
- // try {
88
87
  return await axiosLibrary(options);
89
- // } catch (error) {
90
- // throw Error(`ERROR FUNCTION LOGIN: ${error}`);
91
- // }
92
88
  }
93
89
 
94
90
  async function sendRequest({ node, msg, config, axios, login, options }) {
@@ -124,10 +120,13 @@ async function sendRequest({ node, msg, config, axios, login, options }) {
124
120
  msg.statusCode = error.response.status;
125
121
  msg.payload = error.response.data;
126
122
  msg.requestUrl = requestOptions.axiosOptions.url;
127
- node.send(msg);
128
- throw new Error(JSON.stringify(error.response.data));
123
+ //node.send(msg);
124
+ node.error(JSON.stringify(error.response.data), msg);
125
+ //throw new Error(JSON.stringify(error.response.data));
126
+ }
127
+ else {
128
+ throw error;
129
129
  }
130
- throw error;
131
130
  }
132
131
  // }
133
132
  }
@@ -135,10 +134,14 @@ async function sendRequest({ node, msg, config, axios, login, options }) {
135
134
  msg.statusCode = error.response.status;
136
135
  msg.payload = error.response.data;
137
136
  msg.requestUrl = requestOptions.axiosOptions.url;
138
- node.send(msg);
139
- throw new Error(JSON.stringify(error.response.data));
137
+ //node.send(msg);
138
+ node.error(JSON.stringify(error.response.data), msg)
139
+ // throw new Error(JSON.stringify(error.response.data));
140
+ }
141
+ else {
142
+ throw error;
140
143
  }
141
- throw error;
144
+
142
145
  }
143
146
  }
144
147
 
@@ -252,7 +255,13 @@ function generateRequest(node, msg, config, options) {
252
255
  }
253
256
 
254
257
  if (thickIdApi.includes(entity) || config.entity === 'UDT') {
255
- url = `https://${host}:${port}/b1s/${version}/${entity}('${entityId}')`;
258
+ if(Number.isInteger(entityId)){
259
+ url = `https://${host}:${port}/b1s/${version}/${entity}(${entityId})`;
260
+ }
261
+ else {
262
+ url = `https://${host}:${port}/b1s/${version}/${entity}('${entityId}')`;
263
+ }
264
+
256
265
  } else {
257
266
  url = `https://${host}:${port}/b1s/${version}/${entity}(${entityId})`;
258
267
  }
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@yousolution/node-red-contrib-you-sap-service-layer",
3
- "version": "0.1.1",
3
+ "version": "0.2.2",
4
4
  "description": "Unofficial module SAP Service Layer for NODE-RED",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
- "update": "npm pack && mv yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz ./data && cd data && npm i yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz && docker-compose restart",
7
+ "update": "run-script-os",
8
+ "update:linux:darwin": "npm pack && mv yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz ./data && cd data && npm i yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz && docker-compose restart",
9
+ "update:win32": "npm pack && copy yousolution-node-red-contrib-you-sap-service-layer-%npm_package_version%.tgz .\\data\\ && cd .\\data\\ && npm i yousolution-node-red-contrib-you-sap-service-layer-%npm_package_version%.tgz && docker-compose restart",
10
+ "update:default": "npm pack && mv yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz ./data && cd data && npm i yousolution-node-red-contrib-you-sap-service-layer-$npm_package_version.tgz && docker-compose restart",
8
11
  "test": "mocha 'test/**/*.spec.js'",
9
12
  "coverage": "nyc npm run test"
10
13
  },
@@ -37,8 +40,8 @@
37
40
  }
38
41
  },
39
42
  "dependencies": {
40
- "axios": "^0.23.0",
41
- "odata-query": "^6.7.1"
43
+ "axios": "^1.2.2",
44
+ "odata-query": "^7.0.4"
42
45
  },
43
46
  "repository": {
44
47
  "type": "git",
@@ -56,6 +59,7 @@
56
59
  "node-red": "^2.1.4",
57
60
  "node-red-node-test-helper": "^0.2.7",
58
61
  "nyc": "^15.1.0",
62
+ "run-script-os": "^1.1.6",
59
63
  "sinon": "^12.0.1"
60
64
  }
61
65
  }
@@ -200,7 +200,7 @@
200
200
  "NFModelsService": ["NFModelsService_GetList"],
201
201
  "NFTaxCategoriesService": ["NFTaxCategoriesService_GetList"],
202
202
  "OccurrenceCodesService": ["OccurrenceCodesService_GetList"],
203
- "OrdersService": ["OrdersService_GetApprovalTemplates", "OrdersService_HandleApprovalRequest"],
203
+ "OrdersService": ["OrdersService_GetApprovalTemplates", "OrdersService_Preview" ,"OrdersService_HandleApprovalRequest"],
204
204
  "PartnersSetupsService": ["PartnersSetupsService_GetList"],
205
205
  "PaymentBlocksService": ["PaymentBlocksService_GetPaymentBlockList"],
206
206
  "PaymentCalculationService": ["PaymentCalculationService_GetPaymentAmount"],