iotagent-node-lib 2.17.0 → 2.20.0

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.
Files changed (347) hide show
  1. package/.github/workflows/ci.yml +17 -2
  2. package/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  3. package/.nyc_output/processinfo/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -1
  5. package/CHANGES_NEXT_RELEASE +1 -0
  6. package/README.md +3 -54
  7. package/doc/advanced-topics.md +121 -85
  8. package/doc/api.md +52 -52
  9. package/doc/development.md +13 -6
  10. package/doc/expressionLanguage.md +514 -312
  11. package/doc/installationguide.md +66 -64
  12. package/doc/usermanual.md +48 -16
  13. package/docker/Mosquitto/Dockerfile +1 -0
  14. package/docker/Mosquitto/README.md +1 -0
  15. package/docker/Mosquitto/startMosquitto.sh +9 -4
  16. package/lib/commonConfig.js +1 -14
  17. package/lib/errors.js +0 -16
  18. package/lib/fiware-iotagent-lib.js +4 -2
  19. package/lib/jexlTranformsMap.js +13 -2
  20. package/lib/model/Device.js +4 -1
  21. package/lib/model/Group.js +19 -1
  22. package/lib/plugins/attributeAlias.js +6 -13
  23. package/lib/plugins/bidirectionalData.js +1 -21
  24. package/lib/plugins/expressionParser.js +7 -6
  25. package/lib/plugins/expressionPlugin.js +11 -25
  26. package/lib/plugins/jexlParser.js +8 -4
  27. package/lib/plugins/multiEntity.js +54 -145
  28. package/lib/plugins/pluginUtils.js +12 -48
  29. package/lib/plugins/timestampProcessPlugin.js +1 -46
  30. package/lib/request-shim.js +111 -0
  31. package/lib/services/common/domain.js +6 -2
  32. package/lib/services/common/genericMiddleware.js +6 -2
  33. package/lib/services/common/iotManagerService.js +1 -1
  34. package/lib/services/common/securityServiceKeystone.js +1 -1
  35. package/lib/services/common/securityServiceOAuth2.js +3 -2
  36. package/lib/services/devices/deviceRegistryMongoDB.js +2 -0
  37. package/lib/services/devices/deviceService.js +2 -5
  38. package/lib/services/devices/devices-NGSI-LD.js +1 -1
  39. package/lib/services/devices/devices-NGSI-v2.js +4 -8
  40. package/lib/services/devices/registrationUtils.js +1 -134
  41. package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
  42. package/lib/services/ngsi/entities-NGSI-v2.js +109 -15
  43. package/lib/services/ngsi/ngsiService.js +4 -6
  44. package/lib/services/ngsi/ngsiUtils.js +0 -36
  45. package/lib/services/ngsi/subscriptionService.js +1 -4
  46. package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
  47. package/lib/services/northBound/contextServer-NGSI-v2.js +24 -12
  48. package/lib/services/northBound/contextServer.js +1 -4
  49. package/lib/services/northBound/contextServerUtils.js +0 -81
  50. package/lib/services/northBound/deviceProvisioningServer.js +31 -7
  51. package/lib/services/northBound/northboundServer.js +2 -0
  52. package/lib/services/northBound/restUtils.js +1 -38
  53. package/lib/templates/updateDevice.json +4 -0
  54. package/lib/templates/updateDeviceLax.json +4 -0
  55. package/package.json +10 -16
  56. package/test/tools/utils.js +2 -0
  57. package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
  58. package/test/unit/expressions/jexlExpression-test.js +44 -5
  59. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +19 -66
  60. package/test/unit/general/deviceService-test.js +11 -27
  61. package/test/unit/general/loglevel-api_test.js +6 -11
  62. package/test/unit/general/startup-test.js +2 -1
  63. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +8 -16
  64. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
  65. package/test/unit/mongodb/mongodb-registry-test.js +38 -114
  66. package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
  67. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
  68. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
  69. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
  70. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
  71. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
  72. package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
  73. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
  74. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
  75. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
  76. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
  77. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
  78. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
  79. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
  80. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
  81. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
  82. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
  83. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
  84. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
  85. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
  86. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
  87. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
  88. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
  89. package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
  90. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  92. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  93. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
  94. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
  95. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
  96. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
  97. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
  98. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
  99. package/test/unit/ngsi-ld/general/deviceService-test.js +1 -1
  100. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  101. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  102. package/test/unit/ngsi-ld/general/startup-test.js +1 -0
  103. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  104. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +2 -1
  105. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +2 -6
  106. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  107. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +1 -0
  108. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +1 -0
  109. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +1 -0
  110. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +4 -3
  111. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +1 -0
  112. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +3 -2
  113. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +61 -0
  114. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +2 -1
  115. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +3 -2
  116. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +1 -0
  117. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +42 -54
  118. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +2 -1
  119. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +4 -4
  120. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +3 -5
  121. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +12 -18
  122. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +3 -1
  123. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
  124. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  142. package/test/unit/{examples → ngsiv2/examples}/contextRequests/updateProvisionDevice.json +0 -0
  143. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +37 -4
  144. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +598 -0
  145. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +3 -2
  146. package/test/unit/ngsiv2/general/deviceService-test.js +9 -8
  147. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  148. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  149. package/test/unit/ngsiv2/general/startup-test.js +1 -0
  150. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  151. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  152. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +287 -15
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -1
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +88 -0
  155. package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +20 -49
  156. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +4 -3
  157. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +3 -2
  158. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +526 -0
  159. package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +21 -21
  160. package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +19 -50
  161. package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +5 -4
  162. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +2 -1
  163. package/test/unit/ngsiv2/provisioning/device-registration_test.js +3 -2
  164. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -3
  165. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +42 -53
  166. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +2 -1
  167. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +4 -4
  168. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +3 -4
  169. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +14 -20
  170. package/test/unit/plugins/capture-configuration-inPlugins_test.js +3 -1
  171. package/test/unit/plugins/capture-provision-inPlugins_test.js +8 -18
  172. package/.eslintcache +0 -1
  173. package/.nyc_output/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  174. package/.nyc_output/processinfo/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  175. package/bin/agentConsole.js +0 -257
  176. package/bin/iotAgentTester.js +0 -44
  177. package/lib/command/commandLine.js +0 -918
  178. package/lib/command/migration.js +0 -176
  179. package/lib/services/devices/devices-NGSI-v1.js +0 -310
  180. package/lib/services/ngsi/entities-NGSI-v1.js +0 -299
  181. package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
  182. package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
  183. package/lib/templates/notificationTemplateNgsi1.json +0 -75
  184. package/lib/templates/updateContextNgsi1.json +0 -50
  185. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
  186. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
  187. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
  188. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
  189. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
  190. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
  191. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
  192. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
  193. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
  194. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
  195. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
  196. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
  197. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
  198. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
  199. package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
  200. package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
  201. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
  202. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
  203. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -26
  204. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
  205. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
  206. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
  207. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
  208. package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
  209. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
  210. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
  211. package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
  212. package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
  213. package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
  214. package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
  215. package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
  216. package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
  217. package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
  218. package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
  219. package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
  220. package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
  221. package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
  222. package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
  223. package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
  224. package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
  225. package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
  226. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
  227. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
  228. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
  229. package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
  230. package/test/unit/examples/contextRequests/queryContext1.json +0 -13
  231. package/test/unit/examples/contextRequests/queryContext2.json +0 -13
  232. package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
  233. package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
  234. package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -32
  235. package/test/unit/examples/contextRequests/updateContext1.json +0 -22
  236. package/test/unit/examples/contextRequests/updateContext2.json +0 -22
  237. package/test/unit/examples/contextRequests/updateContext3.json +0 -17
  238. package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
  239. package/test/unit/examples/contextRequests/updateContext4.json +0 -22
  240. package/test/unit/examples/contextRequests/updateContext5.json +0 -19
  241. package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
  242. package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
  243. package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
  244. package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
  245. package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
  246. package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
  247. package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
  248. package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
  249. package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
  250. package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
  251. package/test/unit/examples/contextRequests/updateContextExpressionPlugin10.json +0 -17
  252. package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
  253. package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
  254. package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
  255. package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
  256. package/test/unit/examples/contextRequests/updateContextExpressionPlugin6.json +0 -17
  257. package/test/unit/examples/contextRequests/updateContextExpressionPlugin7.json +0 -27
  258. package/test/unit/examples/contextRequests/updateContextExpressionPlugin8.json +0 -22
  259. package/test/unit/examples/contextRequests/updateContextExpressionPlugin9.json +0 -27
  260. package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
  261. package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
  262. package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
  263. package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
  264. package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
  265. package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
  266. package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
  267. package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
  268. package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
  269. package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
  270. package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
  271. package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
  272. package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
  273. package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
  274. package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
  275. package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
  276. package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
  277. package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
  278. package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
  279. package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
  280. package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
  281. package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
  282. package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
  283. package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
  284. package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
  285. package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
  286. package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
  287. package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -42
  288. package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
  289. package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
  290. package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
  291. package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
  292. package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
  293. package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
  294. package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
  295. package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
  296. package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
  297. package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
  298. package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
  299. package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
  300. package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
  301. package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
  302. package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
  303. package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
  304. package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
  305. package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
  306. package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
  307. package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
  308. package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
  309. package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
  310. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
  311. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
  312. package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
  313. package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
  314. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
  315. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
  316. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
  317. package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
  318. package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
  319. package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
  320. package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
  321. package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
  322. package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
  323. package/test/unit/general/https-support-test.js +0 -286
  324. package/test/unit/general/iotam-autoregistration-test.js +0 -368
  325. package/test/unit/general/migration-test.js +0 -256
  326. package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
  327. package/test/unit/lazyAndCommands/command-test.js +0 -341
  328. package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
  329. package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
  330. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
  331. package/test/unit/ngsiService/active-devices-test.js +0 -692
  332. package/test/unit/ngsiService/staticAttributes-test.js +0 -148
  333. package/test/unit/ngsiService/subscriptions-test.js +0 -345
  334. package/test/unit/plugins/alias-plugin_test.js +0 -158
  335. package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
  336. package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
  337. package/test/unit/plugins/event-plugin_test.js +0 -119
  338. package/test/unit/plugins/multientity-plugin_test.js +0 -248
  339. package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
  340. package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
  341. package/test/unit/provisioning/device-registration_test.js +0 -432
  342. package/test/unit/provisioning/device-update-registration_test.js +0 -326
  343. package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
  344. package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
  345. package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
  346. package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
  347. package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
