iotagent-node-lib 4.4.0 → 4.6.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 (100) hide show
  1. package/README.md +67 -272
  2. package/config.js +2 -1
  3. package/doc/README.md +1 -1
  4. package/doc/admin.md +19 -22
  5. package/doc/api.md +621 -155
  6. package/doc/deprecated.md +4 -0
  7. package/doc/devel/architecture.md +5 -135
  8. package/doc/devel/development.md +224 -12
  9. package/doc/getting-started.md +114 -53
  10. package/doc/requirements.txt +1 -1
  11. package/doc/roadmap.md +5 -5
  12. package/docker/Mosquitto/Dockerfile +2 -2
  13. package/docker/Mosquitto/README.md +14 -11
  14. package/lib/commonConfig.js +7 -1
  15. package/lib/constants.js +3 -0
  16. package/lib/fiware-iotagent-lib.js +12 -15
  17. package/lib/jexlTranformsMap.js +3 -1
  18. package/lib/model/dbConn.js +1 -4
  19. package/lib/services/common/alarmManagement.js +3 -0
  20. package/lib/services/devices/deviceRegistryMemory.js +1 -1
  21. package/lib/services/devices/deviceRegistryMongoDB.js +2 -2
  22. package/lib/services/devices/deviceService.js +4 -3
  23. package/lib/services/devices/devices-NGSI-LD.js +5 -5
  24. package/lib/services/devices/devices-NGSI-mixed.js +3 -3
  25. package/lib/services/devices/devices-NGSI-v2.js +5 -5
  26. package/lib/services/groups/groupService.js +1 -1
  27. package/lib/services/ngsi/entities-NGSI-LD.js +321 -571
  28. package/lib/services/ngsi/entities-NGSI-v2.js +348 -281
  29. package/lib/services/ngsi/ngsiService.js +3 -1
  30. package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
  31. package/lib/services/ngsi/subscription-NGSI-v2.js +2 -2
  32. package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
  33. package/lib/services/northBound/deviceProvisioningServer.js +5 -5
  34. package/lib/services/northBound/northboundServer.js +4 -2
  35. package/lib/services/stats/statsRegistry.js +128 -101
  36. package/lib/templates/createDevice.json +0 -24
  37. package/lib/templates/createDeviceLax.json +0 -23
  38. package/lib/templates/deviceGroup.json +1 -25
  39. package/lib/templates/updateDevice.json +0 -24
  40. package/lib/templates/updateDeviceLax.json +0 -23
  41. package/package.json +2 -2
  42. package/scripts/legacy_expression_tool/README.md +0 -1
  43. package/test/functional/README.md +75 -47
  44. package/test/functional/functional-tests-runner.js +9 -4
  45. package/test/functional/functional-tests.js +4 -4
  46. package/test/functional/testCases.js +1251 -257
  47. package/test/functional/testUtils.js +53 -20
  48. package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
  49. package/test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json +4 -0
  50. package/test/unit/examples/groupProvisioningRequests/multipleConfigGroupsCreation.json +44 -0
  51. package/test/unit/examples/groupProvisioningRequests/provisionDuplicateConfigGroup.json +35 -0
  52. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroup.json +36 -0
  53. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroupAlternate.json +36 -0
  54. package/test/unit/general/deviceService-test.js +102 -0
  55. package/test/unit/general/statistics-service_test.js +1 -74
  56. package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
  57. package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -3
  58. package/test/unit/mongodb/mongodb-group-registry-test.js +34 -33
  59. package/test/unit/mongodb/mongodb-service-registry-test.js +477 -0
  60. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +4 -4
  61. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +22 -22
  62. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +4 -4
  63. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +14 -15
  64. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +23 -23
  65. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +0 -5
  66. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +11 -16
  67. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +23 -28
  68. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +8 -13
  69. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
  70. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +24 -29
  71. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +12 -17
  72. package/test/unit/ngsi-ld/examples/contextRequests/updateContextStaticLinkedAttributes.json +12 -10
  73. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -102
  74. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +4 -5
  75. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +5 -5
  76. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +0 -4
  77. package/test/unit/ngsiv2/general/deviceService-test.js +94 -1
  78. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
  79. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +259 -0
  80. package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1189 -0
  81. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +6 -6
  82. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +0 -4
  83. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +35 -0
  84. package/test/unit/statsRegistry/openmetrics-test.js +167 -0
  85. package/lib/templates/queryContext.json +0 -25
  86. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +0 -35
  87. package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json +0 -17
  88. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +0 -31
  89. package/test/unit/general/statistics-persistence_test.js +0 -121
  90. package/test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json +0 -17
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +0 -12
  92. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  93. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +0 -21
  94. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -17
  95. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -23
  96. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +0 -132
  97. package/test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json +0 -8
  98. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  99. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -19
  100. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -24
