@itentialopensource/adapter-alkira 0.1.2 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ## 0.1.3 [04-06-2023]
3
+
4
+ * bug fix for getConfig and iapGetDeviceCount in adapterBase.js
5
+
6
+ See merge request itentialopensource/adapters/cloud/adapter-alkira!2
7
+
8
+ ---
9
+
2
10
  ## 0.1.2 [12-21-2022]
3
11
 
4
12
  * Updates to authentication schemas
package/adapterBase.js CHANGED
@@ -1160,72 +1160,65 @@ class AdapterBase extends EventEmitterCl {
1160
1160
  uriMethod = callProps.method;
1161
1161
  }
1162
1162
  if (callProps.query) {
1163
- callQuery = callProps.query;
1163
+ callQuery = { ...callProps.query };
1164
1164
 
1165
1165
  // go through the query params to check for variable values
1166
1166
  const cpKeys = Object.keys(callQuery);
1167
1167
  for (let cp = 0; cp < cpKeys.length; cp += 1) {
1168
- if (callQuery[cpKeys[cp]].startsWith('{') && callQuery[cpKeys[cp]].endsWith('}')) {
1169
- // make any necessary changes to the query params
1170
- if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1171
- const rqKeys = Object.keys(callProps.requestFields);
1172
-
1173
- // get the field from the provided device
1174
- for (let rq = 0; rq < rqKeys.length; rq += 1) {
1175
- if (cpKeys[cp] === rqKeys[rq]) {
1176
- const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1177
-
1178
- // put the value into the query - if it has been specified in the query
1179
- callQuery[cpKeys[cp]] = fieldValue;
1180
- }
1168
+ // make any necessary changes to the query params
1169
+ if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1170
+ const rqKeys = Object.keys(callProps.requestFields);
1171
+
1172
+ // get the field from the provided device
1173
+ for (let rq = 0; rq < rqKeys.length; rq += 1) {
1174
+ if (callQuery[cpKeys[cp]] === rqKeys[rq]) {
1175
+ const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1176
+ // put the value into the query - if it has been specified in the query
1177
+ callQuery[cpKeys[cp]] = fieldValue;
1181
1178
  }
1182
1179
  }
1183
1180
  }
1184
1181
  }
1185
1182
  }
1186
1183
  if (callProps.body) {
1187
- callBody = callProps.body;
1184
+ callBody = { ...callProps.body };
1188
1185
 
1189
1186
  // go through the body fields to check for variable values
1190
1187
  const cbKeys = Object.keys(callBody);
1191
1188
  for (let cb = 0; cb < cbKeys.length; cb += 1) {
1192
- if (callBody[cbKeys[cb]].startsWith('{') && callBody[cbKeys[cb]].endsWith('}')) {
1193
- // make any necessary changes to the query params
1194
- if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1195
- const rqKeys = Object.keys(callProps.requestFields);
1196
-
1197
- // get the field from the provided device
1198
- for (let rq = 0; rq < rqKeys.length; rq += 1) {
1199
- if (cbKeys[cb] === rqKeys[rq]) {
1200
- const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1201
-
1202
- // put the value into the query - if it has been specified in the query
1203
- callBody[cbKeys[cb]] = fieldValue;
1204
- }
1189
+ // make any necessary changes to the query params
1190
+ if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1191
+ const rqKeys = Object.keys(callProps.requestFields);
1192
+
1193
+ // get the field from the provided device
1194
+ for (let rq = 0; rq < rqKeys.length; rq += 1) {
1195
+ if (callBody[cbKeys[cb]] === rqKeys[rq]) {
1196
+ const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1197
+
1198
+ // put the value into the query - if it has been specified in the query
1199
+ callBody[cbKeys[cb]] = fieldValue;
1205
1200
  }
1206
1201
  }
1207
1202
  }
1208
1203
  }
1209
1204
  }
1210
1205
  if (callProps.headers) {
1211
- callHeaders = callProps.headers;
1206
+ callHeaders = { ...callProps.headers };
1212
1207
 
1213
1208
  // go through the body fields to check for variable values
1214
1209
  const chKeys = Object.keys(callHeaders);
1215
1210
  for (let ch = 0; ch < chKeys.length; ch += 1) {
1216
- if (callHeaders[chKeys[ch]].startsWith('{') && callHeaders[chKeys[ch]].endsWith('}')) {
1217
- // make any necessary changes to the query params
1218
- if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1219
- const rqKeys = Object.keys(callProps.requestFields);
1220
-
1221
- // get the field from the provided device
1222
- for (let rq = 0; rq < rqKeys.length; rq += 1) {
1223
- if (chKeys[ch] === rqKeys[rq]) {
1224
- const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1225
-
1226
- // put the value into the query - if it has been specified in the query
1227
- callHeaders[chKeys[ch]] = fieldValue;
1228
- }
1211
+ // make any necessary changes to the query params
1212
+ if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1213
+ const rqKeys = Object.keys(callProps.requestFields);
1214
+
1215
+ // get the field from the provided device
1216
+ for (let rq = 0; rq < rqKeys.length; rq += 1) {
1217
+ if (callHeaders[chKeys[ch]] === rqKeys[rq]) {
1218
+ const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1219
+
1220
+ // put the value into the query - if it has been specified in the query
1221
+ callHeaders[chKeys[ch]] = fieldValue;
1229
1222
  }
1230
1223
  }
1231
1224
  }
@@ -1247,6 +1240,7 @@ class AdapterBase extends EventEmitterCl {
1247
1240
  // if we received an error or their is no response on the results return an error
1248
1241
  if (error) {
1249
1242
  if (handleFail === 'fail') {
1243
+ // IT IS CRASHING RIGHT BELOW HERE
1250
1244
  return callback(null, error);
1251
1245
  }
1252
1246
  return callback({}, null);
@@ -1427,7 +1421,7 @@ class AdapterBase extends EventEmitterCl {
1427
1421
  // Perform component calls here.
1428
1422
  callPromises.push(
1429
1423
  new Promise((resolve, reject) => {
1430
- this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], [devs.list[0]], null, (callRet, callErr) => {
1424
+ this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], [devs.list[0]], [deviceName], (callRet, callErr) => {
1431
1425
  // return an error
1432
1426
  if (callErr) {
1433
1427
  reject(callErr);
@@ -1535,6 +1529,7 @@ class AdapterBase extends EventEmitterCl {
1535
1529
  let myResult = [];
1536
1530
  results.forEach((result) => {
1537
1531
  if (Array.isArray(result)) {
1532
+ // myResult = myResult.concat(result);
1538
1533
  myResult = [...myResult, ...result];
1539
1534
  } else if (Object.keys(result).length > 0) {
1540
1535
  myResult.push(result);
@@ -1691,7 +1686,7 @@ class AdapterBase extends EventEmitterCl {
1691
1686
  // Perform component calls here.
1692
1687
  callPromises.push(
1693
1688
  new Promise((resolve, reject) => {
1694
- this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], [devs.list[0]], null, (callRet, callErr) => {
1689
+ this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], [devs.list[0]], [deviceName], (callRet, callErr) => {
1695
1690
  // return an error
1696
1691
  if (callErr) {
1697
1692
  reject(callErr);
@@ -1708,7 +1703,13 @@ class AdapterBase extends EventEmitterCl {
1708
1703
  return Promise.all(callPromises).then((results) => {
1709
1704
  let myResult = {};
1710
1705
  results.forEach((result) => {
1711
- myResult = { ...myResult, ...result };
1706
+ if (typeof result === 'string') {
1707
+ myResult = { ...myResult, result };
1708
+ } else if (Array.isArray(result)) {
1709
+ myResult = result[0];
1710
+ } else {
1711
+ myResult = { ...myResult, ...result };
1712
+ }
1712
1713
  });
1713
1714
 
1714
1715
  // return the result
@@ -1753,7 +1754,7 @@ class AdapterBase extends EventEmitterCl {
1753
1754
  // Perform component calls here.
1754
1755
  callPromises.push(
1755
1756
  new Promise((resolve, reject) => {
1756
- this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
1757
+ this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], [{ fake: 'fakedata' }], null, (callRet, callErr) => {
1757
1758
  // return an error
1758
1759
  if (callErr) {
1759
1760
  reject(callErr);
@@ -1774,7 +1775,7 @@ class AdapterBase extends EventEmitterCl {
1774
1775
  });
1775
1776
 
1776
1777
  // return the result
1777
- return callback({ count: myResult.length });
1778
+ return callback({ count: Object.keys(myResult).length });
1778
1779
  });
1779
1780
  } catch (ex) {
1780
1781
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-alkira",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "This adapter integrates with system described as: alkiraApi.",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.44.15",
@@ -65,10 +65,10 @@
65
65
  "mongodb": "^4.1.0",
66
66
  "network-diagnostics": "^0.5.3",
67
67
  "nyc": "^15.1.0",
68
+ "prompts": "^2.4.2",
68
69
  "readline-sync": "^1.4.10",
69
70
  "semver": "^7.3.2",
70
- "winston": "^3.3.3",
71
- "prompts": "^2.4.2"
71
+ "winston": "^3.3.3"
72
72
  },
73
73
  "devDependencies": {
74
74
  "chai": "^4.3.4",
Binary file
@@ -1,10 +1,10 @@
1
1
  {
2
- "version": "0.1.0",
3
- "configLines": 46225,
2
+ "version": "0.1.2",
3
+ "configLines": 46212,
4
4
  "scriptLines": 1795,
5
- "codeLines": 40906,
6
- "testLines": 32659,
5
+ "codeLines": 40907,
6
+ "testLines": 32660,
7
7
  "testCases": 1735,
8
- "totalCodeLines": 75360,
8
+ "totalCodeLines": 75362,
9
9
  "wfTasks": 457
10
10
  }