kuzzle-device-manager 0.4.12 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install kuzzle-device-manager
17
17
 
18
18
  ### Online
19
19
 
20
- Open [https://docs.kuzzle.io/kuzzle-iot-platform/device-manager/1](https://docs.kuzzle.io/kuzzle-iot-platform/device-manager/1)
20
+ Open [https://docs.kuzzle.io/official-plugins/device-manager/1/guides/devices/](https://docs.kuzzle.io/official-plugins/device-manager/1/guides/devices/)
21
21
 
22
22
  ### Locally
23
23
 
package/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,5 +1,5 @@
1
- import { Plugin, PluginContext, JSONObject } from 'kuzzle';
2
- import { Decoder, PayloadHandler, AssetMappingsManager, DeviceMappingsManager } from './core-classes';
1
+ import { Plugin, PluginContext, JSONObject, EmbeddedSDK } from 'kuzzle';
2
+ import { PayloadService, BatchWriter, Decoder, PayloadHandler, AssetMappingsManager, DeviceMappingsManager } from './core-classes';
3
3
  export declare type DeviceManagerConfig = {
4
4
  /**
5
5
  * Administration index name
@@ -36,12 +36,12 @@ export declare class DeviceManagerPlugin extends Plugin {
36
36
  private assetController;
37
37
  private deviceController;
38
38
  private engineController;
39
- private payloadService;
39
+ protected payloadService: PayloadService;
40
40
  private deviceManagerEngine;
41
41
  private deviceService;
42
42
  private migrationService;
43
- private batchWriter;
44
- private get sdk();
43
+ protected batchWriter: BatchWriter;
44
+ protected get sdk(): EmbeddedSDK;
45
45
  /**
46
46
  * List of registered decoders.
47
47
  * Map<model, decoder>
@@ -3,5 +3,7 @@ import { CRUDController } from './CRUDController';
3
3
  export declare class AssetController extends CRUDController {
4
4
  get sdk(): EmbeddedSDK;
5
5
  constructor(plugin: Plugin);
6
- create(request: KuzzleRequest): Promise<import("kuzzle").Document>;
6
+ create(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
7
+ [x: string]: any;
8
+ }>>;
7
9
  }
@@ -12,13 +12,15 @@ export declare class CRUDController {
12
12
  *
13
13
  * @param request
14
14
  */
15
- create(request: KuzzleRequest): Promise<import("kuzzle").Document>;
15
+ create(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
16
+ [x: string]: any;
17
+ }>>;
16
18
  /**
17
19
  * Delete an asset or a device depending on the collection.
18
20
  *
19
21
  * @param request
20
22
  */
21
- delete(request: KuzzleRequest): Promise<number>;
23
+ delete(request: KuzzleRequest): Promise<string>;
22
24
  /**
23
25
  * search assets or devices depending on the collection.
24
26
  *
@@ -30,5 +32,7 @@ export declare class CRUDController {
30
32
  *
31
33
  * @param request
32
34
  */
33
- update(request: KuzzleRequest): Promise<import("kuzzle").Document>;
35
+ update(request: KuzzleRequest): Promise<import("kuzzle").KDocument<{
36
+ [x: string]: any;
37
+ }>>;
34
38
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -34,8 +34,8 @@ class DeviceService {
34
34
  }
35
35
  const deviceDocuments = this.formatDevicesContent(devices, document);
36
36
  const { errors, successes } = await this.writeToDatabase(deviceDocuments, async (deviceDocuments) => {
37
- const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, ...options });
38
- await this.sdk.document.mCreate(document.tenantId, 'devices', deviceDocuments, { strict, ...options });
37
+ const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, refresh: options.refresh });
38
+ await this.sdk.document.mCreate(document.tenantId, 'devices', deviceDocuments, { strict, refresh: options.refresh });
39
39
  return {
40
40
  successes: results.successes.concat(updated.successes),
41
41
  errors: results.errors.concat(updated.errors)
@@ -76,8 +76,8 @@ class DeviceService {
76
76
  return { _id: device._id, body: { tenantId: null } };
77
77
  });
78
78
  const { errors, successes } = await this.writeToDatabase(deviceDocuments, async (deviceDocuments) => {
79
- const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, ...options });
80
- await this.sdk.document.mDelete(document.tenantId, 'devices', deviceDocuments.map(device => device._id), { strict, ...options });
79
+ const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, refresh: options.refresh });
80
+ await this.sdk.document.mDelete(document.tenantId, 'devices', deviceDocuments.map(device => device._id), { strict, refresh: options.refresh });
81
81
  return {
82
82
  successes: results.successes.concat(updated.successes),
83
83
  errors: results.errors.concat(updated.errors)
@@ -123,15 +123,15 @@ class DeviceService {
123
123
  assetDocuments.push({ _id: assetId, body: { measures } });
124
124
  }
125
125
  const updatedDevice = await this.writeToDatabase(deviceDocuments, async (deviceDocuments) => {
126
- const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, ...options });
127
- await this.sdk.document.mUpdate(document.tenantId, 'devices', deviceDocuments, { strict, ...options });
126
+ const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, refresh: options.refresh });
127
+ await this.sdk.document.mUpdate(document.tenantId, 'devices', deviceDocuments, { strict, refresh: options.refresh });
128
128
  return {
129
129
  successes: results.successes.concat(updated.successes),
130
130
  errors: results.errors.concat(updated.errors)
131
131
  };