@@ -233,42 +233,6 @@ function getMetaData(typeInformation, name, metadata) {
233
233
  return undefined;
234
234
  }
235
235
 
236
- /**
237
- * Given a NGSI v1 Body, determines whether it contains any NGSI error.
238
- *
239
- * @param {String} body String representing a NGSI body in JSON format.
240
- * @return {Number|*}
241
- */
242
- function getErrorField(body) {
243
- let errorField = body.errorCode || body.orionError;
244
-
245
- if (body && body.contextResponses) {
246
- for (const i in body.contextResponses) {
247
- if (body.contextResponses[i].statusCode && body.contextResponses[i].statusCode.code !== '200') {
248
- errorField = body.contextResponses[i].statusCode;
249
- }
250
- }
251
- }
252
-
253
- return errorField;
254
- }
255
-
256
- /**
257
- * Given a NGSI v2 Body, determines whether it contains any NGSI error.
258
- *
259
- * @param {Object} body Object representing a NGSI body in JSON format.
260
- * @return {String|undefined} String with the error and description or undefined if body is not a NGSIv2 error response
261
- */
262
- function getErrorFieldV2(body) {
263
- let errorField = body.error;
264
- if (body.description) {
265
- errorField += ':' + body.description;
266
- }
267
- return errorField;
268
- }
269
-
270
- exports.getErrorField = intoTrans(context, getErrorField);
271
- exports.getErrorFieldV2 = intoTrans(context, getErrorFieldV2);
272
236
  exports.createRequestObject = createRequestObject;
