kuzzle-device-manager 0.4.8 → 0.4.12

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 (61) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +17 -0
  3. package/lib/DeviceManagerPlugin.d.ts +100 -0
  4. package/lib/DeviceManagerPlugin.js +237 -0
  5. package/lib/controllers/AssetController.d.ts +7 -0
  6. package/lib/controllers/AssetController.js +53 -0
  7. package/lib/controllers/CRUDController.d.ts +34 -0
  8. package/lib/controllers/CRUDController.js +65 -0
  9. package/lib/controllers/DeviceController.d.ts +56 -0
  10. package/lib/controllers/DeviceController.js +218 -0
  11. package/lib/controllers/index.d.ts +3 -0
  12. package/lib/controllers/index.js +16 -0
  13. package/lib/core-classes/BatchProcessing/BatchController.d.ts +34 -0
  14. package/lib/core-classes/BatchProcessing/BatchController.js +115 -0
  15. package/lib/core-classes/BatchProcessing/BatchWriter.d.ts +110 -0
  16. package/lib/core-classes/BatchProcessing/BatchWriter.js +264 -0
  17. package/lib/core-classes/BatchProcessing/InstrumentablePromise.d.ts +6 -0
  18. package/lib/core-classes/BatchProcessing/InstrumentablePromise.js +13 -0
  19. package/lib/core-classes/BatchProcessing/index.d.ts +3 -0
  20. package/lib/core-classes/BatchProcessing/index.js +16 -0
  21. package/lib/core-classes/CustomMappings/AssetMappingsManager.d.ts +31 -0
  22. package/lib/core-classes/CustomMappings/AssetMappingsManager.js +79 -0
  23. package/lib/core-classes/CustomMappings/DeviceMappingsManager.d.ts +43 -0
  24. package/lib/core-classes/CustomMappings/DeviceMappingsManager.js +71 -0
  25. package/lib/core-classes/Decoder.d.ts +133 -0
  26. package/lib/core-classes/Decoder.js +166 -0
  27. package/lib/core-classes/DeviceManagerEngine.d.ts +21 -0
  28. package/lib/core-classes/DeviceManagerEngine.js +64 -0
  29. package/lib/core-classes/DeviceService.d.ts +41 -0
  30. package/lib/core-classes/DeviceService.js +264 -0
  31. package/lib/core-classes/MigrationService.d.ts +13 -0
  32. package/lib/core-classes/MigrationService.js +49 -0
  33. package/lib/core-classes/PayloadService.d.ts +43 -0
  34. package/lib/core-classes/PayloadService.js +191 -0
  35. package/lib/core-classes/index.d.ts +8 -0
  36. package/lib/core-classes/index.js +21 -0
  37. package/lib/models/BaseAsset.d.ts +56 -0
  38. package/lib/models/BaseAsset.js +58 -0
  39. package/lib/models/Catalog.d.ts +55 -0
  40. package/lib/models/Catalog.js +38 -0
  41. package/lib/models/Config.d.ts +33 -0
  42. package/lib/models/Config.js +26 -0
  43. package/lib/models/Device.d.ts +102 -0
  44. package/lib/models/Device.js +91 -0
  45. package/lib/models/index.d.ts +3 -0
  46. package/lib/models/index.js +16 -0
  47. package/lib/types/AssetsHistoryContent.d.ts +9 -0
  48. package/lib/types/AssetsHistoryContent.js +3 -0
  49. package/lib/types/BaseAssetContent.d.ts +8 -0
  50. package/lib/types/BaseAssetContent.js +3 -0
  51. package/lib/types/DeviceContent.d.ts +62 -0
  52. package/lib/types/DeviceContent.js +3 -0
  53. package/lib/types/Measure.d.ts +54 -0
  54. package/lib/types/Measure.js +3 -0
  55. package/lib/types/index.d.ts +3 -0
  56. package/lib/types/index.js +16 -0
  57. package/lib/utils/events.d.ts +8 -0
  58. package/lib/utils/events.js +17 -0
  59. package/lib/utils/index.d.ts +1 -0
  60. package/lib/utils/index.js +14 -0
  61. package/package.json +1 -1
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PayloadService = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const kuzzle_1 = require("kuzzle");
9
+ const uuid_1 = require("uuid");
10
+ const models_1 = require("../models");
11
+ const utils_1 = require("../utils");
12
+ class PayloadService {
13
+ constructor(plugin, batchWriter) {
14
+ this.config = plugin.config;
15
+ this.context = plugin.context;
16
+ this.batchController = batchWriter.document;
17
+ }
18
+ get sdk() {
19
+ return this.context.accessors.sdk;
20
+ }
21
+ async process(request, decoder, { refresh = undefined } = {}) {
22
+ const payload = request.input.body;
23
+ if (!payload
24
+ || (typeof payload === 'object' && Object.keys(payload).length === 0)) {
25
+ throw new kuzzle_1.BadRequestError('The body must contain the payload.');
26
+ }
27
+ const uuid = request.input.args.uuid || (0, uuid_1.v4)();
28
+ let valid = true;
29
+ try {
30
+ valid = await decoder.validate(payload, request);
31
+ if (!valid) {
32
+ return { valid };
33
+ }
34
+ await decoder.beforeProcessing(payload, request);
35
+ }
36
+ catch (error) {
37
+ valid = false;
38
+ throw error;
39
+ }
40
+ finally {
41
+ await this.batchController.create(this.config.adminIndex, 'payloads', {
42
+ deviceModel: decoder.deviceModel,
43
+ uuid,
44
+ valid,
45
+ payload,
46
+ }, uuid);
47
+ }
48
+ const deviceContent = await decoder.decode(payload, request);
49
+ // Inject payload uuid
50
+ for (const measure of Object.values(deviceContent.measures)) {
51
+ if (!measure.payloadUuid) {
52
+ measure.payloadUuid = uuid;
53
+ }
54
+ }
55
+ if (!deviceContent.model) {
56
+ deviceContent.model = decoder.deviceModel;
57
+ }
58
+ const device = new models_1.Device(deviceContent);
59
+ const exists = await this.batchController.exists(this.config.adminIndex, 'devices', device._id);
60
+ if (exists) {
61
+ return await this.update(device, decoder, request, { refresh });
62
+ }
63
+ return await this.deviceProvisionning(device, decoder, request, { refresh });
64
+ }
65
+ async register(device, decoder, request, { refresh }) {
66
+ const enrichedDevice = await decoder.beforeRegister(device, request);
67
+ await this.batchController.create(this.config.adminIndex, 'devices', enrichedDevice._source, enrichedDevice._id, { refresh });
68
+ return await decoder.afterRegister(enrichedDevice, request);
69
+ }
70
+ /**
71
+ * Device provisioning strategy.
72
+ *
73
+ * If autoProvisionning is on, device is automatically registered, otherwise
74
+ * we request the admin provisioning catalog to ensure this device is allowed
75
+ * to register.
76
+ *
77
+ * After registration, we look at the admin provisioning catalog entry to:
78
+ * - attach the device to a tenant
79
+ * - link the device to an asset of this tenant
80
+ *
81
+ * Then we look into the tenant provisioning catalog entry to:
82
+ * - link the device to an asset of this tenant
83
+ */
84
+ async deviceProvisionning(device, decoder, request, { refresh }) {
85
+ const pluginConfigDocument = await this.batchController.get(this.config.adminIndex, this.config.configCollection, 'plugin--device-manager');
86
+ const autoProvisionning = pluginConfigDocument._source['device-manager'].autoProvisionning;
87
+ const catalogEntry = await this.getCatalogEntry(this.config.adminIndex, device._id);
88
+ if (!autoProvisionning && !catalogEntry) {
89
+ throw new kuzzle_1.BadRequestError(`Device ${device._id} is not provisionned.`);
90
+ }
91
+ if (!autoProvisionning && catalogEntry.content.authorized === false) {
92
+ throw new kuzzle_1.BadRequestError(`Device ${device._id} is not allowed for registration.`);
93
+ }
94
+ const ret = await this.register(device, decoder, request, { refresh });
95
+ // If there is not auto attachment to a tenant then we cannot link asset as well
96
+ if (!catalogEntry || !catalogEntry.content.tenantId) {
97
+ return ret;
98
+ }
99
+ await this.sdk.query({
100
+ controller: 'device-manager/device',
101
+ action: 'attachTenant',
102
+ _id: device._id,
103
+ index: catalogEntry.content.tenantId,
104
+ });
105
+ if (catalogEntry.content.assetId) {
106
+ await this.sdk.query({
107
+ controller: 'device-manager/device',
108
+ action: 'linkAsset',
109
+ _id: device._id,
110
+ assetId: catalogEntry.content.assetId,
111
+ });
112
+ }
113
+ const tenantCatalogEntry = await this.getCatalogEntry(catalogEntry.content.tenantId, device._id);
114
+ if (tenantCatalogEntry
115
+ && tenantCatalogEntry.content.authorized !== false
116
+ && tenantCatalogEntry.content.assetId) {
117
+ await this.sdk.query({
118
+ controller: 'device-manager/device',
119
+ action: 'linkAsset',
120
+ _id: device._id,
121
+ assetId: tenantCatalogEntry.content.assetId,
122
+ });
123
+ }
124
+ return ret;
125
+ }
126
+ /**
127
+ * Get the device entry from the provisioning catalog in corresponding index
128
+ */
129
+ async getCatalogEntry(index, deviceId) {
130
+ try {
131
+ const document = await this.batchController.get(index, this.config.configCollection, `catalog--${deviceId}`);
132
+ return new models_1.Catalog(document);
133
+ }
134
+ catch (error) {
135
+ if (error.id !== 'services.storage.not_found') {
136
+ throw error;
137
+ }
138
+ return null;
139
+ }
140
+ }
141
+ async update(device, decoder, request, { refresh }) {
142
+ const refreshableCollections = [];
143
+ const previousDevice = await this.batchController.get(this.config.adminIndex, 'devices', device._id);
144
+ const enrichedDevice = await decoder.beforeUpdate(device, request);
145
+ const deviceDocument = await this.batchController.update(this.config.adminIndex, 'devices', enrichedDevice._id, enrichedDevice._source, { source: true, retryOnConflict: 10 });
146
+ const updatedDevice = new models_1.Device(deviceDocument._source, deviceDocument._id);
147
+ refreshableCollections.push([this.config.adminIndex, 'devices']);
148
+ const tenantId = previousDevice._source.tenantId;
149
+ let updatedAsset = null;
150
+ // Propagate device into tenant index
151
+ if (tenantId) {
152
+ await this.batchController.update(tenantId, 'devices', enrichedDevice._id, enrichedDevice._source, { retryOnConflict: 10 });
153
+ refreshableCollections.push([tenantId, 'devices']);
154
+ // Propagate measures into linked asset
155
+ const assetId = previousDevice._source.assetId;
156
+ if (assetId) {
157
+ updatedAsset = await this.propagateToAsset(tenantId, decoder, updatedDevice, assetId);
158
+ await this.historizeAsset(tenantId, updatedAsset);
159
+ refreshableCollections.push([tenantId, 'assets']);
160
+ }
161
+ }
162
+ if (refresh === 'wait_for') {
163
+ await Promise.all(refreshableCollections.map(([index, collection]) => (this.sdk.collection.refresh(index, collection))));
164
+ }
165
+ return decoder.afterUpdate(updatedDevice, updatedAsset, request);
166
+ }
167
+ /**
168
+ * Propagate the measures inside the asset document.
169
+ */
170
+ async propagateToAsset(tenantId, decoder, updatedDevice, assetId) {
171
+ const measures = await decoder.copyToAsset(updatedDevice);
172
+ const measureTypes = Object.keys(measures);
173
+ const asset = await this.batchController.get(tenantId, 'assets', assetId);
174
+ asset._source.measures = lodash_1.default.merge(asset._source.measures, measures);
175
+ const { result } = await global.app.trigger(`engine:${tenantId}:asset:measures:new`, (0, utils_1.eventPayload)({ asset, measureTypes }));
176
+ const assetDocument = await this.batchController.update(tenantId, 'assets', assetId, result.asset._source, { source: true, retryOnConflict: 10 });
177
+ return new models_1.BaseAsset(assetDocument._source, assetDocument._id);
178
+ }
179
+ /**
180
+ * Creates an history entry for an asset
181
+ */
182
+ async historizeAsset(tenantId, asset) {
183
+ await this.batchController.create(tenantId, 'asset-history', {
184
+ assetId: asset._id,
185
+ measureTypes: Object.keys(asset._source.measures),
186
+ asset: lodash_1.default.omit(asset._source, ['_kuzzle_info']),
187
+ });
188
+ }
189
+ }
190
+ exports.PayloadService = PayloadService;
191
+ //# sourceMappingURL=PayloadService.js.map
@@ -0,0 +1,8 @@
1
+ export * from './PayloadService';
2
+ export * from './DeviceManagerEngine';
3
+ export * from './DeviceService';
4
+ export * from './MigrationService';
5
+ export * from './BatchProcessing';
6
+ export * from './Decoder';
7
+ export * from './CustomMappings/AssetMappingsManager';
8
+ export * from './CustomMappings/DeviceMappingsManager';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./PayloadService"), exports);
14
+ __exportStar(require("./DeviceManagerEngine"), exports);
15
+ __exportStar(require("./DeviceService"), exports);
16
+ __exportStar(require("./MigrationService"), exports);
17
+ __exportStar(require("./BatchProcessing"), exports);
18
+ __exportStar(require("./Decoder"), exports);
19
+ __exportStar(require("./CustomMappings/AssetMappingsManager"), exports);
20
+ __exportStar(require("./CustomMappings/DeviceMappingsManager"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,56 @@
1
+ import { JSONObject } from 'kuzzle';
2
+ import { BaseAssetContent } from '../types';
3
+ export declare class BaseAsset {
4
+ _id: string;
5
+ _source: BaseAssetContent;
6
+ constructor(content: BaseAssetContent, _id?: string);
7
+ serialize(): JSONObject;
8
+ }
9
+ export declare const assetsMappings: {
10
+ dynamic: string;
11
+ properties: {
12
+ type: {
13
+ type: string;
14
+ fields: {
15
+ text: {
16
+ type: string;
17
+ };
18
+ };
19
+ };
20
+ model: {
21
+ type: string;
22
+ fields: {
23
+ text: {
24
+ type: string;
25
+ };
26
+ };
27
+ };
28
+ reference: {
29
+ type: string;
30
+ fields: {
31
+ text: {
32
+ type: string;
33
+ };
34
+ };
35
+ };
36
+ measures: {
37
+ properties: {};
38
+ };
39
+ metadata: {
40
+ dynamic: string;
41
+ properties: {};
42
+ };
43
+ };
44
+ };
45
+ export declare const assetsHistoryMappings: {
46
+ dynamic: string;
47
+ properties: {
48
+ assetId: {
49
+ type: string;
50
+ };
51
+ measureTypes: {
52
+ type: string;
53
+ };
54
+ asset: any;
55
+ };
56
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assetsHistoryMappings = exports.assetsMappings = exports.BaseAsset = void 0;
4
+ class BaseAsset {
5
+ constructor(content, _id) {
6
+ this._id = _id || `${content.type}-${content.model}-${content.reference}`;
7
+ this._source = content;
8
+ }
9
+ serialize() {
10
+ return {
11
+ _id: this._id,
12
+ _source: this._source
13
+ };
14
+ }
15
+ }
16
+ exports.BaseAsset = BaseAsset;
17
+ exports.assetsMappings = {
18
+ dynamic: 'strict',
19
+ properties: {
20
+ type: {
21
+ type: 'keyword',
22
+ fields: {
23
+ text: { type: 'text' }
24
+ }
25
+ },
26
+ model: {
27
+ type: 'keyword',
28
+ fields: {
29
+ text: { type: 'text' }
30
+ }
31
+ },
32
+ reference: {
33
+ type: 'keyword',
34
+ fields: {
35
+ text: { type: 'text' }
36
+ }
37
+ },
38
+ measures: {
39
+ properties: {
40
+ // autogenerated from devices mappings
41
+ }
42
+ },
43
+ metadata: {
44
+ dynamic: 'false',
45
+ properties: {}
46
+ }
47
+ }
48
+ };
49
+ exports.assetsHistoryMappings = {
50
+ dynamic: 'strict',
51
+ properties: {
52
+ assetId: { type: 'keyword' },
53
+ measureTypes: { type: 'keyword' },
54
+ // Will be replaced by the custom asset mappings
55
+ asset: null,
56
+ }
57
+ };
58
+ //# sourceMappingURL=BaseAsset.js.map
@@ -0,0 +1,55 @@
1
+ import { JSONObject } from 'kuzzle';
2
+ import { ConfigDocument } from './Config';
3
+ export declare const catalogMappings: {
4
+ dynamic: string;
5
+ properties: {
6
+ deviceId: {
7
+ type: string;
8
+ };
9
+ authorized: {
10
+ type: string;
11
+ };
12
+ tenantId: {
13
+ type: string;
14
+ };
15
+ assetId: {
16
+ type: string;
17
+ };
18
+ };
19
+ };
20
+ /**
21
+ * Provisioning catalog entry
22
+ */
23
+ export declare type CatalogContent = {
24
+ /**
25
+ * ID of the device
26
+ * (e.g. "Abeeway-123456")
27
+ */
28
+ deviceId: string;
29
+ /**
30
+ * If set to false, the device cannot register
31
+ */
32
+ authorized: boolean;
33
+ /**
34
+ * If set, the device will be attached to this tenant
35
+ */
36
+ tenantId?: string;
37
+ /**
38
+ * If set, the device will be linked to this asset
39
+ */
40
+ assetId?: string;
41
+ };
42
+ /**
43
+ * Catalog configuration document
44
+ */
45
+ export declare class Catalog extends ConfigDocument<CatalogContent> {
46
+ /**
47
+ * Can be build either:
48
+ * - with a raw config document (_id and _source properties)
49
+ * - with a rule definition
50
+ */
51
+ constructor(document: CatalogContent | {
52
+ _id: string;
53
+ _source: JSONObject;
54
+ });
55
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Catalog = exports.catalogMappings = void 0;
4
+ const Config_1 = require("./Config");
5
+ exports.catalogMappings = {
6
+ dynamic: 'strict',
7
+ properties: {
8
+ deviceId: { type: 'keyword' },
9
+ authorized: { type: 'boolean' },
10
+ tenantId: { type: 'keyword' },
11
+ assetId: { type: 'keyword' },
12
+ },
13
+ };
14
+ /**
15
+ * Catalog configuration document
16
+ */
17
+ class Catalog extends Config_1.ConfigDocument {
18
+ /**
19
+ * Can be build either:
20
+ * - with a raw config document (_id and _source properties)
21
+ * - with a rule definition
22
+ */
23
+ constructor(document) {
24
+ if (document['_id'] || document['_source']) {
25
+ super(document);
26
+ }
27
+ else {
28
+ super({
29
+ _source: {
30
+ type: 'catalog',
31
+ catalog: document
32
+ }
33
+ });
34
+ }
35
+ }
36
+ }
37
+ exports.Catalog = Catalog;
38
+ //# sourceMappingURL=Catalog.js.map
@@ -0,0 +1,33 @@
1
+ import { JSONObject } from 'kuzzle';
2
+ import { CatalogContent } from './Catalog';
3
+ /**
4
+ * Represents either a Rule or Workflow raw configuration document
5
+ */
6
+ export declare type ConfigContent = ConfigCatalogContent | JSONObject;
7
+ /**
8
+ * Content of a configuration document for a catalog entry
9
+ */
10
+ export declare type ConfigCatalogContent = {
11
+ type: 'catalog';
12
+ catalog: CatalogContent;
13
+ _kuzzle_info?: JSONObject;
14
+ };
15
+ /**
16
+ * Class to manipulate configuration documents
17
+ */
18
+ export declare class ConfigDocument<TConfigContent> {
19
+ _id: string;
20
+ _source: ConfigContent;
21
+ /**
22
+ * Rule or workflow definition
23
+ */
24
+ get content(): TConfigContent;
25
+ /**
26
+ * Author or updater of the document (from Kuzzle Metadata)
27
+ */
28
+ get author(): string;
29
+ constructor(document: {
30
+ _id?: string;
31
+ _source: JSONObject;
32
+ });
33
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigDocument = void 0;
4
+ /**
5
+ * Class to manipulate configuration documents
6
+ */
7
+ class ConfigDocument {
8
+ constructor(document) {
9
+ this._id = document._id;
10
+ this._source = document._source;
11
+ }
12
+ /**
13
+ * Rule or workflow definition
14
+ */
15
+ get content() {
16
+ return this._source[this._source.type];
17
+ }
18
+ /**
19
+ * Author or updater of the document (from Kuzzle Metadata)
20
+ */
21
+ get author() {
22
+ return this._source._kuzzle_info.updater || this._source._kuzzle_info.author;
23
+ }
24
+ }
25
+ exports.ConfigDocument = ConfigDocument;
26
+ //# sourceMappingURL=Config.js.map
@@ -0,0 +1,102 @@
1
+ import { JSONObject } from 'kuzzle';
2
+ import { DeviceContent } from '../types';
3
+ export declare class Device {
4
+ _id: string;
5
+ _source: DeviceContent;
6
+ constructor(content: DeviceContent, _id?: string);
7
+ serialize(): JSONObject;
8
+ }
9
+ export declare const devicesMappings: {
10
+ dynamic: string;
11
+ properties: {
12
+ reference: {
13
+ type: string;
14
+ fields: {
15
+ text: {
16
+ type: string;
17
+ };
18
+ };
19
+ };
20
+ model: {
21
+ type: string;
22
+ fields: {
23
+ text: {
24
+ type: string;
25
+ };
26
+ };
27
+ };
28
+ measures: {
29
+ properties: {
30
+ temperature: {
31
+ properties: {
32
+ updatedAt: {
33
+ type: string;
34
+ };
35
+ payloadUuid: {
36
+ type: string;
37
+ };
38
+ degree: {
39
+ type: string;
40
+ };
41
+ };
42
+ };
43
+ position: {
44
+ properties: {
45
+ updatedAt: {
46
+ type: string;
47
+ };
48
+ payloadUuid: {
49
+ type: string;
50
+ };
51
+ point: {
52
+ type: string;
53
+ };
54
+ altitude: {
55
+ type: string;
56
+ };
57
+ accuracy: {
58
+ type: string;
59
+ };
60
+ };
61
+ };
62
+ movement: {
63
+ properties: {
64
+ updatedAt: {
65
+ type: string;
66
+ };
67
+ payloadUuid: {
68
+ type: string;
69
+ };
70
+ moving: {
71
+ type: string;
72
+ };
73
+ };
74
+ };
75
+ };
76
+ };
77
+ qos: {
78
+ dynamic: string;
79
+ properties: {};
80
+ };
81
+ metadata: {
82
+ dynamic: string;
83
+ properties: {};
84
+ };
85
+ assetId: {
86
+ type: string;
87
+ fields: {
88
+ text: {
89
+ type: string;
90
+ };
91
+ };
92
+ };
93
+ tenantId: {
94
+ type: string;
95
+ fields: {
96
+ text: {
97
+ type: string;
98
+ };
99
+ };
100
+ };
101
+ };
102
+ };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.devicesMappings = exports.Device = void 0;
4
+ class Device {
5
+ constructor(content, _id) {
6
+ this._id = _id || `${content.model}-${content.reference}`;
7
+ this._source = {
8
+ qos: {},
9
+ metadata: {},
10
+ ...content
11
+ };
12
+ }
13
+ serialize() {
14
+ return {
15
+ _id: this._id,
16
+ _source: this._source
17
+ };
18
+ }
19
+ }
20
+ exports.Device = Device;
21
+ exports.devicesMappings = {
22
+ dynamic: 'strict',
23
+ properties: {
24
+ reference: {
25
+ type: 'keyword',
26
+ fields: {
27
+ text: { type: 'text' }
28
+ }
29
+ },
30
+ model: {
31
+ type: 'keyword',
32
+ fields: {
33
+ text: { type: 'text' }
34
+ }
35
+ },
36
+ measures: {
37
+ properties: {
38
+ temperature: {
39
+ properties: {
40
+ // common
41
+ updatedAt: { type: 'date' },
42
+ payloadUuid: { type: 'keyword' },
43
+ // temperature
44
+ degree: { type: 'float' }
45
+ }
46
+ },
47
+ position: {
48
+ properties: {
49
+ // common
50
+ updatedAt: { type: 'date' },
51
+ payloadUuid: { type: 'keyword' },
52
+ // position
53
+ point: { type: 'geo_point' },
54
+ altitude: { type: 'float' },
55
+ accuracy: { type: 'integer' },
56
+ }
57
+ },
58
+ movement: {
59
+ properties: {
60
+ // common
61
+ updatedAt: { type: 'date' },
62
+ payloadUuid: { type: 'keyword' },
63
+ // movement state
64
+ moving: { type: 'boolean' },
65
+ }
66
+ }
67
+ }
68
+ },
69
+ qos: {
70
+ dynamic: 'false',
71
+ properties: {},
72
+ },
73
+ metadata: {
74
+ dynamic: 'false',
75
+ properties: {},
76
+ },
77
+ assetId: {
78
+ type: 'keyword',
79
+ fields: {
80
+ text: { type: 'text' }
81
+ }
82
+ },
83
+ tenantId: {
84
+ type: 'keyword',
85
+ fields: {
86
+ text: { type: 'text' }
87
+ }
88
+ }
89
+ }
90
+ };
91
+ //# sourceMappingURL=Device.js.map
@@ -0,0 +1,3 @@
1
+ export * from './Device';
2
+ export * from './BaseAsset';
3
+ export * from './Catalog';