132
132
  });
133
133
  const updatedAssets = await this.writeToDatabase(assetDocuments, async (assetDocuments) => {
134
- const updated = await this.sdk.document.mUpdate(document.tenantId, 'assets', assetDocuments, { strict, ...options });
134
+ const updated = await this.sdk.document.mUpdate(document.tenantId, 'assets', assetDocuments, { strict, refresh: options.refresh });
135
135
  return {
136
136
  successes: results.successes.concat(updated.successes),
137
137
  errors: results.errors.concat(updated.errors)
@@ -168,15 +168,15 @@ class DeviceService {
168
168
  assetDocuments.push({ _id: device._source.assetId, body: { measures } });
169
169
  }
170
170
  const updatedDevice = await this.writeToDatabase(deviceDocuments, async (deviceDocuments) => {
171
- const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, ...options });
172
- await this.sdk.document.mUpdate(document.tenantId, 'devices', deviceDocuments, { strict, ...options });
171
+ const updated = await this.sdk.document.mUpdate(this.config.adminIndex, 'devices', deviceDocuments, { strict, refresh: options.refresh });
172
+ await this.sdk.document.mUpdate(document.tenantId, 'devices', deviceDocuments, { strict, refresh: options.refresh });
173
173
  return {
174
174
  successes: results.successes.concat(updated.successes),
175
175
  errors: results.errors.concat(updated.errors)
176
176
  };
177
177
  });
178
178
  const updatedAssets = await this.writeToDatabase(assetDocuments, async (assetDocuments) => {
179
- const updated = await this.sdk.document.mUpdate(document.tenantId, 'assets', assetDocuments, { strict, ...options });
179
+ const updated = await this.sdk.document.mUpdate(document.tenantId, 'assets', assetDocuments, { strict, refresh: options.refresh });
180
180
  return {
181
181
  successes: results.successes.concat(updated.successes),
182
182
  errors: results.errors.concat(updated.errors)
@@ -191,7 +191,7 @@ class DeviceService {
191
191
  const { _source: { measures } } = await this.sdk.document.get(tenantId, 'assets', device._source.assetId);
192
192
  for (const [measureName] of Object.entries(device._source.measures)) {
193
193
  if (measures[measureName]) {
194
- measures[measureName] = undefined;
194
+ measures[measureName] = null;
195
195
  }
196
196
  }
197
197
  return measures;
@@ -1,11 +1,13 @@
1
- import { KuzzleRequest, EmbeddedSDK, Plugin } from 'kuzzle';
1
+ import { KuzzleRequest, PluginContext, EmbeddedSDK, Plugin } from 'kuzzle';
2
2
  import { Decoder } from './Decoder';
3
- import { BatchWriter } from './BatchProcessing';
3
+ import { Device, BaseAsset } from '../models';
4
+ import { BatchController, BatchWriter } from './BatchProcessing';
5
+ import { DeviceManagerConfig } from '../DeviceManagerPlugin';
4
6
  export declare type PayloadHandler = (request: KuzzleRequest, decoder: Decoder) => Promise<any>;
5
7
  export declare class PayloadService {
6
- private config;
7
- private context;
8
- private batchController;
8
+ protected config: DeviceManagerConfig;
9
+ protected context: PluginContext;
10
+ protected batchController: BatchController;
9
11
  get sdk(): EmbeddedSDK;
10
12
  constructor(plugin: Plugin, batchWriter: BatchWriter);
11
13
  process(request: KuzzleRequest, decoder: Decoder, { refresh }?: {
@@ -31,13 +33,15 @@ export declare class PayloadService {
31
33
  * Get the device entry from the provisioning catalog in corresponding index
32
34
  */
33
35
  private getCatalogEntry;
34
- private update;
36
+ protected update(device: Device, decoder: Decoder, request: KuzzleRequest, { refresh }: {
37
+ refresh: any;
38
+ }): Promise<any>;
35
39
  /**
36
40
  * Propagate the measures inside the asset document.
37
41
  */
38
- private propagateToAsset;
42
+ protected propagateToAsset(tenantId: string, decoder: Decoder, updatedDevice: Device, assetId: string): Promise<BaseAsset>;
39
43
  /**
40
44
  * Creates an history entry for an asset
41
45
  */
42
- private historizeAsset;
46
+ protected historizeAsset(tenantId: string, asset: BaseAsset): Promise<void>;
43
47
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager",
3
- "version": "0.4.12",
3
+ "version": "0.4.15",
4
4
  "description": "Manage your IoT devices and assets. Choose a provisionning strategy, receive and decode payload, handle your IoT business logic.",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "repository": {
@@ -25,29 +25,30 @@
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
27
  "csvtojson": "~2.0.10",
28
+ "kuzzle": "^2.18.0",
28
29
  "kuzzle-plugin-commons": "https://github.com/kuzzleio/kuzzle-plugin-commons/archive/refs/tags/0.0.1.tar.gz",
29
30
  "uuid": "~8.3.2"
30
31
  },
31
32
  "devDependencies": {
32
- "@types/node": "^16.11.11",
33
- "@typescript-eslint/eslint-plugin": "^5.5.0",
34
- "@typescript-eslint/parser": "^5.5.0",
35
- "cucumber": "^6.0.5",
36
- "ergol": "^1.0.1",
37
- "eslint": "^8.4.0",
33
+ "@types/node": "^16.11.27",
34
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
35
+ "@typescript-eslint/parser": "^5.20.0",
36
+ "cucumber": "^6.0.7",
37
+ "ergol": "^1.0.2",
38
+ "eslint": "^8.13.0",
38
39
  "eslint-friendly-formatter": "^4.0.1",
39
40
  "eslint-loader": "^4.0.2",
40
- "kuzzle": "^2.15.2",
41
- "kuzzle-sdk": "^7.7.6",
41
+ "kuzzle": "^2.18.0",
42
+ "kuzzle-sdk": "^7.10.0",
42
43
  "lodash": "^4.17.21",
43
- "mocha": "^9.1.3",
44
+ "mocha": "^9.2.2",
44
45
  "mock-require": "^3.0.3",
45
46
  "rewire": "^5.0.0",
46
47
  "should": "^13.2.3",
47
48
  "should-sinon": "^0.0.6",
48
49
  "sinon": "^12.0.1",
49
- "ts-node": "^10.4.0",
50
- "typescript": "^4.5.2"
50
+ "ts-node": "^10.7.0",
51
+ "typescript": "^4.6.3"
51
52
  },
52
53
  "peerDependencies": {
53
54
  "kuzzle": "^2.15.2"