273
237
  exports.applyMiddlewares = applyMiddlewares;
274
238
  exports.getMetaData = getMetaData;
@@ -40,14 +40,11 @@ function init() {
40
40
  case 'ld':
41
41
  subscriptionHandler = require('./subscription-NGSI-LD');
42
42
  break;
43
- case 'v2':
44
- subscriptionHandler = require('./subscription-NGSI-v2');
45
- break;
46
43
  case 'mixed':
47
44
  subscriptionHandler = require('./subscription-NGSI-mixed');
48
45
  break;
49
46
  default:
50
- subscriptionHandler = require('./subscription-NGSI-v1');
47
+ subscriptionHandler = require('./subscription-NGSI-v2');
51
48
  }
52
49
  }
53
50
 
@@ -40,6 +40,7 @@ const context = {
40
40
  const updateContextTemplateNgsiLD = require('../../templates/updateContextNgsiLD.json');
41
41
  const notificationTemplateNgsiLD = require('../../templates/notificationTemplateNgsiLD.json');
42
42
  const contextServerUtils = require('./contextServerUtils');
43
+ const ngsiLD = require('../ngsi/entities-NGSI-LD');
43
44
 
44
45
  const updatePaths = ['/ngsi-ld/v1/entities/:entity/attrs/:attr'];
45
46
  const queryPaths = ['/ngsi-ld/v1/entities/:entity'];
@@ -250,10 +251,10 @@ function defaultQueryHandlerNgsiLD(id, type, service, subservice, attributes, ca
250
251
  attributeType = lazyAttribute.type;
251
252
  }
252
253
 
253
- contextElement[attributes[i]] = {
254
+ contextElement[attributes[i]] = ngsiLD.convertAttrNGSILD({
254
255
  type: attributeType,
255
256
  value: ''
256
- };
257
+ });
257
258
  }
258
259
 
259
260
  callback(null, contextElement);
@@ -408,6 +409,10 @@ function handleQueryNgsiLD(req, res, next) {
408
409
  }
409
410
 
410
411
  logger.debug(context, 'Handling query from [%s]', req.get('host'));
412
+ if ((req.is('json') || req.is('application/ld+json')) === false) {
413
+ return handleQueryContextRequests(new errors.UnsupportedContentType(req.header('content-type')));
414
+ }
415
+
411
416
  if (req.body) {
412
417
  logger.debug(context, JSON.stringify(req.body, null, 4));
413
418
  }
@@ -538,25 +538,37 @@ function handleQueryNgsi2(req, res, next) {
538
538
  logger.debug(context, JSON.stringify(req.body, null, 4));
539
539
  }
540
540
  const contextEntity = {};
541
+ const entities = req.body.entities || [];
541
542
 
