iotagent-node-lib 3.2.0 → 3.4.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 (184) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +16 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +55 -0
  4. package/.github/advanced-issue-labeler.yml +30 -0
  5. package/.github/workflows/issue-labeler.yml +43 -0
  6. package/README.md +10 -11
  7. package/doc/README.md +16 -0
  8. package/doc/admin.md +565 -0
  9. package/doc/api.md +32 -85
  10. package/doc/deprecated.md +16 -10
  11. package/doc/{architecture.md → devel/architecture.md} +3 -3
  12. package/doc/{Contribution.md → devel/contribution-guidelines.md} +43 -35
  13. package/doc/devel/development.md +1879 -0
  14. package/doc/{northboundinteractions.md → devel/northboundinteractions.md} +18 -33
  15. package/doc/index.md +3 -5
  16. package/doc/requirements.txt +1 -1
  17. package/docker/Mosquitto/Dockerfile +1 -1
  18. package/docker/Mosquitto/README.md +1 -0
  19. package/lib/commonConfig.js +0 -5
  20. package/lib/fiware-iotagent-lib.js +1 -1
  21. package/lib/jexlTranformsMap.js +2 -1
  22. package/lib/model/Device.js +0 -1
  23. package/lib/model/Group.js +0 -1
  24. package/lib/model/dbConn.js +1 -7
  25. package/lib/plugins/jexlParser.js +1 -1
  26. package/lib/request-shim.js +2 -2
  27. package/lib/services/commands/commandService.js +1 -1
  28. package/lib/services/common/genericMiddleware.js +1 -1
  29. package/lib/services/common/iotManagerService.js +0 -1
  30. package/lib/services/devices/deviceRegistryMemory.js +2 -2
  31. package/lib/services/devices/deviceRegistryMongoDB.js +32 -19
  32. package/lib/services/devices/deviceService.js +44 -43
  33. package/lib/services/devices/devices-NGSI-LD.js +14 -2
  34. package/lib/services/devices/devices-NGSI-mixed.js +0 -2
  35. package/lib/services/devices/devices-NGSI-v2.js +23 -104
  36. package/lib/services/groups/groupService.js +1 -1
  37. package/lib/services/ngsi/entities-NGSI-LD.js +3 -3
  38. package/lib/services/ngsi/entities-NGSI-v2.js +28 -19
  39. package/lib/services/northBound/deviceProvisioningServer.js +14 -8
  40. package/lib/templates/createDevice.json +0 -4
  41. package/lib/templates/createDeviceLax.json +0 -4
  42. package/lib/templates/deviceGroup.json +1 -5
  43. package/lib/templates/updateDevice.json +4 -0
  44. package/lib/templates/updateDeviceLax.json +11 -0
  45. package/mkdocs.yml +6 -11
  46. package/package.json +3 -3
  47. package/scripts/legacy_expression_tool/README.md +280 -0
  48. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  49. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  50. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +0 -1
  51. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -15
  52. package/test/unit/mongodb/mongodb-registry-test.js +1 -1
  53. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +66 -65
  54. package/test/unit/ngsi-ld/general/https-support-test.js +1 -1
  55. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +8 -7
  56. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  57. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +12 -11
  58. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +41 -39
  59. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +122 -122
  60. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +28 -28
  61. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +18 -17
  62. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +7 -7
  63. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +8 -7
  64. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +12 -0
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -12
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -4
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -4
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -12
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -12
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -4
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +2 -0
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -10
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -4
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -4
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -4
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -12
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -4
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +2 -6
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  142. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  143. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  144. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  145. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  146. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  147. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  148. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  149. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +144 -85
  150. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +20 -53
  151. package/test/unit/ngsiv2/general/https-support-test.js +2 -6
  152. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +8 -24
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +146 -65
  155. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  156. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  157. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +11 -20
  158. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  159. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  160. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +1 -2
  161. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +3 -5
  162. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  163. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  164. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +13 -156
  165. package/test/unit/ngsiv2/provisioning/device-registration_test.js +9 -13
  166. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -10
  167. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  168. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -8
  169. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  170. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  171. package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  172. package/.nyc_output/processinfo/index.json +0 -1
  173. package/doc/config-basic-example.js +0 -20
  174. package/doc/development.md +0 -285
  175. package/doc/howto.md +0 -645
  176. package/doc/installationguide.md +0 -370
  177. package/doc/operations.md +0 -127
  178. package/doc/usermanual.md +0 -900
  179. package/lib/plugins/bidirectionalData.js +0 -356
  180. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +0 -697
  181. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +0 -599
  182. /package/doc/{NorthboundInteractions.postman_collection → devel/NorthboundInteractions.postman_collection} +0 -0
  183. /package/doc/{echo.js → devel/echo.js} +0 -0
  184. /package/doc/{finalResult.js → devel/finalResult.js} +0 -0
