@wiotp/sdk 0.4.2 → 0.6.2

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 (48) hide show
  1. package/LICENSE +203 -203
  2. package/README.md +68 -68
  3. package/dist/BaseClient.js +259 -0
  4. package/dist/BaseConfig.js +194 -0
  5. package/dist/api/ApiClient.js +508 -0
  6. package/dist/api/ApiErrors.js +118 -0
  7. package/dist/api/DscClient.js +332 -0
  8. package/dist/api/LecClient.js +48 -0
  9. package/dist/api/MgmtClient.js +77 -0
  10. package/dist/api/RegistryClient.js +234 -0
  11. package/dist/api/RulesClient.js +105 -0
  12. package/dist/api/StateClient.js +738 -0
  13. package/dist/application/ApplicationClient.js +436 -0
  14. package/dist/application/ApplicationConfig.js +233 -0
  15. package/dist/application/index.js +23 -0
  16. package/dist/bundled/wiotp-bundle.js +35592 -0
  17. package/dist/bundled/wiotp-bundle.min.js +47 -0
  18. package/dist/device/DeviceClient.js +125 -0
  19. package/dist/device/DeviceConfig.js +216 -0
  20. package/dist/device/index.js +23 -0
  21. package/dist/gateway/GatewayClient.js +159 -0
  22. package/dist/gateway/GatewayConfig.js +52 -0
  23. package/dist/gateway/index.js +23 -0
  24. package/dist/index.js +55 -0
  25. package/dist/util.js +50 -0
  26. package/package.json +92 -84
  27. package/src/BaseClient.js +215 -215
  28. package/src/BaseConfig.js +157 -157
  29. package/src/api/ApiClient.js +454 -454
  30. package/src/api/ApiErrors.js +33 -33
  31. package/src/api/DscClient.js +164 -145
  32. package/src/api/LecClient.js +32 -32
  33. package/src/api/MgmtClient.js +57 -57
  34. package/src/api/RegistryClient.js +194 -194
  35. package/src/api/RulesClient.js +84 -84
  36. package/src/api/StateClient.js +650 -650
  37. package/src/application/ApplicationClient.js +348 -348
  38. package/src/application/ApplicationConfig.js +191 -191
  39. package/src/application/index.js +12 -12
  40. package/src/device/DeviceClient.js +78 -78
  41. package/src/device/DeviceConfig.js +175 -175
  42. package/src/device/index.js +14 -14
  43. package/src/gateway/GatewayClient.js +114 -114
  44. package/src/gateway/GatewayConfig.js +21 -21
  45. package/src/gateway/index.js +13 -13
  46. package/{index.js → src/index.js} +19 -19
  47. package/src/util.js +38 -38
  48. package/src/util/IoTFoundation.pem +0 -82