542
- // At the present moment, IOTA supports query request with one entity and without patterns. This is aligned
543
- // with the utilization cases in combination with ContextBroker. Other cases are returned as error
544
- if (req.body.entities.length !== 1) {
543
+ if (!req.is('json')) {
545
544
  logger.warn(
546
- 'queries with entities number different to 1 are not supported (%d found)',
547
- req.body.entities.length
545
+ 'queries must offer JSON entities, content-type not supported (%s found)',
546
+ req.header('content-type')
548
547
  );
549
- handleQueryContextRequests({ code: 400, name: 'BadRequest', message: 'more than one entity in query' });
550
- return;
548
+ return handleQueryContextRequests(new errors.UnsupportedContentType(req.header('content-type')));
549
+ }
550
+
551
+ // At the present moment, IOTA supports query request with one entity and without patterns. This is aligned
552
+ // with the utilization cases in combination with ContextBroker. Other cases are returned as error
553
+ if (entities.length !== 1) {
554
+ logger.warn('queries with entities number different to 1 are not supported (%d found)', entities.length);
555
+ return handleQueryContextRequests({
556
+ code: 400,
557
+ name: 'BadRequest',
558
+ message: 'query does not contain a single entity'
559
+ });
551
560
  }
552
- if (req.body.entities[0].idPattern) {
561
+ if (entities[0].idPattern) {
553
562
  logger.warn('queries with idPattern are not supported');
554
- handleQueryContextRequests({ code: 400, name: 'BadRequest', message: 'idPattern usage in query' });
555
- return;
563
+ return handleQueryContextRequests({
564
+ code: 400,
565
+ name: 'BadRequest',
566
+ message: 'idPattern usage in query'
567
+ });
556
568
  }
557
569
 
558
- contextEntity.id = req.body.entities[0].id;
559
- contextEntity.type = req.body.entities[0].type;
570
+ contextEntity.id = entities[0].id;
571
+ contextEntity.type = entities[0].type;
560
572
  const queryAtts = req.body.attrs;
561
573
  createQueryRequest(queryAtts, contextEntity, handleQueryContextRequests);
562
574
  }
@@ -41,14 +41,11 @@ function init() {
41
41
  case 'ld':
42
42
  contextServerHandler = require('./contextServer-NGSI-LD');
43
43
  break;
44
- case 'v2':
45
- contextServerHandler = require('./contextServer-NGSI-v2');
46
- break;
47
44
  case 'mixed':
48
45
  contextServerHandler = require('./contextServer-NGSI-mixed');
49
46
  break;
50
47
  default:
51
- contextServerHandler = require('./contextServer-NGSI-v1');
48
+ contextServerHandler = require('./contextServer-NGSI-v2');
52
49
  }
53
50
  }
54
51
 
@@ -26,14 +26,10 @@
26
26
 
27
27
  const async = require('async');
28
28
  const apply = async.apply;
29
- const logger = require('logops');
30
29
  const constants = require('../../constants');
31
30
  const config = require('../../commonConfig');
32
31
  const ngsi = require('../ngsi/ngsiService');
33
32
  const commands = require('../commands/commandService');
34
- const context = {
35
- op: 'IoTAgentNGSI.ContextServerUtils'
36
- };
37
33
 
