kuzzle-device-manager 2.0.0-rc12 → 2.0.0-rc16

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.
@@ -53,7 +53,15 @@ class MeasureService {
53
53
  }
54
54
  }
55
55
  const measures = this.buildMeasures(device, asset, decodedPayloads[device._source.reference], payloadUuids);
56
- const updatedMeasures = await this.app.trigger('device-manager:measures:receive', measures, { asset, device });
56
+ /**
57
+ * Event before starting to process new measures.
58
+ *
59
+ * Useful to enrich measures before they are saved.
60
+ */
61
+ const { measures: updatedMeasures } = await this.app.trigger('device-manager:measures:process:before', { asset, device, measures });
62
+ if (device._source.engineId) {
63
+ await this.app.trigger(`engine:${device._source.engineId}:device-manager:measures:process:before`, { asset, device, measures });
64
+ }
57
65
  device.updateMeasures(updatedMeasures);
58
66
  await this.sdk.document.update(this.config.adminIndex, InternalCollection_1.InternalCollection.DEVICES, device._id, { measures: device._source.measures });
59
67
  if (device._source.engineId) {
@@ -65,6 +73,17 @@ class MeasureService {
65
73
  await this.sdk.document.update(device._source.engineId, InternalCollection_1.InternalCollection.ASSETS, asset._id, { measures: asset._source.measures });
66
74
  }
67
75
  }
76
+ /**
77
+ * Event at the end of the measure process pipeline.
78
+ *
79
+ * Useful to trigger alerts.
80
+ *
81
+ * @todo test this
82
+ */
83
+ await this.app.trigger('device-manager:measures:process:after', { asset, device, measures });
84
+ if (device._source.engineId) {
85
+ await this.app.trigger(`engine:${device._source.engineId}:device-manager:measures:process:after`, { asset, device, measures });
86
+ }
68
87
  }
69
88
  }
70
89
  buildMeasures(device, asset, measurements, payloadUuids) {
@@ -130,7 +149,10 @@ class MeasureService {
130
149
  };
131
150
  });
132
151
  // @todo replace with batch.mCreate when available
133
- const { successes } = await this.sdk.document.mCreate(this.config.adminIndex, InternalCollection_1.InternalCollection.DEVICES, newDevices, { refresh, strict: true, });
152
+ const { successes, errors } = await this.sdk.document.mCreate(this.config.adminIndex, InternalCollection_1.InternalCollection.DEVICES, newDevices, { refresh });
153
+ for (const error of errors) {
154
+ this.app.log.error(`Cannot create device "${error.document._id}": ${error.reason}`);
155
+ }
134
156
  return successes.map(({ _source, _id }) => new models_1.Device(_source, _id));
135
157
  }
136
158
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager",
3
- "version": "2.0.0-rc12",
3
+ "version": "2.0.0-rc16",
4
4
  "description": "Manage your IoT devices and assets. Choose a provisioning strategy, receive and decode payload, handle your IoT business logic.",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "repository": {