@@ -1,132 +0,0 @@
1
- /*
2
- * Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::daniel.moranjimenez@telefonica.com
22
- *
23
- * Modified by: Jason Fox - FIWARE Foundation
24
- */
25
-
26
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
- const utils = require('../../../tools/utils');
28
- const should = require('should');
29
- const logger = require('logops');
30
- const nock = require('nock');
31
- const moment = require('moment');
32
- let contextBrokerMock;
33
- const iotAgentConfig = {
34
- contextBroker: {
35
- host: '192.168.1.1',
36
- port: '1026',
37
- ngsiVersion: 'ld',
38
- jsonLdContext: 'http://context.json-ld'
39
- },
40
- server: {
41
- port: 4041,
42
- host: 'localhost'
43
- },
44
- types: {
45
- Light: {
46
- commands: [],
47
- type: 'Light',
48
- lazy: [
49
- {
50
- name: 'temperature',
51
- type: 'centigrades'
52
- }
53
- ],
54
- active: [
55
- {
56
- name: 'pressure',
57
- type: 'Hgmm'
58
- }
59
- ]
60
- }
61
- },
62
- service: 'smartgondor',
63
- subservice: 'gardens',
64
- providerUrl: 'http://smartgondor.com'
65
- };
66
-
67
- describe('NGSI-LD - Timestamp processing plugin', function () {
68
- beforeEach(function (done) {
69
- logger.setLevel('FATAL');
70
-
71
- iotAgentLib.activate(iotAgentConfig, function () {
72
- iotAgentLib.clearAll(function () {
73
- done();
74
- });
75
- });
76
- });
77
-
78
- afterEach(function (done) {
79
- iotAgentLib.clearAll(function () {
80
- iotAgentLib.deactivate(done);
81
- });
82
- });
83
- describe('When an update comes with a timestamp through the plugin', function () {
84
- const values = [
85
- {
86
- name: 'state',
87
- type: 'Boolean',
88
- value: true
89
- },
90
- {
91
- name: 'TimeInstant',
92
- type: 'DateTime',
93
- value: '2016-05-30T16:25:22.304Z'
94
- }
95
- ];
96
-
97
- beforeEach(function () {
98
- nock.cleanAll();
99
-
100
- contextBrokerMock = nock('http://192.168.1.1:1026')
101
- .matchHeader('fiware-service', 'smartgondor')
102
- .post('/ngsi-ld/v1/entityOperations/upsert/?options=update', function (body) {
103
- const expectedBody = utils.readExampleFile(
104
- './test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json'
105
- );
106
-
107
- // Note that TimeInstant fields are not included in the json used by this mock as they are dynamic
108
- // fields. The following code just checks that TimeInstant fields are present.
109
- if (!body[0].state.observedAt) {
110
- return false;
111
- }
112
-
113
- const timeInstantAtt = body[0].state.observedAt;
114
- if (moment(timeInstantAtt, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid) {
115
- delete body[0].state.observedAt;
116
- delete expectedBody[0].state.observedAt;
117
- return JSON.stringify(body) === JSON.stringify(expectedBody);
118
- }
119
- return false;
120
- })
121
- .reply(204);
122
- });
123
-
124
- it('should return an entity with all its timestamps expanded to have separators', function (done) {
125
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
126
- should.not.exist(error);
127
- contextBrokerMock.done();
128
- done();
129
- });
130
- });
131
- });
132
- });
@@ -1,8 +0,0 @@
1
- {
2
- "id": "TheFirstLight",
3
- "type": "TheLightType",
4
- "location": {
5
- "type": "geo:point",
6
- "value": "0, 0"
7
- }
8
- }
@@ -1,13 +0,0 @@
1
- {
2
- "subscriptionId": "51c0ac9ed714fb3b37d7d5a8",
3
- "data": [
4
- {
5
- "location": {
6
- "type": "geo:point",
7
- "value": "12.4, -9.6"
8
- },
9
- "type": "TheLightType",
10
- "id": "TheFirstLight"
11
- }
12
- ]
13
- }
@@ -1,19 +0,0 @@
1
- {
2
- "subscriptionId": "51c0ac9ed714fb3b37d7d5a8",
3
- "data": [
4
- {
5
- "location": {
6
- "type": "geo:point",
7
- "value": "12.4, -9.6",
8
- "metadata": {
9
- "qos": {
10
- "type": "Number",
11
- "value": 1
12
- }
13
- }
14
- },
15
- "type": "TheLightType",
16
- "id": "TheFirstLight"
17
- }
18
- ]
19
- }
@@ -1,24 +0,0 @@
1
- {
2
- "subject":{
3
- "entities": [
4
- {
5
- "id": "TheFirstLight",
6
- "type": "TheLightType"
7
- }
8
- ],
9
- "condition":{
10
- "attrs":[
11
- "location"
12
- ]
13
- }
14
- },
15
- "notification":{
16
- "http":{
17
- "url":"http://smartgondor.com/notify"
18
- },
19
- "attrs":[
20
- "location"
21
- ],
22
- "attrsFormat": "normalized"
23
- }
24
- }