38
34
  /**
39
35
  * Returns the Current Tenant defined for the NGSI-LD Broker. Tenant is based on the request
@@ -68,81 +64,6 @@ function getLDPath(req) {
68
64
  return config.getConfig().contextBroker.fallbackPath;
69
65
  }
70
66
 
71
- /**
72
- * Create the response for an UpdateContext operation, based on the results of the individual updates. The signature
73
- * retains the results object for homogeinity with the createQuery* version.
74
- *
75
- * @param {Object} req Request that was handled in first place.
76
- * @param {Object} res Response that will be sent.
77
- * @param {Object} results Ignored for this function. TODO: to be removed in later versions.
78
- * @return {{contextResponses: Array}}
79
- */
80
-
81
- /* eslint-disable-next-line no-unused-vars */
82
- function createUpdateResponse(req, res, results) {
83
- const result = {
84
- contextResponses: []
85
- };
86
-
87
- for (let i = 0; i < req.body.contextElements.length; i++) {
88
- const contextResponse = {
89
- contextElement: {
90
- attributes: req.body.contextElements[i].attributes,
91
- id: req.body.contextElements[i].id,
92
- isPattern: false,
93
- type: req.body.contextElements[i].type
94
- },
95
- statusCode: {
96
- code: 200,
97
- reasonPhrase: 'OK'
98
- }
99
- };
100
-
101
- for (let j = 0; j < contextResponse.contextElement.attributes.length; j++) {
102
- contextResponse.contextElement.attributes[i].value = '';
103
- }
104
-
105
- result.contextResponses.push(contextResponse);
106
- }
107
-
108
- logger.debug(context, 'Generated update response: %j', result);
109
-
110
- return result;
111
- }
112
-
113
- /**
114
- * Create the response for a queryContext operation based on the individual results gathered from the query handlers.
115
- * The returned response is in the NGSI Response format.
116
- *
117
- * @param {Object} req Request that was handled in first place.
118
- * @param {Object} res Response that will be sent.
119
- * @param {Object} results Individual Context Element results from the query handlers.
120
- * @return {{contextResponses: Array}}
121
- */
122
- function createQueryResponse(req, res, results) {
123
- const result = {
124
- contextResponses: []
125
- };
126
-
127
- for (let i = 0; i < results.length; i++) {
128
- const contextResponse = {
129
- contextElement: results[i],
130
- statusCode: {
131
- code: 200,
132
- reasonPhrase: 'OK'
133
- }
134
- };
135
-
136
- contextResponse.contextElement.isPattern = false;
137
-
138
- result.contextResponses.push(contextResponse);
139
- }
140
-
141
- logger.debug(context, 'Generated query response: %j', result);
142
-
143
- return result;
144
- }
145
-
146
67
  /**
147
68
  * Retrieve the Device that corresponds to a Context Update, and execute the update side effects
148
69
  * if there were any (e.g.: creation of attributes related to comands).
@@ -199,8 +120,6 @@ exports.updateHandler = null;
199
120
  exports.commandHandler = null;
200
121
  exports.queryHandler = null;
201
122
  exports.notificationHandler = null;
202
- exports.createUpdateResponse = createUpdateResponse;
203
- exports.createQueryResponse = createQueryResponse;
204
123
  exports.executeUpdateSideEffects = executeUpdateSideEffects;
205
124
  exports.pushCommandsToQueue = pushCommandsToQueue;
206
125
  exports.getLDTenant = getLDTenant;
@@ -34,6 +34,7 @@ const context = {
34
34
  };
35
35
  const apply = async.apply;
36
36
  let provisioningHandler;
37
+ let updatingHandler;
37
38
  let removeDeviceHandler;
38
39
  let updateDeviceTemplate;
39
40
  let createDeviceTemplate;
@@ -53,6 +54,7 @@ const provisioningAPITranslation = {
53
54
  protocol: 'protocol',
54
55
  transport: 'transport',
55
56
  endpoint: 'endpoint',
57
+ polling: 'polling',
56
58
  attributes: 'active',
57
59
  commands: 'commands',
58
60
  lazy: 'lazy',
@@ -181,7 +183,8 @@ function attributeToProvisioningAPIFormat(attribute) {
181
183
  reverse: attribute.reverse,
182
184
  entity_name: attribute.entity_name,
183
185
  entity_type: attribute.entity_type,
184
- mqtt: attribute.mqtt
186
+ mqtt: attribute.mqtt,
187
+ metadata: attribute.metadata
185
188
  };
186
189
  }
187
190
 
@@ -203,6 +206,7 @@ function toProvisioningAPIFormat(device) {
203
206
  timezone: device.timezone,
204
207
  timestamp: device.timestamp,
205
208
  endpoint: device.endpoint,
209
+ polling: device.polling,
206
210
  transport: device.transport,
207
211
  attributes: device.active ? device.active.map(attributeToProvisioningAPIFormat) : undefined,
208
212
  lazy: device.lazy ? device.lazy.map(attributeToProvisioningAPIFormat) : undefined,
@@ -316,6 +320,14 @@ function handleRemoveDevice(req, res, next) {
316
320
  * This middleware handles updates in the provisioning devices. The only attribute
317
321
  */