@@ -0,0 +1,738 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _loglevel = _interopRequireDefault(require("loglevel"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
17
+
18
+ var StateClient =
19
+ /*#__PURE__*/
20
+ function () {
21
+ function StateClient(apiClient) {
22
+ _classCallCheck(this, StateClient);
23
+
24
+ this.log = _loglevel["default"];
25
+ this.apiClient = apiClient;
26
+ this.draftMode = true; // Create an alias to the apiClient's methods that we use
27
+
28
+ this.callApi = this.apiClient.callApi.bind(this.apiClient);
29
+ this.parseSortSpec = this.apiClient.parseSortSpec.bind(this.apiClient);
30
+ this.callFormDataApi = this.apiClient.callFormDataApi.bind(this.apiClient);
31
+ this.invalidOperation = this.apiClient.invalidOperation.bind(this.apiClient);
32
+ }
33
+
34
+ _createClass(StateClient, [{
35
+ key: "workWithActive",
36
+ value: function workWithActive() {
37
+ this.draftMode = false;
38
+ }
39
+ }, {
40
+ key: "workWithDraft",
41
+ value: function workWithDraft() {
42
+ this.draftMode = true;
43
+ } // IM Device state API
44
+
45
+ }, {
46
+ key: "createSchema",
47
+ value: function createSchema(schemaContents, name, description) {
48
+ var body = {
49
+ 'schemaFile': schemaContents,
50
+ 'schemaType': 'json-schema',
51
+ 'name': name
52
+ };
53
+
54
+ if (description) {
55
+ body.description = description;
56
+ }
57
+
58
+ var base = this.draftMode ? ["draft", "schemas"] : ["schemas"];
59
+ return this.callFormDataApi('POST', 201, true, base, body, null);
60
+ }
61
+ }, {
62
+ key: "getSchema",
63
+ value: function getSchema(schemaId) {
64
+ var base = this.draftMode ? ["draft", "schemas", schemaId] : ["schemas", schemaId];
65
+ return this.callApi('GET', 200, true, base);
66
+ }
67
+ }, {
68
+ key: "getActiveSchema",
69
+ value: function getActiveSchema(schemaId) {
70
+ return this.callApi('GET', 200, true, ["schemas", schemaId]);
71
+ }
72
+ }, {
73
+ key: "getSchemas",
74
+ value: function getSchemas() {
75
+ var base = this.draftMode ? ["draft", "schemas"] : ["schemas"];
76
+ return this.callApi('GET', 200, true, base);
77
+ }
78
+ }, {
79
+ key: "getActiveSchemas",
80
+ value: function getActiveSchemas() {
81
+ return this.callApi('GET', 200, true, ["schemas"]);
82
+ }
83
+ }, {
84
+ key: "updateSchema",
85
+ value: function updateSchema(schemaId, name, description) {
86
+ var body = {
87
+ "id": schemaId,
88
+ "name": name,
89
+ "description": description
90
+ };
91
+ var base = this.draftMode ? ["draft", "schemas", schemaId] : ["schemas", schemaId];
92
+ return this.callApi('PUT', 200, true, base, body);
93
+ }
94
+ }, {
95
+ key: "updateSchemaContent",
96
+ value: function updateSchemaContent(schemaId, schemaContents, filename) {
97
+ var body = {
98
+ 'schemaFile': schemaContents,
99
+ 'name': filename
100
+ };
101
+ var base = this.draftMode ? ["draft", "schemas", schemaId, "content"] : ["schemas", schemaId, "content"];
102
+ return this.callFormDataApi('PUT', 204, false, base, body, null);
103
+ }
104
+ }, {
105
+ key: "getSchemaContent",
106
+ value: function getSchemaContent(schemaId) {
107
+ var base = this.draftMode ? ["draft", "schemas", schemaId, "content"] : ["schemas", schemaId, "content"];
108
+ return this.callApi('GET', 200, true, base);
109
+ }
110
+ }, {
111
+ key: "getActiveSchemaContent",
112
+ value: function getActiveSchemaContent(schemaId) {
113
+ return this.callApi('GET', 200, true, ["schemas", schemaId, "content"]);
114
+ }
115
+ }, {
116
+ key: "deleteSchema",
117
+ value: function deleteSchema(schemaId) {
118
+ var base = this.draftMode ? ["draft", "schemas", schemaId] : ["schemas", schemaId];
119
+ return this.callApi('DELETE', 204, false, base, null);
120
+ }
121
+ }, {
122
+ key: "createEventType",
123
+ value: function createEventType(name, description, schemaId) {
124
+ var body = {
125
+ 'name': name,
126
+ 'description': description,
127
+ 'schemaId': schemaId
128
+ };
129
+ var base = this.draftMode ? ["draft", "event", "types"] : ["event", "types"];
130
+ return this.callApi('POST', 201, true, base, JSON.stringify(body));
131
+ }
132
+ }, {
133
+ key: "getEventType",
134
+ value: function getEventType(eventTypeId) {
135
+ var base = this.draftMode ? ["draft", "event", "types", eventTypeId] : ["event", "types", eventTypeId];
136
+ return this.callApi('GET', 200, true, base);
137
+ }
138
+ }, {
139
+ key: "getActiveEventType",
140
+ value: function getActiveEventType(eventTypeId) {
141
+ return this.callApi('GET', 200, true, ["event", "types", eventTypeId]);
142
+ }
143
+ }, {
144
+ key: "deleteEventType",
145
+ value: function deleteEventType(eventTypeId) {
146
+ var base = this.draftMode ? ["draft", "event", "types", eventTypeId] : ["event", "types", eventTypeId];
147
+ return this.callApi('DELETE', 204, false, base);
148
+ }
149
+ }, {
150
+ key: "updateEventType",
151
+ value: function updateEventType(eventTypeId, name, description, schemaId) {
152
+ var body = {
153
+ "id": eventTypeId,
154
+ "name": name,
155
+ "description": description,
156
+ "schemaId": schemaId
157
+ };
158
+ var base = this.draftMode ? ["draft", "event", "types", eventTypeId] : ["event", "types", eventTypeId];
159
+ return this.callApi('PUT', 200, true, base, body);
160
+ }
161
+ }, {
162
+ key: "getEventTypes",
163
+ value: function getEventTypes() {
164
+ var base = this.draftMode ? ["draft", "event", "types"] : ["event", "types"];
165
+ return this.callApi('GET', 200, true, base);
166
+ }
167
+ }, {
168
+ key: "getActiveEventTypes",
169
+ value: function getActiveEventTypes() {
170
+ return this.callApi('GET', 200, true, ["event", "types"]);
171
+ }
172
+ }, {
173
+ key: "createPhysicalInterface",
174
+ value: function createPhysicalInterface(name, description) {
175
+ var body = {
176
+ 'name': name,
177
+ 'description': description
178
+ };
179
+ var base = this.draftMode ? ["draft", "physicalinterfaces"] : ["physicalinterfaces"];
180
+ return this.callApi('POST', 201, true, base, body);
181
+ }
182
+ }, {
183
+ key: "getPhysicalInterface",
184
+ value: function getPhysicalInterface(physicalInterfaceId) {
185
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId] : ["physicalinterfaces", physicalInterfaceId];
186
+ return this.callApi('GET', 200, true, base);
187
+ }
188
+ }, {
189
+ key: "getActivePhysicalInterface",
190
+ value: function getActivePhysicalInterface(physicalInterfaceId) {
191
+ return this.callApi('GET', 200, true, ["physicalinterfaces", physicalInterfaceId]);
192
+ }
193
+ }, {
194
+ key: "deletePhysicalInterface",
195
+ value: function deletePhysicalInterface(physicalInterfaceId) {
196
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId] : ["physicalinterfaces", physicalInterfaceId];
197
+ return this.callApi('DELETE', 204, false, base);
198
+ }
199
+ }, {
200
+ key: "updatePhysicalInterface",
201
+ value: function updatePhysicalInterface(physicalInterfaceId, name, description) {
202
+ var body = {
203
+ 'id': physicalInterfaceId,
204
+ 'name': name,
205
+ 'description': description
206
+ };
207
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId] : ["physicalinterfaces", physicalInterfaceId];
208
+ return this.callApi('PUT', 200, true, base, body);
209
+ }
210
+ }, {
211
+ key: "getPhysicalInterfaces",
212
+ value: function getPhysicalInterfaces() {
213
+ var base = this.draftMode ? ["draft", "physicalinterfaces"] : ["physicalinterfaces"];
214
+ return this.callApi('GET', 200, true, base);
215
+ }
216
+ }, {
217
+ key: "getActivePhysicalInterfaces",
218
+ value: function getActivePhysicalInterfaces() {
219
+ return this.callApi('GET', 200, true, ["physicalinterfaces"]);
220
+ }
221
+ }, {
222
+ key: "createPhysicalInterfaceEventMapping",
223
+ value: function createPhysicalInterfaceEventMapping(physicalInterfaceId, eventId, eventTypeId) {
224
+ var body = {
225
+ "eventId": eventId,
226
+ "eventTypeId": eventTypeId
227
+ };
228
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId, "events"] : ["physicalinterfaces", physicalInterfaceId, "events"];
229
+ return this.callApi('POST', 201, true, base, body);
230
+ }
231
+ }, {
232
+ key: "getPhysicalInterfaceEventMappings",
233
+ value: function getPhysicalInterfaceEventMappings(physicalInterfaceId) {
234
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId, "events"] : ["physicalinterfaces", physicalInterfaceId, "events"];
235
+ return this.callApi('GET', 200, true, base);
236
+ }
237
+ }, {
238
+ key: "getActivePhysicalInterfaceEventMappings",
239
+ value: function getActivePhysicalInterfaceEventMappings(physicalInterfaceId) {
240
+ return this.callApi('GET', 200, true, ["physicalinterfaces", physicalInterfaceId, "events"]);
241
+ }
242
+ }, {
243
+ key: "deletePhysicalInterfaceEventMapping",
244
+ value: function deletePhysicalInterfaceEventMapping(physicalInterfaceId, eventId) {
245
+ var base = this.draftMode ? ["draft", "physicalinterfaces", physicalInterfaceId, "events", eventId] : ["physicalinterfaces", physicalInterfaceId, "events", eventId];
246
+ return this.callApi('DELETE', 204, false, base);
247
+ }
248
+ }, {
249
+ key: "createLogicalInterface",
250
+ value: function createLogicalInterface(name, description, schemaId, alias) {
251
+ var body = {
252
+ 'name': name,
253
+ 'description': description,
254
+ 'schemaId': schemaId
255
+ };
256
+
257
+ if (alias !== undefined) {
258
+ body.alias = alias;
259
+ }
260
+
261
+ var base = this.draftMode ? ["draft", "logicalinterfaces"] : ["applicationinterfaces"];
262
+ return this.callApi('POST', 201, true, base, body);
263
+ }
264
+ }, {
265
+ key: "getLogicalInterface",
266
+ value: function getLogicalInterface(logicalInterfaceId) {
267
+ var base = this.draftMode ? ["draft", "logicalinterfaces", logicalInterfaceId] : ["applicationinterfaces", logicalInterfaceId];
268
+ return this.callApi('GET', 200, true, base);
269
+ }
270
+ }, {
271
+ key: "getActiveLogicalInterface",
272
+ value: function getActiveLogicalInterface(logicalInterfaceId) {
273
+ return this.callApi('GET', 200, true, ["logicalinterfaces", logicalInterfaceId]);
274
+ }
275
+ }, {
276
+ key: "deleteLogicalInterface",
277
+ value: function deleteLogicalInterface(logicalInterfaceId) {
278
+ var base = this.draftMode ? ["draft", "logicalinterfaces", logicalInterfaceId] : ["applicationinterfaces", logicalInterfaceId];
279
+ return this.callApi('DELETE', 204, false, base);
280
+ }
281
+ }, {
282
+ key: "updateLogicalInterface",
283
+ value: function updateLogicalInterface(logicalInterfaceId, name, description, schemaId, alias) {
284
+ var body = {
285
+ "id": logicalInterfaceId,
286
+ "name": name,
287
+ "description": description,
288
+ "schemaId": schemaId
289
+ };
290
+
291
+ if (alias !== undefined) {
292
+ body.alias = alias;
293
+ }
294
+
295
+ var base = this.draftMode ? ["draft", "logicalinterfaces", logicalInterfaceId] : ["applicationinterfaces", logicalInterfaceId];
296
+ return this.callApi('PUT', 200, true, base, body);
297
+ }
298
+ }, {
299
+ key: "getLogicalInterfaces",
300
+ value: function getLogicalInterfaces(bookmark, limit, sort, name) {
301
+ var base = this.draftMode ? ["draft", "logicalinterfaces"] : ["logicalinterfaces"];
302
+
303
+ var _sort = this.parseSortSpec(sort);
304
+
305
+ return this.callApi('GET', 200, true, base, undefined, {
306
+ _bookmark: bookmark,
307
+ _limit: limit,
308
+ _sort: _sort,
309
+ name: name ? name : undefined
310
+ });
311
+ }
312
+ }, {
313
+ key: "getActiveLogicalInterfaces",
314
+ value: function getActiveLogicalInterfaces() {
315
+ return this.callApi('GET', 200, true, ["logicalinterfaces"]);
316
+ } // Application interface patch operation on draft version
317
+ // Acceptable operation id - validate-configuration, activate-configuration, list-differences
318
+
319
+ }, {
320
+ key: "patchOperationLogicalInterface",
321
+ value: function patchOperationLogicalInterface(logicalInterfaceId, operationId) {
322
+ var body = {
323
+ "operation": operationId
324
+ };
325
+
326
+ if (this.draftMode) {
327
+ switch (operationId) {
328
+ case 'validate-configuration':
329
+ return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
330
+ break;
331
+
332
+ case 'activate-configuration':
333
+ return this.callApi('PATCH', 202, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
334
+
335
+ case 'deactivate-configuration':
336
+ return this.callApi('PATCH', 202, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
337
+
338
+ case 'list-differences':
339
+ return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
340
+
341
+ default:
342
+ return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
343
+ }
344
+ } else {
345
+ return this.invalidOperation("PATCH operation not allowed on logical interface");
346
+ }
347
+ } // Application interface patch operation on active version
348
+ // Acceptable operation id - deactivate-configuration
349
+
350
+ }, {
351
+ key: "patchOperationActiveLogicalInterface",
352
+ value: function patchOperationActiveLogicalInterface(logicalInterfaceId, operationId) {
353
+ var body = {
354
+ "operation": operationId
355
+ };
356
+
357
+ if (this.draftMode) {
358
+ return this.callApi('PATCH', 202, true, ["logicalinterfaces", logicalInterfaceId], body);
359
+ } else {
360
+ return this.invalidOperation("PATCH operation 'deactivate-configuration' not allowed on logical interface");
361
+ }
362
+ } // Create device type with physical Interface Id
363
+
364
+ }, {
365
+ key: "createDeviceType",
366
+ value: function createDeviceType(typeId, description, deviceInfo, metadata, classId, physicalInterfaceId) {
367
+ this.log.debug("[ApiClient] registerDeviceType(" + typeId + ", " + description + ", " + deviceInfo + ", " + metadata + ", " + classId + ", " + physicalInterfaceId + ")");
368
+ classId = classId || "Device";
369
+ var body = {
370
+ id: typeId,
371
+ classId: classId,
372
+ deviceInfo: deviceInfo,
373
+ description: description,
374
+ metadata: metadata,
375
+ physicalInterfaceId: physicalInterfaceId
376
+ };
377
+ return this.callApi('POST', 201, true, ['device', 'types'], JSON.stringify(body));
378
+ }
379
+ }, {
380
+ key: "createDeviceTypePhysicalInterfaceAssociation",
381
+ value: function createDeviceTypePhysicalInterfaceAssociation(typeId, physicalInterfaceId) {
382
+ var body = {
383
+ id: physicalInterfaceId
384
+ };
385
+
386
+ if (this.draftMode) {
387
+ return this.callApi('POST', 201, true, ['draft', 'device', 'types', typeId, 'physicalinterface'], JSON.stringify(body));
388
+ } else {
389
+ return this.callApi('PUT', 200, true, ['device', 'types', typeId], JSON.stringify({
390
+ physicalInterfaceId: physicalInterfaceId
391
+ }));
392
+ }
393
+ }
394
+ }, {
395
+ key: "getDeviceTypePhysicalInterfaces",
396
+ value: function getDeviceTypePhysicalInterfaces(typeId) {
397
+ if (this.draftMode) {
398
+ return this.callApi('GET', 200, true, ['draft', 'device', 'types', typeId, 'physicalinterface']);
399
+ } else {
400
+ return this.invalidOperation("GET Device type's physical interface is not allowed");
401
+ }
402
+ }
403
+ }, {
404
+ key: "getActiveDeviceTypePhysicalInterfaces",
405
+ value: function getActiveDeviceTypePhysicalInterfaces(typeId) {
406
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'physicalinterface']);
407
+ }
408
+ }, {
409
+ key: "deleteDeviceTypePhysicalInterfaceAssociation",
410
+ value: function deleteDeviceTypePhysicalInterfaceAssociation(typeId) {
411
+ if (this.draftMode) {
412
+ return this.callApi('DELETE', 204, false, ['draft', 'device', 'types', typeId, 'physicalinterface']);
413
+ } else {
414
+ return this.invalidOperation("DELETE Device type's physical interface is not allowed");
415
+ }
416
+ }
417
+ }, {
418
+ key: "createDeviceTypeLogicalInterfaceAssociation",
419
+ value: function createDeviceTypeLogicalInterfaceAssociation(typeId, logicalInterfaceId) {
420
+ var body = {
421
+ 'id': logicalInterfaceId
422
+ };
423
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'logicalinterfaces'] : ['device', 'types', typeId, 'applicationinterfaces'];
424
+ return this.callApi('POST', 201, true, base, body);
425
+ }
426
+ }, {
427
+ key: "getDeviceTypeLogicalInterfaces",
428
+ value: function getDeviceTypeLogicalInterfaces(typeId) {
429
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'logicalinterfaces'] : ['device', 'types', typeId, 'applicationinterfaces'];
430
+ return this.callApi('GET', 200, true, base);
431
+ }
432
+ }, {
433
+ key: "getActiveDeviceTypeLogicalInterfaces",
434
+ value: function getActiveDeviceTypeLogicalInterfaces(typeId) {
435
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'logicalinterfaces']);
436
+ }
437
+ }, {
438
+ key: "createDeviceTypeLogicalInterfacePropertyMappings",
439
+ value: function createDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId, mappings, notificationStrategy) {
440
+ var body = null,
441
+ base = null;
442
+
443
+ if (this.draftMode) {
444
+ body = {
445
+ "logicalInterfaceId": logicalInterfaceId,
446
+ "propertyMappings": mappings,
447
+ "notificationStrategy": "never"
448
+ };
449
+
450
+ if (notificationStrategy) {
451
+ body.notificationStrategy = notificationStrategy;
452
+ }
453
+
454
+ base = ['draft', 'device', 'types', typeId, 'mappings'];
455
+ } else {
456
+ body = {
457
+ "applicationInterfaceId": logicalInterfaceId,
458
+ "propertyMappings": mappings
459
+ };
460
+ base = ['device', 'types', typeId, 'mappings'];
461
+ }
462
+
463
+ return this.callApi('POST', 201, true, base, body);
464
+ }
465
+ }, {
466
+ key: "getDeviceTypePropertyMappings",
467
+ value: function getDeviceTypePropertyMappings(typeId) {
468
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'mappings'] : ['device', 'types', typeId, 'mappings'];
469
+ return this.callApi('GET', 200, true, base);
470
+ }
471
+ }, {
472
+ key: "getActiveDeviceTypePropertyMappings",
473
+ value: function getActiveDeviceTypePropertyMappings(typeId) {
474
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'mappings']);
475
+ }
476
+ }, {
477
+ key: "getDeviceTypeLogicalInterfacePropertyMappings",
478
+ value: function getDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId) {
479
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'mappings', logicalInterfaceId] : ['device', 'types', typeId, 'mappings', logicalInterfaceId];
480
+ return this.callApi('GET', 200, true, base);
481
+ }
482
+ }, {
483
+ key: "getActiveDeviceTypeLogicalInterfacePropertyMappings",
484
+ value: function getActiveDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId) {
485
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'mappings', logicalInterfaceId]);
486
+ }
487
+ }, {
488
+ key: "updateDeviceTypeLogicalInterfacePropertyMappings",
489
+ value: function updateDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId, mappings, notificationStrategy) {
490
+ var body = null,
491
+ base = null;
492
+
493
+ if (this.draftMode) {
494
+ body = {
495
+ "logicalInterfaceId": logicalInterfaceId,
496
+ "propertyMappings": mappings,
497
+ "notificationStrategy": "never"
498
+ };
499
+
500
+ if (notificationStrategy) {
501
+ body.notificationStrategy = notificationStrategy;
502
+ }
503
+
504
+ base = ['draft', 'device', 'types', typeId, 'mappings', logicalInterfaceId];
505
+ } else {
506
+ body = {
507
+ "applicationInterfaceId": logicalInterfaceId,
508
+ "propertyMappings": mappings
509
+ };
510
+ base = ['device', 'types', typeId, 'mappings', logicalInterfaceId];
511
+ }
512
+
513
+ return this.callApi('PUT', 200, false, base, body);
514
+ }
515
+ }, {
516
+ key: "deleteDeviceTypeLogicalInterfacePropertyMappings",
517
+ value: function deleteDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId) {
518
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'mappings', logicalInterfaceId] : ['device', 'types', typeId, 'mappings', logicalInterfaceId];
519
+ return this.callApi('DELETE', 204, false, base);
520
+ }
521
+ }, {
522
+ key: "deleteDeviceTypeLogicalInterfaceAssociation",
523
+ value: function deleteDeviceTypeLogicalInterfaceAssociation(typeId, logicalInterfaceId) {
524
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'logicalinterfaces', logicalInterfaceId] : ['device', 'types', typeId, 'applicationinterfaces', logicalInterfaceId];
525
+ return this.callApi('DELETE', 204, false, base);
526
+ } // Device Type patch operation on draft version
527
+ // Acceptable operation id - validate-configuration, activate-configuration, list-differences
528
+
529
+ }, {
530
+ key: "patchOperationDeviceType",
531
+ value: function patchOperationDeviceType(typeId, operationId) {
532
+ if (!operationId) {
533
+ return invalidOperation("PATCH operation is not allowed. Operation id is expected");
534
+ }
535
+
536
+ var body = {
537
+ "operation": operationId
538
+ };
539
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId] : ['device', 'types', typeId];
540
+
541
+ if (this.draftMode) {
542
+ switch (operationId) {
543
+ case 'validate-configuration':
544
+ return this.callApi('PATCH', 200, true, base, body);
545
+ break;
546
+
547
+ case 'activate-configuration':
548
+ return this.callApi('PATCH', 202, true, base, body);
549
+ break;
550
+
551
+ case 'deactivate-configuration':
552
+ return this.callApi('PATCH', 202, true, base, body);
553
+ break;
554
+
555
+ case 'list-differences':
556
+ return this.callApi('PATCH', 200, true, base, body);
557
+ break;
558
+
559
+ default:
560
+ return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
561
+ }
562
+ } else {
563
+ switch (operationId) {
564
+ case 'validate-configuration':
565
+ return this.callApi('PATCH', 200, true, base, body);
566
+ break;
567
+
568
+ case 'deploy-configuration':
569
+ return this.callApi('PATCH', 202, true, base, body);
570
+ break;
571
+
572
+ case 'remove-deployed-configuration':
573
+ return this.callApi('PATCH', 202, true, base, body);
574
+ break;
575
+
576
+ case 'list-differences':
577
+ return this.invalidOperation("PATCH operation 'list-differences' is not allowed");
578
+ break;
579
+
580
+ default:
581
+ return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
582
+ }
583
+ }
584
+ } // Device Type patch operation on active version
585
+ // Acceptable operation id - deactivate-configuration
586
+
587
+ }, {
588
+ key: "patchOperationActiveDeviceType",
589
+ value: function patchOperationActiveDeviceType(typeId, operationId) {
590
+ var body = {
591
+ "operation": operationId
592
+ };
593
+
594
+ if (this.draftMode) {
595
+ return this.callApi('PATCH', 202, true, ['device', 'types', typeId], body);
596
+ } else {
597
+ return this.invalidOperation("PATCH operation 'deactivate-configuration' is not allowed");
598
+ }
599
+ }
600
+ }, {
601
+ key: "getDeviceTypeDeployedConfiguration",
602
+ value: function getDeviceTypeDeployedConfiguration(typeId) {
603
+ if (this.draftMode) {
604
+ return this.invalidOperation("GET deployed configuration is not allowed");
605
+ } else {
606
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'deployedconfiguration']);
607
+ }
608
+ }
609
+ }, {
610
+ key: "getDeviceState",
611
+ value: function getDeviceState(typeId, deviceId, logicalInterfaceId) {
612
+ return this.callApi('GET', 200, true, ['device', 'types', typeId, 'devices', deviceId, 'state', logicalInterfaceId]);
613
+ }
614
+ }, {
615
+ key: "createSchemaAndEventType",
616
+ value: function createSchemaAndEventType(schemaContents, schemaFileName, eventTypeName, eventDescription) {
617
+ var _this = this;
618
+
619
+ var body = {
620
+ 'schemaFile': schemaContents,
621
+ 'schemaType': 'json-schema',
622
+ 'name': schemaFileName
623
+ };
624
+ var createSchema = new Promise(function (resolve, reject) {
625
+ var base = _this.draftMode ? ["draft", "schemas"] : ["schemas"];
626
+
627
+ _this.callFormDataApi('POST', 201, true, base, body, null).then(function (result) {
628
+ resolve(result);
629
+ }, function (error) {
630
+ reject(error);
631
+ });
632
+ });
633
+ return createSchema.then(function (value) {
634
+ var schemaId = value["id"];
635
+ return _this.createEventType(eventTypeName, eventDescription, schemaId);
636
+ });
637
+ }
638
+ }, {
639
+ key: "createSchemaAndLogicalInterface",
640
+ value: function createSchemaAndLogicalInterface(schemaContents, schemaFileName, appInterfaceName, appInterfaceDescription, appInterfaceAlias) {
641
+ var _this2 = this;
642
+
643
+ var body = {
644
+ 'schemaFile': schemaContents,
645
+ 'schemaType': 'json-schema',
646
+ 'name': schemaFileName
647
+ };
648
+ var createSchema = new Promise(function (resolve, reject) {
649
+ var base = _this2.draftMode ? ["draft", "schemas"] : ["schemas"];
650
+
651
+ _this2.callFormDataApi('POST', 201, true, base, body, null).then(function (result) {
652
+ resolve(result);
653
+ }, function (error) {
654
+ reject(error);
655
+ });
656
+ });
657
+ return createSchema.then(function (value) {
658
+ var schemaId = value.id;
659
+ return _this2.createLogicalInterface(appInterfaceName, appInterfaceDescription, schemaId, appInterfaceAlias);
660
+ });
661
+ }
662
+ }, {
663
+ key: "createPhysicalInterfaceWithEventMapping",
664
+ value: function createPhysicalInterfaceWithEventMapping(physicalInterfaceName, description, eventId, eventTypeId) {
665
+ var _this3 = this;
666
+
667
+ var createPhysicalInterface = new Promise(function (resolve, reject) {
668
+ _this3.createPhysicalInterface(physicalInterfaceName, description).then(function (result) {
669
+ resolve(result);
670
+ }, function (error) {
671
+ reject(error);
672
+ });
673
+ });
674
+ return createPhysicalInterface.then(function (value) {
675
+ var physicalInterface = value;
676
+ var PhysicalInterfaceEventMapping = new Promise(function (resolve, reject) {
677
+ _this3.createPhysicalInterfaceEventMapping(physicalInterface.id, eventId, eventTypeId).then(function (result) {
678
+ resolve([physicalInterface, result]);
679
+ }, function (error) {
680
+ reject(error);
681
+ });
682
+ });
683
+ return PhysicalInterfaceEventMapping.then(function (result) {
684
+ return result;
685
+ });
686
+ });
687
+ }
688
+ }, {
689
+ key: "createDeviceTypeLogicalInterfaceEventMapping",
690
+ value: function createDeviceTypeLogicalInterfaceEventMapping(deviceTypeName, description, logicalInterfaceId, eventMapping, notificationStrategy) {
691
+ var _this4 = this;
692
+
693
+ var createDeviceType = new Promise(function (resolve, reject) {
694
+ _this4.createDeviceType(deviceTypeName, description).then(function (result) {
695
+ resolve(result);
696
+ }, function (error) {
697
+ reject(error);
698
+ });
699
+ });
700
+ return createDeviceType.then(function (result) {
701
+ var deviceObject = result;
702
+ var deviceTypeLogicalInterface = null;
703
+ var deviceTypeLogicalInterface = new Promise(function (resolve, reject) {
704
+ _this4.createDeviceTypeLogicalInterfaceAssociation(deviceObject.id, logicalInterfaceId).then(function (result) {
705
+ resolve(result);
706
+ }, function (error) {
707
+ reject(error);
708
+ });
709
+ });
710
+ return deviceTypeLogicalInterface.then(function (result) {
711
+ deviceTypeLogicalInterface = result;
712
+ var deviceTypeLogicalInterfacePropertyMappings = new Promise(function (resolve, reject) {
713
+ var notificationstrategy = "never";
714
+
715
+ if (notificationStrategy) {
716
+ notificationstrategy = notificationStrategy;
717
+ }
718
+
719
+ _this4.createDeviceTypeLogicalInterfacePropertyMappings(deviceObject.id, logicalInterfaceId, eventMapping, notificationstrategy).then(function (result) {
720
+ var arr = [deviceObject, deviceTypeLogicalInterface, result];
721
+ resolve(arr);
722
+ }, function (error) {
723
+ reject(error);
724
+ });
725
+ });
726
+ return deviceTypeLogicalInterfacePropertyMappings.then(function (result) {
727
+ return result;
728
+ });
729
+ });
730
+ });
731
+ }
732
+ }]);
733
+
734
+ return StateClient;
735
+ }();
736
+
737
+ exports["default"] = StateClient;
738
+ ;