package/doc/usermanual.md DELETED
@@ -1,900 +0,0 @@
1
- # Library Functions
2
-
3
- - [Stats Registry](#stats-registry)
4
- - [Alarm module](#alarm-module)
5
- - [Transactions](#transactions)
6
- - [Library overview](#library-overview)
7
- - [Function reference](#function-reference)
8
-
9
- ### Stats Registry
10
-
11
- The library provides a mechanism for the periodic reporting of stats related to the library's work. In order to activate
12
- the use of the periodic stats, it must be configured in the config file, as described in the
13
- [Configuration](installationguide.md#configuration) section.
14
-
15
- The Stats Registry holds two dictionaries, with the same set of stats. For each stat, one of the dictionaries holds the
16
- historical global value and the other one stores the value since the last value reporting (or current value).
17
-
18
- The stats library currently stores only the following values:
19
-
20
- - **deviceCreationRequests**: number of Device Creation Requests that arrived to the API (no matter the result).
21
- - **deviceRemovalRequests**: number of Removal Device Requests that arrived to the API (no matter the result).
22
- - **measureRequests**: number of times the ngsiService.update() function has been invoked (no matter the result).
23
-
24
- More values will be added in the future to the library. The applications using the library can add values to the Stats
25
- Registry just by using the following function:
26
-
27
- ```javascript
28
- iotagentLib.statsRegistry.add("statName", statIncrementalValue, callback);
29
- ```
30
-
31
- The first time this function is invoked, it will add the new stat to the registry. Subsequent calls will add the value
32
- to the specified stat both to the current and global measures. The stat will be cleared in each interval as usual.
33
-
34
- ### Alarm module
35
-
36
- The library provide an alarm module that can be used to track through the logs alarms raised in the IoTAgent. This
37
- module provides:
38
-
39
- - Two functions to raise and release and alarm (`raise()` and `release()`): every alarm is identified by a name and a
40
- description. When the alarm is raised, an error with the text `Raising [%s]` is logged. When the alarm is released,
41
- the corresponding text, `Releasing [%s]` is logged. If an alarm is raised multiple times, it is only logged once. If
42
- its released multiple times it is only released once. Releasing a non-existing alarm has no effect.
43
-
44
- - Functions to list all the raised alarms and clean all the alarms (`list()` and `clean()`).
45
-
46
- - A function to instrument other functions, so when one of that functions return an error, an alarm is raised, and
47
- when it returns a success an alarm is ceased (`intercept()`).
48
-
49
- All this functions can be accessed through the `.alarms` attribute of the library.
50
-
51
- ### Transactions
52
-
53
- The library implements a concept of transactions, in order to follow the execution flow the library follows when
54
- treating requests entering both from the North and the South ports of the IoT Agent.
55
-
56
- To follow the transactions, a new Domain is created for each incoming request; in the case of requests received on the
57
- North Port of the IoT Agent, this domain is automatically created by a Express middleware, and no further action is
58
- needed from the user. For the case of requests received on the South Port of the IoT Agent, the user is responsible of
59
- creating an stopping the transaction, using the `ensureSouthboundDomain` and `finishSouthBoundTransaction`. In this
60
- case, the transaction will last from the invocation to the former to the invocation of the latter.
61
-
62
- The Transaction Correlator is used along all the IoT Platform to follow the trace of a transaction between multiple
63
- components. To do so, in all the HTTP requests sent to other components of the platform, a custom header named
64
- `Fiware-Correlator` is sent with the correlator of the transaction that generated the request. If a component of the
65
- platform receives a request containing this header that starts a transaction, the component will create the transaction
66
- with the received correlator, instead of creating a new one. If the header is not present or the transaction originates
67
- in the component, the transaction ID in this component will be used as the correlator.
68
-
69
- During the duration of a transaction, all the log entries created by the code will write the current Transaction ID and
70
- correlator for the operation being executed.
71
-
72
- ### Library overview
73
-
74
- In order to use the library, add the following dependency to your package.json file:
75
-
76
- ```json
77
- "iotagent-node-lib": "*"
78
- ```
79
-
80
- In order to use this library, first you must require it:
81
-
82
- ```javascript
83
- var iotagentLib = require("iotagent-node-lib");
84
- ```
85
-
86
- The library supports four groups of features, one for each direction of the communication: client-to-server and
87
- server-to-client (and each flow both for the client and the server). Each feature set is defined in the following
88
- sections.
89
-
90
- ### Function reference
91
-
92
- ##### iotagentLib.activate()
93
-
94
- ###### Signature
95
-
96
- ```javascript
97
- function activate(newConfig, callback)
98
- ```
99
-
100
- ###### Description
101
-
102
- Activates the IoT Agent to start listening for NGSI Calls (acting as a Context Provider). It also creates the device
103
- registry for the IoT Agent (based on the deviceRegistry.type configuration option).
104
-
105
- ###### Params
106
-
107
- - newConfig: Configuration of the Context Server (described in the [Configuration](installationguide.md#configuration)
108
- section).
109
-
110
- ##### iotagentLib.deactivate()
111
-
112
- ###### Signature
113
-
114
- ```javascript
115
- function deactivate(callback)
116
- ```
117
-
118
- ###### Description
119
-
120
- Stops the HTTP server.
121
-
122
- ###### Params
123
-
124
- ##### iotagentLib.register()
125
-
126
- ###### Signature
127
-
128
- ```javascript
129
- function registerDevice(deviceObj, callback)
130
- ```
131
-
132
- ###### Description
133
-
134
- Register a new device in the IoT Agent. This registration will also trigger a Context Provider registration in the
135
- Context Broker for all its lazy attributes.
136
-
137
- The device Object can have the following attributes:
138
-
139
- - `id`: Device ID of the device.
140
- - `type`: type to be assigned to the device.
141
- - `name`: name that will be used for the Entity representing the device in the Context Broker.
142
- - `service`: name of the service associated with the device.
143
- - `subservice`: name of the subservice associated with th device.
144
- - `lazy`: list of lazy attributes with their types.
145
- - `active`: list of active attributes with their types.
146
- - `staticAttributes`: list of NGSI attributes to add to the device entity 'as is' in updates, queries and
147
- registrations.
148
- - `internalAttributes`: optional section with free format, to allow specific IoT Agents to store information along
149
- with the devices in the Device Registry.
150
-
151
- The device `id` and `type` are required fields for any registration. The rest of the attributes are optional, but, if
152
- they are not present in the function call arguments, the type must be registered in the configuration, so the service
153
- can infer their default values from the configured type. If an optional attribute is not given in the parameter list and
154
- there isn't a default configuration for the given type, a TypeNotFound error is raised.
155
-
156
- If the device has been previously preprovisioned, the missing data will be completed with the values from the registered
157
- device.
158
-
159
- ###### Params
160
-
161
- - deviceObj: object containing all the information about the device to be registered (mandatory).
162
-
163
- ##### iotagentLib.unregister()
164
-
165
- ###### Signature
166
-
167
- ```javascript
168
- function unregisterDevice(id, service, subservice, callback)
169
- ```
170
-
171
- ###### Description
172
-
173
- Unregister a device from the Context broker and the internal registry.
174
-
175
- ###### Params
176
-
177
- - id: Device ID of the device to register.
178
- - service: Service of the device to unregister.
179
- - subservice: Subservice inside the service for the unregistered device.
180
-
181
- ##### iotagentLib.update()
182
-
183
- ###### Signature
184
-
185
- ```javascript
186
- function update(entityName, attributes, typeInformation, token, callback)
187
- ```
188
-
189
- ###### Description
190
-
191
- Makes an update in the Device's entity in the context broker, with the values given in the 'attributes' array. This
192
- array should comply to the NGSI's attribute format.
193
-
194
- ###### Params
195
-
196
- - entityName: Name of the entity to register.
197
- - attributes: Attribute array containing the values to update.
198
- - typeInformation: Configuration information for the device.
199
- - token: User token to identify against the PEP Proxies (optional).
200
-
201
- ##### iotagentLib.setCommandResult()
202
-
203
- ###### Signature
204
-
205
- ```javascript
206
- function setCommandResult(entityName, resource, apikey, commandName, commandResult, status, deviceInformation, callback)
207
- ```
208
-
209
- ###### Description
210
-
211
- Update the result of a command in the Context Broker. The result of the command has two components: the result of the
212
- command itself will be represented with the suffix `_info` in the entity while the status is updated in the attribute
213
- with the `_status` suffix.
214
-
215
- ###### Params
216
-
217
- - entityName: Name of the entity holding the command.
218
- - resource: Resource name of the endpoint the device is calling.
219
- - apikey: Apikey the device is using to send the values (can be the empty string if none is needed).
220
- - commandName: Name of the command whose result is being updated.
221
- - commandResult: Result of the command in string format.
222
- - deviceInformation: Device information, including security and service information. (optional).
223
-
224
- ##### iotagentLib.listDevices()
225
-
226
- ###### Signature
227
-
228
- ```javascript
229
- function listDevices(callback)
230
- function listDevices(limit, offset, callback)
231
- function listDevices(service, subservice, limit, offset, callback)
232
- ```
233
-
234
- ###### Description
235
-
236
- Return a list of all the devices registered in the specified service and subservice. This function can be invoked in
237
- three different ways:
238
-
239
- - with just one parameter (the callback)
240
- - with three parameters (service, subservice and callback)
241
- - or with five parameters (including limit and offset).
242
-
243
- ###### Params
244
-
245
- - service: service from where the devices will be retrieved.
246
- - subservice: subservice from where the devices will be retrieved.
247
- - limit: maximum number of results to retrieve (optional).
248
- - offset: number of results to skip from the listing (optional).
249
-
250
- ##### iotagentLib.setDataUpdateHandler()
251
-
252
- ###### Signature
253
-
254
- ```javascript
255
- function setDataUpdateHandler(newHandler)
256
- ```
257
-
258
- ###### Description
259
-
260
- Sets the new user handler for Entity update requests. This handler will be called whenever an update request arrives
261
- with the following parameters: (`id`, `type`, `service`, `subservice`, `attributes`, `callback`). Every object within of
262
- the `attributes` array contains `name`, `type` and `value` attributes, and may also include additional attributes for
263
- `metadata` and `datasetId`. The handler is in charge of updating the corresponding values in the devices with the
264
- appropriate protocol.
265
-
266
- Once all the updates have taken place, the callback must be invoked with the updated Context Element. E.g.:
267
-
268
- ```javascript
269
- callback(null, {
270
- type: "TheType",
271
- isPattern: false,
272
- id: "EntityID",
273
- attributes: [
274
- {
275
- name: "lumniscence",
276
- type: "Lumens",
277
- value: "432"
278
- }
279
- ]
280
- });
281
- ```
282
-
283
- In the case of NGSI requests affecting multiple entities, this handler will be called multiple times, one for each
284
- entity, and all the results will be combined into a single response.
285
-
286
- ###### Params
287
-
288
- - newHandler: User handler for update requests
289
-
290
- ##### iotagentLib.setDataQueryHandler()
291
-
292
- ###### Signature
293
-
294
- ```javascript
295
- function setDataQueryHandler(newHandler)
296
- ```
297
-
298
- ###### Description
299
-
300
- Sets the new user handler for Entity query requests. This handler will be called whenever a query request arrives, with
301
- the following parameters: (`id`, `type`, `service`, `subservice`, `attributes`, `callback`). The handler must retrieve
302
- all the corresponding information from the devices and return a NGSI entity with the requested values.
303
-
304
- The callback must be invoked with the updated Context Element, using the information retrieved from the devices. E.g.:
305
-
306
- ```javascript
307
- callback(null, {
308
- type: "TheType",
309
- isPattern: false,
310
- id: "EntityID",
311
- attributes: [
312
- {
313
- name: "lumniscence",
314
- type: "Lumens",
315
- value: "432"
316
- }
317
- ]
318
- });
319
- ```
320
-
321
- In the case of NGSI requests affecting multiple entities, this handler will be called multiple times, one for each
322
- entity, and all the results will be combined into a single response.
323
-
324
- ###### Params
325
-
326
- - newHandler: User handler for query requests.
327
-
328
- ##### iotagentLib.setNotificationHandler()
329
-
330
- ###### Signature
331
-
332
- ```javascript
333
- function setNotificationHandler(newHandler)
334
- ```
335
-
336
- ###### Description
337
-
338
- Sets the new handler for incoming notifications. The notifications are sent by the Context Broker based on the IoT Agent
339
- subscriptions created with the `subscribe()` function.
340
-
341
- The handler must adhere to the following signature:
342
-
343
- ```javascript
344
- function mockedHandler(device, data, callback)
345
- ```
346
-
347
- The `device` parameter contains the device object corresponding to the entity whose changes were notified with the
348
- incoming notification. Take into account that multiple entities may be modified with each single notification. The
349
- handler will be called once for each one of those entities.
350
-
351
- The `data` parameter is an array with all the attributes that were requested in the subscription and its respective
352
- values.
353
-
354
- The handler is expected to call its callback once with no parameters (failing to do so may cause unexpected behaviors in
355
- the IoT Agent).
356
-
357
- ##### iotagentLib.setCommandHandler()
358
-
359
- ###### Signature
360
-
361
- ```javascript
362
- function setCommandHandler(newHandler)
363
- ```
364
-
365
- ###### Description
366
-
367
- Sets the new user handler for registered entity commands. This handler will be called whenever a command request arrives, with
368
- the following parameters: (`id`, `type`, `service`, `subservice`, `attributes`, `callback`). The handler must retrieve
369
- all the corresponding information from the devices and return a NGSI entity with the requested values.
370
-
371
- The callback must be invoked with the updated Context Element, using the information retrieved from the devices. E.g.:
372
-
373
- ```javascript
374
- callback(null, {
375
- type: "TheType",
376
- isPattern: false,
377
- id: "EntityID",
378
- attributes: [
379
- {
380
- name: "lumniscence",
381
- type: "Lumens",
382
- value: "432"
383
- }
384
- ]
385
- });
386
- ```
387
-
388
- In the case of NGSI requests affecting multiple entities, this handler will be called multiple times, one for each
389
- entity, and all the results will be combined into a single response. Only IoT Agents which deal with actuator devices will include a handler for commands.
390
-
391
- ###### Params
392
-
393
- - newHandler: User handler for command requests.
394
-
395
- ##### iotagentLib.setMergePatchHandler()
396
-
397
- ###### Signature
398
-
399
- ```javascript
400
- function setMergePatchHandler(newHandler)
401
- ```
402
-
403
- ###### Description
404
-
405
- Sets the new user handler for NGSI-LD Entity [merge-patch](https://datatracker.ietf.org/doc/html/rfc7386) requests. This handler will be called whenever a merge-patch request arrives, with
406
- the following parameters: (`id`, `type`, `service`, `subservice`, `attributes`, `callback`). The handler must retrieve
407
- all the corresponding information from the devices and return a NGSI entity with the requested values.
408
-
409
- The callback must be invoked with the updated Context Element, using the information retrieved from the devices. E.g.:
410
-
411
- ```javascript
412
- callback(null, {
413
- type: "TheType",
414
- isPattern: false,
415
- id: "EntityID",
416
- attributes: [
417
- {
418
- name: "lumniscence",
419
- type: "Lumens",
420
- value: "432"
421
- }
422
- ]
423
- });
424
- ```
425
-
426
- In the case of NGSI-LD requests affecting multiple entities, this handler will be
427
- called multiple times. Since merge-patch is an advanced function, not all IoT Agents
428
- will include a handler for merge-patch.
429
-
430
- ###### Params
431
-
432
- - newHandler: User handler for merge-patch requests.
433
-
434
- ##### iotagentLib.setProvisioningHandler()
435
-
436
- ###### Signature
437
-
438
- ```javascript
439
- function setProvisioningHandler (newHandler)
440
- ```
441
-
442
- ###### Description
443
-
444
- Sets the new user handler for the provisioning of devices. This handler will be called every time a new device is
445
- created.
446
-
447
- The handler must adhere to the following signature:
448
-
449
- ```javascript
450
- function(newDevice, callback)
451
- ```
452
-
453
- The `newDevice` parameter will contain the newly created device. The handler is expected to call its callback with no
454
- parameters (this handler should only be used for reconfiguration purposes of the IoT Agent).
455
-
456
- ##### iotagentLib.setRemoveDeviceHandler()
457
-
458
- ###### Signature
459
-
460
- ```javascript
461
- function setRemoveDeviceHandler(newHandler)
462
- ```
463
-
464
- ###### Description
465
-
466
- Sets the new user handler for the removal of a device. This handler will be called every time a device is removed.
467
-
468
- The handler must adhere to the following signature:
469
-
470
- ```javascript
471
- function(deviceToDelete, callback)
472
- ```
473
-
474
- The `deviceToDelete` parameter will contain the device to be deleted. The handler is expected to call its callback with
475
- no parameters (this handler should only be used for reconfiguration purposes of the IoT Agent).
476
-
477
- ##### iotagentLib.setConfigurationHandler()
478
-
479
- ###### Signature
480
-
481
- ```javascript
482
- function setConfigurationHandler(newHandler)
483
- ```
484
-
485
- ###### Description
486
-
487
- Sets the new user handler for the configuration updates. This handler will be called every time a new configuration is
488
- created or an old configuration is updated.
489
-
490
- The handler must adhere to the following signature:
491
-
492
- ```javascript
493
- function(newConfiguration, callback)
494
- ```
495
-
496
- The `newConfiguration` parameter will contain the newly created configuration. The handler is expected to call its
497
- callback with no parameters (this handler should only be used for reconfiguration purposes of the IoT Agent).
498
-
499
- For the cases of multiple updates (a single Device Configuration POST that will create several device groups), the
500
- handler will be called once for each of the configurations (both in the case of the creations and the updates).
501
-
502
- The handler will be also called in the case of updates related to configurations. In that situation, the
503
- `newConfiguration` parameter contains also the fields needed to identify the configuration to be updated, i.e.,
504
- `service`, `subservice`, `resource` and `apikey`.
505
-
506
- ##### iotagentLib.setRemoveConfigurationHandler()
507
-
508
- ###### Signature
509
-
510
- ```javascript
511
- function setRemoveConfigurationHandler(newHandler)
512
- ```
513
-
514
- ###### Description
515
-
516
- Sets the new user handler for the removal of configuratios. This handler will be called every time a configuration is
517
- removed.
518
-
519
- The handler must adhere to the following signature:
520
-
521
- ```javascript
522
- function(configurationToDelete, callback)
523
- ```
524
-
525
- The `configurationToDelete` parameter will contain the configuration to be deleted. The handler is expected to call its
526
- callback with no parameters (this handler should only be used for reconfiguration purposes of the IoT Agent).
527
-
528
- ##### iotagentLib.getDevice()
529
-
530
- ###### Signature
531
-
532
- ```javascript
533
- function getDevice(deviceId, service, subservice, callback)
534
- ```
535
-
536
- ###### Description
537
-
538
- Retrieve all the information about a device from the device registry.
539
-
540
- ###### Params
541
-
542
- - deviceId: ID of the device to be found.
543
- - service: Service for which the requested device.
544
- - subservice: Subservice inside the service for which the device is requested.
545
-
546
- ##### iotagentLib.getDeviceByName()
547
-
548
- ###### Signature
549
-
550
- ```javascript
551
- function getDeviceByName(deviceName, service, subservice, callback)
552
- ```
553
-
554
- ###### Description
555
-
556
- Retrieve a device from the registry based on its entity name.
557
-
558
- ###### Params
559
-
560
- - deviceName: Name of the entity associated to a device.
561
- - service: Service the device belongs to.
562
- - subservice: Division inside the service.
563
-
564
- ##### iotagentLib.getDevicesByAttribute()
565
-
566
- ###### Signature
567
-
568
- ```javascript
569
- function getDevicesByAttribute(attributeName, attributeValue, service, subservice, callback)
570
- ```
571
-
572
- ###### Description
573
-
574
- Retrieve all the devices having an attribute named `name` with value `value`.
575
-
576
- ###### Params
577
-
578
- - name: name of the attribute to match.
579
- - value: value to match in the attribute.
580
- - service: Service the device belongs to.
581
- - subservice: Division inside the service.
582
-
583
- ##### iotagentLib.retrieveDevice()
584
-
585
- ###### Signature
586
-
587
- ```javascript
588
- function retrieveDevice(deviceId, apiKey, callback)
589
- ```
590
-
591
- ###### Description
592
-
593
- Retrieve a device from the device repository based on the given APIKey and DeviceID, creating one if none is found for
594
- the given data.
595
-
596
- ###### Params
597
-
598
- - deviceId: Device ID of the device that wants to be retrieved or created.
599
- - apiKey: APIKey of the Device Group (or default APIKey).
600
-
601
- ##### iotagentLib.mergeDeviceWithConfiguration()
602
-
603
- ###### Signature
604
-
605
- ```javascript
606
- function mergeDeviceWithConfiguration(fields, defaults, deviceData, configuration, callback)
607
- ```
608
-
609
- ###### Description
610
-
611
- Complete the information of the device with the information in the configuration group (with precedence of the device).
612
- The first argument indicates what fields would be merged.
613
-
614
- ###### Params
615
-
616
- - fields: Fields that will be merged.
617
- - defaults: Default values fot each of the fields.
618
- - deviceData: Device data.
619
- - configuration: Configuration data.
620
-
621
- ##### iotagentLib.getConfiguration()
622
-
623
- ###### Signature
624
-
625
- ```javascript
626
- function getConfiguration(resource, apikey, callback)
627
- ```
628
-
629
- ###### Description
630
-
631
- Gets the device group identified by the given (`resource`, `apikey`) pair.
632
-
633
- ###### Params
634
-
635
- - resource: representation of the configuration in the IoT Agent (dependent on the protocol) .
636
- - apikey: special key the devices will present to prove they belong to a particular configuration.
637
-
638
- ##### iotagentLib.findConfiguration()
639
-
640
- ###### Signature
641
-
642
- ```javascript
643
- function findConfiguration(service, subservice, callback)
644
- ```
645
-
646
- ###### Description
647
-
648
- Find a device group based on its service and subservice.
649
-
650
- ###### Params
651
-
652
- - service: name of the service of the configuration.
653
- - subservice: name of the subservice of the configuration.
654
-
655
- ##### iotagentLib.getEffectiveApiKey()
656
-
657
- ###### Signature
658
-
659
- ```javascript
660
- function getEffectiveApiKey(service, subservice, type, callback)
661
- ```
662
-
663
- ###### Description
664
-
665
- Get the API Key for the selected service if there is any, or the default API Key if a specific one does not exist.
666
-
667
- ###### Params
668
-
669
- - service: Name of the service whose API Key we are retrieving.
670
- - subservice: Name of the subservice whose API Key we are retrieving.
671
- - type: Type of the device.
672
-
673
- ##### iotagentLib.subscribe()
674
-
675
- ###### Signature
676
-
677
- ```javascript
678
- function subscribe(device, triggers, content, callback)
679
- ```
680
-
681
- ###### Description
682
-
683
- Creates a subscription for the IoTA to the entity representing the selected device.
684
-
685
- ###### Params
686
-
687
- - device: Object containing all the information about a particular device.
688
- - triggers: Array with the names of the attributes that would trigger the subscription
689
- - content: Array with the names of the attributes to retrieve in the notification.
690
-
691
- ##### iotagentLib.unsubscribe()
692
-
693
- ###### Signature
694
-
695
- ```javascript
696
- function unsubscribe(device, id, callback)
697
- ```
698
-
699
- ###### Description
700
-
701
- Removes a single subscription from the selected device, identified by its ID.
702
-
703
- ###### Params
704
-
705
- - `device`: Object containing all the information about a particular device.
706
- - `id`: ID of the subscription to remove.
707
-
708
- ##### iotagentLib.ensureSouthboundDomain()
709
-
710
- ###### Signature
711
-
712
- ```javascript
713
- function ensureSouthboundTransaction(context, callback)
714
- ```
715
-
716
- ###### Description
717
-
718
- Ensures that the current operation is executed inside a transaction with all the information needed for the appropriate
719
- platform logging: start date, transaction ID and correlator in case one is needed. If the function is executed in the
720
- context of a previous transaction, just the context is changed (and the Transaction ID and start time are kept).
721
-
722
- ###### Params
723
-
724
- - context: New context data for the transaction.
725
-
726
- ##### iotagentLib.finishSouthBoundTransaction()
727
-
728
- ###### Signature
729
-
730
- ```javascript
731
- function finishSouthboundTransaction(callback)
732
- ```
733
-
734
- ###### Description
735
-
736
- Terminates the current transaction, if there is any, cleaning its context.
737
-
738
- ##### iotagentLib.startServer()
739
-
740
- ###### Signature
741
-
742
- ```javascript
743
- function startServer(newConfig, iotAgent, callback)
744
- ```
745
-
746
- ###### Description
747
-
748
- Start the HTTP server either in single-thread or multi-thread (multi-core) based on the value of _multiCore_ variable
749
- (described in the [Configuration](installationguide.md#configuration) section). If the value is `False` (either was
750
- directly specified `False` in the `config.js` or it was not specified and by default is assigned `False`), it is a
751
- normal (single-thread) behaviour. Nevertheless, if _multiCore_ is `True`, the IoTAgent is executed in multi-thread
752
- environment.
753
-
754
- The number of parallel processes is calculated based on the number of available CPUs. In case of some of the process
755
- unexpectedly dead, a new process is created automatically to keep always the maximum of them working in parallel.
756
-
757
- > Note: `startServer()` initializes the server but it does not activate the library. The function in the Node Lib will
758
- > call the `iotAgent.start()` in order to complete the activation of the library. Therefore, it is expected that the IoT
759
- > Agent implement the `iotAgent.start()` function with the proper invocation to the `iotAgentLib.activate()`.
760
-
761
- ###### Params
762
-
763
- - newConfig: Configuration of the Context Server (described in the [Configuration](installationguide.md#configuration)
764
- section).
765
- - iotAgent: The IoT Agent Objects, used to start the agent.
766
- - callback: The callback function.
767
-
768
- ##### iotagentLib.request()
769
-
770
- ###### Signature
771
-
772
- ```javascript
773
- function request(options, callback)
774
- ```
775
-
776
- ###### Description
777
-
778
- Make a direct HTTP request using the underlying request library (currently [got](https://github.com/sindresorhus/got)),
779
- this is useful when creating agents which use an HTTP transport for their southbound commands, and removes the need for
780
- the custom IoT Agent to import its own additional request library
781
-
782
- ###### Params
783
-
784
- - options: definition of the request (see
785
- [got options](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) for more details). The
786
- following attributes are currently exposed.
787
- - `method` - HTTP Method
788
- - `searchParams` - query string params
789
- - `qs` - alias for query string params
790
- - `headers`
791
- - `responseType` - either `text` or `json`. `json` is the default
792
- - `json` - a supplied JSON object as the request body
793
- - `body` - any ASCII text as the request body. It takes precedence over `json` if both are provided at the same
794
- time (not recommended).
795
- - `url` - the request URL
796
- - `uri` - alternative alias for the request URL.
797
- - callback: The callback currently returns an `error` Object, the `response` and `body`. The `body` is parsed to a
798
- JSON object if the `responseType` is JSON.
799
-
800
- #### Generic middlewares
801
-
802
- This collection of utility middlewares is aimed to be used to north of the IoT Agent Library, as well as in other
803
- HTTP-based APIs of the IoT Agents. All the middlewares follow the Express convention of `(req, res, next)` objects, so
804
- this information will not be repeated in the descriptions for the middleware functions. All the middlewares can be added
805
- to the servers using the standard Express mechanisms.
806
-
807
- ##### iotagentLib.middlewares.handleError()
808
-
809
- ###### Signature
810
-
811
- ```javascript
812
- function handleError(error, req, res, next)
813
- ```
814
-
815
- ###### Description
816
-
817
- Express middleware for handling errors in the IoTAs. It extracts the code information to return from the error itself
818
- returning 500 when no error code has been found.
819
-
820
- ##### iotagentLib.middlewares.traceRequest()
821
-
822
- ###### Signature
823
-
824
- ```javascript
825
- function traceRequest(req, res, next)
826
- ```
827
-
828
- ###### Description
829
-
830
- Express middleware for tracing the complete request arriving to the IoTA in debug mode.
831
-
832
- ##### iotagentLib.middlewares.changeLogLevel()
833
-
834
- ###### Signature
835
-
836
- ```javascript
837
- function changeLogLevel(req, res, next)
838
- ```
839
-
840
- ###### Description
841
-
842
- Changes the log level to the one specified in the request.
843
-
844
- ##### iotagentLib.middlewares.ensureType()
845
-
846
- ###### Signature
847
-
848
- ```javascript
849
- function ensureType(req, res, next)
850
- ```
851
-
852
- ###### Description
853
-
854
- Ensures the request type is one of the supported ones.
855
-
856
- ##### iotagentLib.middlewares.validateJson()
857
-
858
- ###### Signature
859
-
860
- ```javascript
861
- function validateJson(template)
862
- ```
863
-
864
- ###### Description
865
-
866
- Generates a Middleware that validates incoming requests based on the JSON Schema template passed as a parameter.
867
-
868
- Returns an Express middleware used in request validation with the given template.
869
-
870
- ###### Params
871
-
872
- - _template_: JSON Schema template to validate the request.
873
-
874
- ##### iotagentLib.middlewares.retrieveVersion()
875
-
876
- ###### Signature
877
-
878
- ```javascript
879
- function retrieveVersion(req, res, next)
880
- ```
881
-
882
- ###### Description
883
-
884
- Middleware that returns all the IoTA information stored in the module.
885
-
886
- ##### iotagentLib.middlewares.setIotaInformation()
887
-
888
- ###### Signature
889
-
890
- ```javascript
891
- function setIotaInformation(newIoTAInfo)
892
- ```
893
-
894
- ###### Description
895
-
896
- Stores the information about the IoTAgent for further use in the `retrieveVersion()` middleware.
897
-
898
- ###### Params
899
-
900
- - _newIoTAInfo_: Object containing all the IoTA Information.