318
322
  function handleUpdateDevice(req, res, next) {
323
+ function applyUpdatingHandler(device, callback) {
324
+ if (updatingHandler) {
325
+ updatingHandler(device, callback);
326
+ } else {
327
+ callback(null, device);
328
+ }
329
+ }
330
+
319
331
  if (req.body.device_id) {
320
332
  next(new errors.BadRequest("Can't change the ID of a preprovisioned device"));
321
333
  } else {
@@ -337,12 +349,19 @@ function handleUpdateDevice(req, res, next) {
337
349
  if (req.body.entity_name || req.body.entity_type) {
338
350
  isTypeOrNameUpdated = true;
339
351
  }
340
- deviceService.updateRegister(newDevice, isTypeOrNameUpdated, function handleDeviceUpdate(error) {
341
- if (error) {
342
- next(error);
343
- } else {
344
- res.status(204).json({});
345
- }
352
+ async.waterfall([apply(applyUpdatingHandler, newDevice)], function handleUpdating(
353
+ error,
354
+ newDeviceUpdated
355
+ ) {
356
+ deviceService.updateRegister(newDeviceUpdated, isTypeOrNameUpdated, function handleDeviceUpdate(
357
+ error
358
+ ) {
359
+ if (error) {
360
+ next(error);
361
+ } else {
362
+ res.status(204).json({});
363
+ }
364
+ });
346
365
  });
347
366
  } else {
348
367
  next(new errors.DeviceNotFound(req.params.deviceId));
@@ -391,6 +410,10 @@ function setProvisioningHandler(newHandler) {
391
410
  provisioningHandler = newHandler;
392
411
  }
393
412
 
413
+ function setUpdatingHandler(newHandler) {
414
+ updatingHandler = newHandler;
415
+ }
416
+
394
417
  function setRemoveDeviceHandler(newHandler) {
395
418
  removeDeviceHandler = newHandler;
396
419
  }
@@ -408,6 +431,7 @@ function clear(callback) {
408
431
  exports.setConfiguration = setConfiguration;
409
432
  exports.loadContextRoutes = intoTrans(context, loadContextRoutes);
410
433
  exports.setProvisioningHandler = intoTrans(context, setProvisioningHandler);
434
+ exports.setUpdatingHandler = intoTrans(context, setUpdatingHandler);
411
435
  exports.setRemoveDeviceHandler = intoTrans(context, setRemoveDeviceHandler);
412
436
  exports.addDeviceProvisionMiddleware = addDeviceProvisionMiddleware;
413
437
  exports.clear = clear;
@@ -31,6 +31,7 @@ const domainUtils = require('../common/domain');
31
31
  const middlewares = require('../common/genericMiddleware');
32
32
  const intoTrans = domainUtils.intoTrans;
33
33
  const deviceProvisioning = require('./deviceProvisioningServer');
34
+ const deviceUpdating = require('./deviceProvisioningServer');
34
35
  const groupProvisioning = require('./deviceGroupAdministrationServer');
35
36
  const logger = require('logops');
36
37
  const context = {
@@ -116,6 +117,7 @@ exports.setNotificationHandler = intoTrans(context, contextServer.setNotificatio
116
117
  exports.setConfigurationHandler = intoTrans(context, groupProvisioning.setConfigurationHandler);
117
118
  exports.setRemoveConfigurationHandler = intoTrans(context, groupProvisioning.setRemoveConfigurationHandler);
118
119
  exports.setProvisioningHandler = intoTrans(context, deviceProvisioning.setProvisioningHandler);
120
+ exports.setUpdatingHandler = intoTrans(context, deviceUpdating.setUpdatingHandler);
119
121
  exports.setRemoveDeviceHandler = intoTrans(context, deviceProvisioning.setRemoveDeviceHandler);
120
122
  exports.addDeviceProvisionMiddleware = deviceProvisioning.addDeviceProvisionMiddleware;
121
123
  exports.addConfigurationProvisionMiddleware = groupProvisioning.addConfigurationProvisionMiddleware;
@@ -35,7 +35,7 @@ const context = {
35
35
  op: 'IoTAgentNGSI.RestUtils'
36
36
  };
37
37
  const _ = require('underscore');
38
- const request = require('request');
38
+ const request = require('../../request-shim');
39
39
  const async = require('async');
40
40
  const apply = async.apply;
41
41
  const ngsiService = require('../ngsi/ngsiService');
@@ -123,25 +123,6 @@ function checkBody(template) {
123
123
  };
124
124
  }
125
125
 
126
- /**
127
- * Checks if the timestamp properties of NGSIv1 entities are valid ISO8601 dates.
128
- *
129
- * @param {Object} payload NGSIv1 payload to be analyzed.
130
- * @return {Boolean} true if timestamp attributes are valid ISO8601. false if not.
131
- */
132
- function IsValidTimestamped(payload) {
133
- for (const i in payload.contextElements[0].attributes) {
134
- if (
135
- payload.contextElements[0].attributes[i].name === constants.TIMESTAMP_ATTRIBUTE &&
136
- !moment(payload.contextElements[0].attributes[i].value, moment.ISO_8601).isValid()
137
- ) {
138
- return false;
139
- }
140
- }
141
-
142
- return true;
143
- }
144
-
145
126
  /**
146
127
  * Checks if the timestamp properties of NGSIv2 entities are valid ISO8601 dates.
147
128
  *
@@ -173,22 +154,6 @@ function IsValidTimestampedNgsi2(payload) {
173
154
  return isValidTimestampedNgsi2Entity(payload);
174
155
  }
175
156
 
176
- /**
177
- * Checks if timestamp attributes are included in NGSIv1 entities.
178
- *
179
- * @param {Object} payload NGSIv1 payload to be analyzed.
180
- * @return {Boolean} true if timestamp attributes are included. false if not.
181
- */
182
- function isTimestamped(payload) {
183
- for (const i in payload.contextElements[0].attributes) {
184
- if (payload.contextElements[0].attributes[i].name === constants.TIMESTAMP_ATTRIBUTE) {
185
- return true;
186
- }
187
- }
188
-
189
- return false;
190
- }
191
-
192
157
  /**
193
158
  * Checks if timestamp attributes are included in NGSIv2 entities.
194
159
  *
@@ -273,7 +238,5 @@ exports.executeWithSecurity = executeWithSecurity;
273
238
  exports.checkMandatoryQueryParams = intoTrans(context, checkMandatoryQueryParams);
274
239
  exports.checkRequestAttributes = intoTrans(context, checkRequestAttributes);
275
240
  exports.checkBody = intoTrans(context, checkBody);
276
- exports.isTimestamped = isTimestamped;
277
- exports.IsValidTimestamped = IsValidTimestamped;
278
241
  exports.isTimestampedNgsi2 = isTimestampedNgsi2;
279
242
  exports.IsValidTimestampedNgsi2 = IsValidTimestampedNgsi2;
@@ -177,6 +177,10 @@
177
177
  }
178
178
  }
179
179
  },
180
+ "internal_attributes": {
181
+ "description": "Free form array of internal attributes for particular IOTAgents",
182
+ "type": "any"
183
+ },
180
184
  "static_attributes": {
181
185
  "description": "Free form array of data to be appended to the target entity",
182
186
  "type": "array"
@@ -149,6 +149,10 @@
149
149
  }
150
150
  }
151
151
  },
152
+ "internal_attributes": {
153
+ "description": "Free form array of internal attributes for particular IOTAgents",
154
+ "type": "any"
155
+ },
152
156
  "static_attributes": {
153
157
  "description": "Free form array of data to be appended to the target entity",
154
158
  "type": "array"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "iotagent-node-lib",
3
3
  "license": "AGPL-3.0-only",
4
4
  "description": "IoT Agent library to interface with NGSI Context Broker",
5
- "version": "2.17.0",
5
+ "version": "2.20.0",
6
6
  "homepage": "https://github.com/telefonicaid/iotagent-node-lib",
7
7
  "keywords": [
8
8
  "fiware",
@@ -21,22 +21,20 @@
21
21
  "bugs": {
22
22
  "url": "https://github.com/telefonicaid/iotagent-node-lib/issues"
23
23
  },
24
- "bin": {
25
- "agentConsole": "bin/agentConsole.js",
26
- "iotAgentTester": "bin/iotAgentTester.js"
27
- },
28
24
  "main": "lib/fiware-iotagent-lib",
29
25
  "engines": {
30
26
  "node": ">=12"
31
27
  },
32
28
  "scripts": {
33
29
  "clean": "rm -rf package-lock.json && rm -rf node_modules && rm -rf coverage",
34
- "lint": "eslint lib/ bin/ test/ --cache --fix",
30
+ "lint": "eslint lib/ test/ --cache --fix",
35
31
  "lint:md": "remark -f '*.md' 'doc/*.md'",
36
32
  "lint:text": "textlint '*.md' 'doc/*.md'",
37
33
  "prettier": "prettier --config .prettierrc.json --write '**/**/**/**/*.js' '**/**/**/*.js' '**/**/*.js' '**/*.js' '*.js'",
38
34
  "prettier:text": "prettier 'README.md' 'doc/*.md' 'doc/**/*.md' --no-config --tab-width 4 --print-width 120 --write --prose-wrap always",
39
- "test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
35
+ "test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 8000 --ui bdd --exit --color true",
36
+ "test:expression": "nyc --reporter=text mocha --recursive 'test/unit/expressions/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
37
+ "test:multientity": "nyc --reporter=text mocha --recursive 'test/unit/ngsiv2/plugins/multientity-plugin_test.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
40
38
  "test:debug": "mocha --recursive 'test/**/*.js' --reporter spec --inspect-brk --timeout 30000 --ui bdd --exit",
41
39
  "test:coverage": "nyc --reporter=lcov mocha -- --recursive 'test/**/*.js' --reporter spec --timeout 5000 --exit",
42
40
  "test:coveralls": "npm run test:coverage && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
@@ -46,18 +44,16 @@
46
44
  "dependencies": {
47
45
  "async": "2.6.2",
48
46
  "body-parser": "~1.19.0",
49
- "command-shell-lib": "1.0.0",
50
47
  "express": "~4.16.4",
51
- "jexl": "2.1.1",
48
+ "got": "~11.8.2",
49
+ "jexl": "2.3.0",
52
50
  "jison": "0.4.18",
53
- "logops": "2.1.0",
51
+ "logops": "2.1.2",
54
52
  "moment": "~2.24.0",
55
53
  "moment-timezone": "~0.5.25",
56
54
  "mongodb": "3.6.8",
57
55
  "mongoose": "5.7.7",
58
- "mu2": "~0.5.20",
59
56
  "query-string": "6.5.0",
60
- "request": "2.88.0",
61
57
  "revalidator": "~0.3.1",
62
58
  "underscore": "~1.12.1",
63
59
  "uuid": "~3.3.2"
@@ -92,12 +88,10 @@
92
88
  },
93
89
  "lint-staged": {
94
90
  "*.md": [
95
- "prettier --parser markdown --tab-width 4 --print-width 120 --write --prose-wrap always",
96
- "git add"
91
+ "prettier --parser markdown --tab-width 4 --print-width 120 --write --prose-wrap always"
97
92
  ],
98
93
  "*.js": [
99
- "prettier --config .prettierrc.json --write",
100
- "git add"
94
+ "prettier --config .prettierrc.json --write"
101
95
  ]
102
96
  }
103
97
  }
@@ -22,6 +22,7 @@
22
22
  */
23
23
 
24
24
  const fs = require('fs');
25
+ const request = require('../../lib/fiware-iotagent-lib').request;
25
26
 
26
27
  function readExampleFile(name, raw) {
27
28
  let text = null;
@@ -36,3 +37,4 @@ function readExampleFile(name, raw) {
36
37
  }
37
38
 
38
39
  exports.readExampleFile = readExampleFile;
40
+ exports.request = request;
@@ -41,4 +41,4 @@
41
41
  "attributes": []
42
42
  }
43
43
  ]
44
- }
44
+ }
@@ -23,6 +23,7 @@
23
23
 
24
24
  const should = require('should');
25
25
  const expressionParser = require('../../../lib/plugins/jexlParser');
26
+ expressionParser.setTransforms({});
26
27
 
27
28
  describe('Jexl expression interpreter', function () {
28
29
  const scope = {
@@ -203,6 +204,16 @@ describe('Jexl expression interpreter', function () {
203
204
  });
204
205
  });
205
206
 
207
+ describe('When an slice function is used with an string', function () {
208
+ it('should work on the expression value', function (done) {
209
+ expressionParser.parse('"AABBCC"|slice(2,4)', scope, function (error, result) {
210
+ should.not.exist(error);
211
+ result.should.equal('BB');
212
+ done();
213
+ });
214
+ });
215
+ });
216
+
206
217
  describe('When an ternary operator is used with an expression', function () {
207
218
  it('should work on the expression value', function (done) {
208
219
  expressionParser.parse('value == 6? true : false', scope, function (error, result) {
@@ -258,7 +269,7 @@ describe('Jexl expression interpreter', function () {
258
269
  const noMap = "I'm not what you expect";
259
270
 
260
271
  it('it should detect when it is not a map', function (done) {
261
- let [error, message, resultMap] = expressionParser.checkTransformationMap(noMap);
272
+ const [error, message, resultMap] = expressionParser.checkTransformationMap(noMap);
262
273
  should.exist(error);
263
274
  message.should.equal('No trasformations were added to JEXL Parser');
264
275
  resultMap.should.eql({});
@@ -266,7 +277,7 @@ describe('Jexl expression interpreter', function () {
266
277
  });
267
278
 
268
279
  it('it should be empty {}', function (done) {
269
- let [error, message, resultMap] = expressionParser.checkTransformationMap({});
280
+ const [error, message, resultMap] = expressionParser.checkTransformationMap({});
270
281
  should.not.exist(error);
271
282
  message.should.equal('No trasformations were added to JEXL Parser');
272
283
  resultMap.should.eql({});
@@ -274,7 +285,7 @@ describe('Jexl expression interpreter', function () {
274
285
  });
275
286
 
276
287
  it('it should be empty null', function (done) {
277
- let [error, message, resultMap] = expressionParser.checkTransformationMap(null);
288
+ const [error, message, resultMap] = expressionParser.checkTransformationMap(null);
278
289
  should.not.exist(error);
279
290
  message.should.equal('No trasformations were added to JEXL Parser');
280
291
  resultMap.should.eql({});
@@ -282,7 +293,7 @@ describe('Jexl expression interpreter', function () {
282
293
  });
283
294
 
284
295
  it('it should detect wrong transformations (not a funtion)', function (done) {
285
- let [error, message, resultMap] = expressionParser.checkTransformationMap(wrongMap);
296
+ const [error, message, resultMap] = expressionParser.checkTransformationMap(wrongMap);
286
297
  should.not.exist(error);
287
298
  message.should.equal('wrongTransformation1,wrongTransformation2 must be a function');
288
299
  should.not.exist(resultMap.wrongTransformation1);
@@ -292,7 +303,7 @@ describe('Jexl expression interpreter', function () {
292
303
  });
293
304
 
294
305
  it('it should be correct (map of funtions)', function (done) {
295
- let [error, message, resultMap] = expressionParser.checkTransformationMap(niceMap);
306
+ const [error, message, resultMap] = expressionParser.checkTransformationMap(niceMap);
296
307
  should.not.exist(error);
297
308
  message.should.equal('Trasformations can be added to JEXL parser');
298
309
  resultMap.should.eql(niceMap);
@@ -323,6 +334,17 @@ describe('Jexl expression interpreter', function () {
323
334
  });
324
335
  });
325
336
 
337
+ describe('When a JSON with an NGSI operator is applied', function () {
338
+ it('should work on the expression value', function (done) {
339
+ const scope = { ina: 34, outa: 4 };
340
+ expressionParser.parse('{$inc:ina-outa}', scope, function (error, result) {
341
+ should.not.exist(error);
342
+ result.should.eql({ $inc: 30 });
343
+ done();
344
+ });
345
+ });
346
+ });
347
+
326
348
  describe('When an expression aims at creating an object', function () {
327
349
  it('it should work', function (done) {
328
350
  expressionParser.parse('{type:"Point",coordinates: [value,other]}', scope, function (error, result) {
@@ -332,4 +354,21 @@ describe('Jexl expression interpreter', function () {
332
354
  });
333
355
  });
334
356
  });
357
+
358
+ describe('When an expression access to non existent property', function () {
359
+ it('it should return null', function (done) {
360
+ expressionParser.parse('object["nothing"]', scope, function (error, result) {
361
+ should.not.exist(error);
362
+ should.equal(result, null);
363
+ done();
364
+ });
365
+ });
366
+ it('it should return null', function (done) {
367
+ expressionParser.parse('object["nothing"]?object["nothing"]:null', scope, function (error, result) {
368
+ should.not.exist(error);
369
+ should.equal(result, null);
370
+ done();
371
+ });
372
+ });
373
+ });
335
374
  });