@edgeiq/edgeiq-api-js 1.7.5 → 1.7.7

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 (115) hide show
  1. package/dist/OIDC/index.js +137 -238
  2. package/dist/OIDC/models.js +1 -2
  3. package/dist/__tests__/auth.test.js +56 -147
  4. package/dist/__tests__/command.test.js +80 -202
  5. package/dist/__tests__/companies.test.js +121 -269
  6. package/dist/__tests__/deviceErrors.test.js +16 -62
  7. package/dist/__tests__/deviceTypes.test.js +78 -200
  8. package/dist/__tests__/devices.test.js +84 -221
  9. package/dist/__tests__/discoveredDevice.test.js +57 -145
  10. package/dist/__tests__/files.test.js +58 -152
  11. package/dist/__tests__/ingestors.test.js +70 -188
  12. package/dist/__tests__/integrations.test.js +95 -235
  13. package/dist/__tests__/lwm2m.test.js +17 -62
  14. package/dist/__tests__/notifications.test.js +16 -62
  15. package/dist/__tests__/pollableAttributes.test.js +60 -162
  16. package/dist/__tests__/rules.test.js +60 -162
  17. package/dist/__tests__/scheduledJobs.test.js +60 -162
  18. package/dist/__tests__/translators.test.js +60 -162
  19. package/dist/__tests__/users.test.js +77 -197
  20. package/dist/auth/index.js +94 -167
  21. package/dist/bulkResponses/index.js +44 -110
  22. package/dist/bulkResponses/models.js +1 -2
  23. package/dist/commandExecutions/index.js +39 -85
  24. package/dist/commandExecutions/models.d.ts +3 -0
  25. package/dist/commandExecutions/models.js +1 -2
  26. package/dist/commands/index.d.ts +2 -2
  27. package/dist/commands/index.js +196 -342
  28. package/dist/commands/models.js +2 -5
  29. package/dist/companies/index.js +150 -272
  30. package/dist/companies/models.js +1 -2
  31. package/dist/configurations/index.js +172 -310
  32. package/dist/configurations/models.js +1 -2
  33. package/dist/constants.js +69 -85
  34. package/dist/core/ModelClass.js +11 -18
  35. package/dist/core/handleResponseError.js +77 -81
  36. package/dist/core/index.js +30 -38
  37. package/dist/deviceConfigs/index.js +103 -201
  38. package/dist/deviceConfigs/models.js +1 -2
  39. package/dist/deviceErrors/index.js +44 -110
  40. package/dist/deviceErrors/models.js +1 -2
  41. package/dist/deviceLocationObservations/index.js +82 -164
  42. package/dist/deviceLocationObservations/models.js +1 -2
  43. package/dist/deviceTemplates/index.js +105 -203
  44. package/dist/deviceTemplates/models.js +1 -2
  45. package/dist/deviceTransferRequests/index.js +116 -222
  46. package/dist/deviceTransferRequests/models.js +1 -2
  47. package/dist/deviceTypes/index.js +328 -554
  48. package/dist/deviceTypes/models.js +1 -2
  49. package/dist/devices/index.js +630 -971
  50. package/dist/devices/models.js +1 -2
  51. package/dist/discoveredDevices/index.js +190 -328
  52. package/dist/discoveredDevices/models.js +1 -2
  53. package/dist/downstreamSystems/index.js +87 -177
  54. package/dist/downstreamSystems/models.js +1 -2
  55. package/dist/escrowDevices/index.js +103 -201
  56. package/dist/escrowDevices/models.js +1 -2
  57. package/dist/files/index.js +137 -251
  58. package/dist/files/models.js +1 -2
  59. package/dist/filtersParser.js +12 -17
  60. package/dist/gatewayCommands/index.js +103 -201
  61. package/dist/gatewayCommands/models.js +1 -2
  62. package/dist/helpers.js +10 -16
  63. package/dist/index.js +86 -142
  64. package/dist/ingestors/index.js +103 -201
  65. package/dist/ingestors/models.js +1 -2
  66. package/dist/integrations/index.js +159 -273
  67. package/dist/integrations/models.js +1 -2
  68. package/dist/log/models.js +1 -2
  69. package/dist/lwm2m/index.js +23 -72
  70. package/dist/lwm2m/models.js +1 -2
  71. package/dist/models/index.js +1 -2
  72. package/dist/models.js +1 -2
  73. package/dist/notifications/index.js +44 -110
  74. package/dist/notifications/models.js +1 -2
  75. package/dist/pollableAttributes/index.js +87 -177
  76. package/dist/pollableAttributes/models.js +1 -2
  77. package/dist/regions/index.js +72 -154
  78. package/dist/regions/models.js +1 -2
  79. package/dist/reports/index.js +88 -178
  80. package/dist/reports/models.js +1 -2
  81. package/dist/retryOptions/models.js +1 -2
  82. package/dist/rules/index.js +131 -245
  83. package/dist/rules/models.js +1 -2
  84. package/dist/scheduledJobs/index.js +183 -321
  85. package/dist/scheduledJobs/models.js +1 -2
  86. package/dist/secrets/index.js +88 -178
  87. package/dist/secrets/models.js +1 -2
  88. package/dist/settings/index.js +119 -227
  89. package/dist/settings/models.js +1 -2
  90. package/dist/settingsApplicationRecord/index.js +27 -65
  91. package/dist/settingsApplicationRecord/models.js +1 -2
  92. package/dist/softwareUpdates/index.js +194 -350
  93. package/dist/softwareUpdates/models.js +1 -2
  94. package/dist/stats/index.js +64 -126
  95. package/dist/stats/models.js +1 -2
  96. package/dist/systemCommandJobs/index.js +72 -154
  97. package/dist/systemCommandJobs/models.js +1 -2
  98. package/dist/systemCommands/index.js +87 -177
  99. package/dist/systemCommands/models.js +1 -2
  100. package/dist/testConstants.js +57 -71
  101. package/dist/translators/index.js +103 -201
  102. package/dist/translators/models.js +1 -2
  103. package/dist/userTypes/index.js +87 -177
  104. package/dist/userTypes/models.js +1 -2
  105. package/dist/users/index.js +149 -271
  106. package/dist/users/models.js +1 -2
  107. package/dist/workflowActions/index.js +132 -246
  108. package/dist/workflowActions/models.js +1 -2
  109. package/dist/workflowDefinitions/index.js +104 -202
  110. package/dist/workflowDefinitions/models.js +1 -2
  111. package/dist/workflowExecutions/index.js +27 -65
  112. package/dist/workflowExecutions/models.js +1 -2
  113. package/dist/workflows/index.js +39 -85
  114. package/dist/workflows/models.js +1 -2
  115. package/package.json +1 -1
@@ -1,30 +1,3 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,950 +7,636 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
35
8
  });
36
9
  };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
10
+ import { EdgeIQAPI, } from '..';
11
+ import { Endpoints, getAttachMessage } from '../constants';
12
+ import { BaseModelClass } from '../core/ModelClass';
13
+ import { parseFilters } from '../filtersParser';
14
+ import { getReturnDeleteMessage, isApiError } from '../helpers';
15
+ export const Devices = class extends BaseModelClass {
16
+ static create(device) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ this.logAction(`Creating device with unique ID: ${device}`);
20
+ const axios = EdgeIQAPI.getAxios();
21
+ const data = JSON.stringify(device);
22
+ const result = yield axios.post(Endpoints.device, data);
23
+ return result === null || result === void 0 ? void 0 : result.data;
24
+ }
25
+ catch (error) {
26
+ if (isApiError(error)) {
27
+ throw error;
28
+ }
29
+ throw error;
30
+ }
31
+ });
62
32
  }
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.Devices = void 0;
66
- var __1 = require("..");
67
- var constants_1 = require("../constants");
68
- var ModelClass_1 = require("../core/ModelClass");
69
- var filtersParser_1 = require("../filtersParser");
70
- var helpers_1 = require("../helpers");
71
- exports.Devices = (function (_super) {
72
- __extends(class_1, _super);
73
- function class_1() {
74
- return _super !== null && _super.apply(this, arguments) || this;
75
- }
76
- class_1.create = function (device) {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var axios, data, result, error_1;
79
- return __generator(this, function (_a) {
80
- switch (_a.label) {
81
- case 0:
82
- _a.trys.push([0, 2, , 3]);
83
- this.logAction("Creating device with unique ID: " + device);
84
- axios = __1.EdgeIQAPI.getAxios();
85
- data = JSON.stringify(device);
86
- return [4, axios.post(constants_1.Endpoints.device, data)];
87
- case 1:
88
- result = _a.sent();
89
- return [2, result === null || result === void 0 ? void 0 : result.data];
90
- case 2:
91
- error_1 = _a.sent();
92
- if ((0, helpers_1.isApiError)(error_1)) {
93
- throw error_1;
94
- }
95
- throw error_1;
96
- case 3: return [2];
97
- }
98
- });
99
- });
100
- };
101
- class_1.bulkCreate = function (uniqueIds, deviceTypeId, namePrefix) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var axios, result, error_2;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- _a.trys.push([0, 2, , 3]);
108
- this.logAction("Creating " + uniqueIds.length + " devices with device type id " + deviceTypeId + " and name prefix '" + namePrefix + "'");
109
- axios = __1.EdgeIQAPI.getAxios();
110
- return [4, axios.post(constants_1.Endpoints.device + "/bulk", {
111
- data: {
112
- unique_ids: uniqueIds,
113
- device_type_id: deviceTypeId,
114
- name_prefix: namePrefix,
115
- },
116
- })];
117
- case 1:
118
- result = _a.sent();
119
- return [2, result === null || result === void 0 ? void 0 : result.data];
120
- case 2:
121
- error_2 = _a.sent();
122
- if ((0, helpers_1.isApiError)(error_2)) {
123
- throw error_2;
124
- }
125
- throw error_2;
126
- case 3: return [2];
127
- }
128
- });
129
- });
130
- };
131
- class_1.update = function (device) {
132
- return __awaiter(this, void 0, void 0, function () {
133
- var axios, data, result, error_3;
134
- return __generator(this, function (_a) {
135
- switch (_a.label) {
136
- case 0:
137
- _a.trys.push([0, 2, , 3]);
138
- this.logAction("Updating device with unique ID: " + device.unique_id);
139
- axios = __1.EdgeIQAPI.getAxios();
140
- data = JSON.stringify(device);
141
- return [4, axios.put(constants_1.Endpoints.device + "/" + device._id, data)];
142
- case 1:
143
- result = _a.sent();
144
- return [2, result === null || result === void 0 ? void 0 : result.data];
145
- case 2:
146
- error_3 = _a.sent();
147
- if ((0, helpers_1.isApiError)(error_3)) {
148
- throw error_3;
149
- }
150
- throw error_3;
151
- case 3: return [2];
152
- }
153
- });
154
- });
155
- };
156
- class_1.deleteMetadata = function (id) {
157
- return __awaiter(this, void 0, void 0, function () {
158
- var axios, result, error_4;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
161
- case 0:
162
- _a.trys.push([0, 2, , 3]);
163
- this.logAction("Delete device metadata with ID: " + id);
164
- axios = __1.EdgeIQAPI.getAxios();
165
- return [4, axios.put(constants_1.Endpoints.device + "/" + id, {
166
- metadata: {},
167
- })];
168
- case 1:
169
- result = _a.sent();
170
- return [2, result === null || result === void 0 ? void 0 : result.data];
171
- case 2:
172
- error_4 = _a.sent();
173
- if ((0, helpers_1.isApiError)(error_4)) {
174
- throw error_4;
175
- }
176
- throw error_4;
177
- case 3: return [2];
178
- }
179
- });
180
- });
181
- };
182
- class_1.list = function (filters, pagination, boundingBox) {
33
+ static bulkCreate(uniqueIds, deviceTypeId, namePrefix) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ this.logAction(`Creating ${uniqueIds.length} devices with device type id ${deviceTypeId} and name prefix '${namePrefix}'`);
37
+ const axios = EdgeIQAPI.getAxios();
38
+ const result = yield axios.post(`${Endpoints.device}/bulk`, {
39
+ data: {
40
+ unique_ids: uniqueIds,
41
+ device_type_id: deviceTypeId,
42
+ name_prefix: namePrefix,
43
+ },
44
+ });
45
+ return result === null || result === void 0 ? void 0 : result.data;
46
+ }
47
+ catch (error) {
48
+ if (isApiError(error)) {
49
+ throw error;
50
+ }
51
+ throw error;
52
+ }
53
+ });
54
+ }
55
+ static update(device) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ this.logAction(`Updating device with unique ID: ${device.unique_id}`);
59
+ const axios = EdgeIQAPI.getAxios();
60
+ const data = JSON.stringify(device);
61
+ const result = yield axios.put(`${Endpoints.device}/${device._id}`, data);
62
+ return result === null || result === void 0 ? void 0 : result.data;
63
+ }
64
+ catch (error) {
65
+ if (isApiError(error)) {
66
+ throw error;
67
+ }
68
+ throw error;
69
+ }
70
+ });
71
+ }
72
+ static deleteMetadata(id) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ try {
75
+ this.logAction(`Delete device metadata with ID: ${id}`);
76
+ const axios = EdgeIQAPI.getAxios();
77
+ const result = yield axios.put(`${Endpoints.device}/${id}`, {
78
+ metadata: {},
79
+ });
80
+ return result === null || result === void 0 ? void 0 : result.data;
81
+ }
82
+ catch (error) {
83
+ if (isApiError(error)) {
84
+ throw error;
85
+ }
86
+ throw error;
87
+ }
88
+ });
89
+ }
90
+ static list(filters, pagination, boundingBox) {
183
91
  var _a, _b, _c, _d;
184
- return __awaiter(this, void 0, void 0, function () {
185
- var endpoint, axios, result, error_5;
186
- return __generator(this, function (_e) {
187
- switch (_e.label) {
188
- case 0:
189
- _e.trys.push([0, 2, , 3]);
190
- this.logAction("Listing devices with following filters: " + (filters !== null && filters !== void 0 ? filters : '{}') + ".\n And pagination " + (pagination !== null && pagination !== void 0 ? pagination : '{}'));
191
- endpoint = constants_1.Endpoints.device;
192
- if ((boundingBox === null || boundingBox === void 0 ? void 0 : boundingBox.topLeft) && boundingBox.bottomRight) {
193
- this.logAction("With bounding box, top left: " + boundingBox.topLeft + ", bottom right: " + boundingBox.bottomRight);
194
- endpoint += "/in_bounding_box/" + boundingBox.topLeft + "/" + boundingBox.bottomRight;
195
- }
196
- axios = __1.EdgeIQAPI.getAxios();
197
- return [4, axios.get(endpoint, {
198
- params: (0, filtersParser_1.parseFilters)(filters, pagination),
199
- })];
200
- case 1:
201
- result = _e.sent();
202
- return [2, {
203
- devices: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
204
- pagination: {
205
- page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
206
- itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
207
- total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
208
- },
209
- }];
210
- case 2:
211
- error_5 = _e.sent();
212
- if ((0, helpers_1.isApiError)(error_5)) {
213
- throw error_5;
214
- }
215
- throw error_5;
216
- case 3: return [2];
217
- }
218
- });
219
- });
220
- };
221
- class_1.getOneById = function (id) {
222
- return __awaiter(this, void 0, void 0, function () {
223
- var axios, result, error_6;
224
- return __generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0:
227
- _a.trys.push([0, 2, , 3]);
228
- this.logAction("Getting device with id: " + id);
229
- axios = __1.EdgeIQAPI.getAxios();
230
- return [4, axios.get(constants_1.Endpoints.device + "/" + id)];
231
- case 1:
232
- result = _a.sent();
233
- return [2, result === null || result === void 0 ? void 0 : result.data];
234
- case 2:
235
- error_6 = _a.sent();
236
- if ((0, helpers_1.isApiError)(error_6)) {
237
- throw error_6;
238
- }
239
- throw error_6;
240
- case 3: return [2];
241
- }
242
- });
243
- });
244
- };
245
- class_1.getOneByUniqueId = function (uniqueId) {
246
- return __awaiter(this, void 0, void 0, function () {
247
- var axios, result, error_7;
248
- return __generator(this, function (_a) {
249
- switch (_a.label) {
250
- case 0:
251
- _a.trys.push([0, 2, , 3]);
252
- this.logAction("Getting device with Unique Id: " + uniqueId);
253
- axios = __1.EdgeIQAPI.getAxios();
254
- return [4, axios.get(constants_1.Endpoints.device, {
255
- params: {
256
- unique_id: uniqueId,
257
- },
258
- })];
259
- case 1:
260
- result = _a.sent();
261
- return [2, result === null || result === void 0 ? void 0 : result.data[0]];
262
- case 2:
263
- error_7 = _a.sent();
264
- if ((0, helpers_1.isApiError)(error_7)) {
265
- throw error_7;
266
- }
267
- throw error_7;
268
- case 3: return [2];
269
- }
270
- });
271
- });
272
- };
273
- class_1.delete = function (id) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- var axios, error_8;
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0:
279
- _a.trys.push([0, 2, , 3]);
280
- this.logAction("Deleting device with id " + id);
281
- axios = __1.EdgeIQAPI.getAxios();
282
- return [4, axios.delete(constants_1.Endpoints.device + "/" + id)];
283
- case 1:
284
- _a.sent();
285
- return [2, (0, helpers_1.getReturnDeleteMessage)('device')];
286
- case 2:
287
- error_8 = _a.sent();
288
- if ((0, helpers_1.isApiError)(error_8)) {
289
- throw error_8;
290
- }
291
- throw error_8;
292
- case 3: return [2];
293
- }
294
- });
295
- });
296
- };
297
- class_1.deleteMultiple = function (ids) {
298
- return __awaiter(this, void 0, void 0, function () {
299
- var axios, result, error_9;
300
- return __generator(this, function (_a) {
301
- switch (_a.label) {
302
- case 0:
303
- _a.trys.push([0, 2, , 3]);
304
- this.logAction("Deleting devices with id " + ids.join(', '));
305
- axios = __1.EdgeIQAPI.getAxios();
306
- return [4, axios.delete(constants_1.Endpoints.device + "/bulk", {
307
- data: { ids: ids },
308
- })];
309
- case 1:
310
- result = _a.sent();
311
- return [2, result === null || result === void 0 ? void 0 : result.data];
312
- case 2:
313
- error_9 = _a.sent();
314
- if ((0, helpers_1.isApiError)(error_9)) {
315
- throw error_9;
316
- }
317
- throw error_9;
318
- case 3: return [2];
319
- }
320
- });
321
- });
322
- };
323
- class_1.attachIngestor = function (id, ingestorId) {
324
- return __awaiter(this, void 0, void 0, function () {
325
- var axios, error_10;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0:
329
- _a.trys.push([0, 2, , 3]);
330
- this.logAction("Attach ingestor with id: " + ingestorId + " to device with id: " + id);
331
- axios = __1.EdgeIQAPI.getAxios();
332
- return [4, axios.put(constants_1.Endpoints.device + "/" + id + "/ingestors/" + ingestorId)];
333
- case 1:
334
- _a.sent();
335
- return [2, (0, constants_1.getAttachMessage)('Ingestor', 'attach', 'device')];
336
- case 2:
337
- error_10 = _a.sent();
338
- if ((0, helpers_1.isApiError)(error_10)) {
339
- throw error_10;
340
- }
341
- throw error_10;
342
- case 3: return [2];
343
- }
344
- });
345
- });
346
- };
347
- class_1.detachIngestor = function (id, ingestorId) {
348
- return __awaiter(this, void 0, void 0, function () {
349
- var axios, error_11;
350
- return __generator(this, function (_a) {
351
- switch (_a.label) {
352
- case 0:
353
- _a.trys.push([0, 2, , 3]);
354
- this.logAction("Detach ingestor with id: " + ingestorId + " from device with id: " + id);
355
- axios = __1.EdgeIQAPI.getAxios();
356
- return [4, axios.delete(constants_1.Endpoints.device + "/" + id + "/ingestors/" + ingestorId)];
357
- case 1:
358
- _a.sent();
359
- return [2, (0, constants_1.getAttachMessage)('Ingestor', 'detach', 'device')];
360
- case 2:
361
- error_11 = _a.sent();
362
- if ((0, helpers_1.isApiError)(error_11)) {
363
- throw error_11;
364
- }
365
- throw error_11;
366
- case 3: return [2];
367
- }
368
- });
369
- });
370
- };
371
- class_1.getIngestors = function (id) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- var axios, result, error_12;
374
- return __generator(this, function (_a) {
375
- switch (_a.label) {
376
- case 0:
377
- _a.trys.push([0, 2, , 3]);
378
- this.logAction("Getting ingestors attached to device with id " + id);
379
- axios = __1.EdgeIQAPI.getAxios();
380
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/ingestors")];
381
- case 1:
382
- result = _a.sent();
383
- return [2, result === null || result === void 0 ? void 0 : result.data];
384
- case 2:
385
- error_12 = _a.sent();
386
- if ((0, helpers_1.isApiError)(error_12)) {
387
- throw error_12;
388
- }
389
- throw error_12;
390
- case 3: return [2];
391
- }
392
- });
393
- });
394
- };
395
- class_1.attachRule = function (id, ruleId) {
396
- return __awaiter(this, void 0, void 0, function () {
397
- var axios, error_13;
398
- return __generator(this, function (_a) {
399
- switch (_a.label) {
400
- case 0:
401
- _a.trys.push([0, 2, , 3]);
402
- this.logAction("Attach rule with id: " + ruleId + " to device with id: " + id);
403
- axios = __1.EdgeIQAPI.getAxios();
404
- return [4, axios.put(constants_1.Endpoints.device + "/" + id + "/rules/" + ruleId)];
405
- case 1:
406
- _a.sent();
407
- return [2, (0, constants_1.getAttachMessage)('Rule', 'attach', 'device')];
408
- case 2:
409
- error_13 = _a.sent();
410
- if ((0, helpers_1.isApiError)(error_13)) {
411
- throw error_13;
412
- }
413
- throw error_13;
414
- case 3: return [2];
415
- }
416
- });
417
- });
418
- };
419
- class_1.bulkAttachRules = function (id, rulesIds) {
420
- return __awaiter(this, void 0, void 0, function () {
421
- var axios, result, error_14;
422
- return __generator(this, function (_a) {
423
- switch (_a.label) {
424
- case 0:
425
- _a.trys.push([0, 2, , 3]);
426
- this.logAction("Attaching " + rulesIds.length + " rules with to device with id " + id);
427
- axios = __1.EdgeIQAPI.getAxios();
428
- return [4, axios.post(constants_1.Endpoints.device + "/" + id + "/rules/bulk", {
429
- ids: rulesIds,
430
- })];
431
- case 1:
432
- result = _a.sent();
433
- return [2, result === null || result === void 0 ? void 0 : result.data];
434
- case 2:
435
- error_14 = _a.sent();
436
- if ((0, helpers_1.isApiError)(error_14)) {
437
- throw error_14;
438
- }
439
- throw error_14;
440
- case 3: return [2];
441
- }
442
- });
443
- });
444
- };
445
- class_1.detachRule = function (id, ruleId) {
446
- return __awaiter(this, void 0, void 0, function () {
447
- var axios, error_15;
448
- return __generator(this, function (_a) {
449
- switch (_a.label) {
450
- case 0:
451
- _a.trys.push([0, 2, , 3]);
452
- this.logAction("Detach rule with id: " + ruleId + " from device with id: " + id);
453
- axios = __1.EdgeIQAPI.getAxios();
454
- return [4, axios.delete(constants_1.Endpoints.device + "/" + id + "/rules/" + ruleId)];
455
- case 1:
456
- _a.sent();
457
- return [2, (0, constants_1.getAttachMessage)('Rule', 'detach', 'device')];
458
- case 2:
459
- error_15 = _a.sent();
460
- if ((0, helpers_1.isApiError)(error_15)) {
461
- throw error_15;
462
- }
463
- throw error_15;
464
- case 3: return [2];
465
- }
466
- });
467
- });
468
- };
469
- class_1.getRules = function (id) {
470
- return __awaiter(this, void 0, void 0, function () {
471
- var axios, result, error_16;
472
- return __generator(this, function (_a) {
473
- switch (_a.label) {
474
- case 0:
475
- _a.trys.push([0, 2, , 3]);
476
- this.logAction("Getting rules attached to device with id " + id);
477
- axios = __1.EdgeIQAPI.getAxios();
478
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/rules")];
479
- case 1:
480
- result = _a.sent();
481
- return [2, result === null || result === void 0 ? void 0 : result.data];
482
- case 2:
483
- error_16 = _a.sent();
484
- if ((0, helpers_1.isApiError)(error_16)) {
485
- throw error_16;
486
- }
487
- throw error_16;
488
- case 3: return [2];
489
- }
490
- });
491
- });
492
- };
493
- class_1.getAwsThingGroups = function (id) {
494
- return __awaiter(this, void 0, void 0, function () {
495
- var axios, result, error_17;
496
- return __generator(this, function (_a) {
497
- switch (_a.label) {
498
- case 0:
499
- _a.trys.push([0, 2, , 3]);
500
- this.logAction("Getting AWS thing groups for device with id: " + id);
501
- axios = __1.EdgeIQAPI.getAxios();
502
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/aws_thing_groups")];
503
- case 1:
504
- result = _a.sent();
505
- return [2, result === null || result === void 0 ? void 0 : result.data];
506
- case 2:
507
- error_17 = _a.sent();
508
- if ((0, helpers_1.isApiError)(error_17)) {
509
- throw error_17;
510
- }
511
- throw error_17;
512
- case 3: return [2];
513
- }
514
- });
515
- });
516
- };
517
- class_1.getCommands = function (id) {
518
- return __awaiter(this, void 0, void 0, function () {
519
- var axios, result, error_18;
520
- return __generator(this, function (_a) {
521
- switch (_a.label) {
522
- case 0:
523
- _a.trys.push([0, 2, , 3]);
524
- this.logAction("Getting commands attached to device with id " + id);
525
- axios = __1.EdgeIQAPI.getAxios();
526
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/" + constants_1.Endpoints.command)];
527
- case 1:
528
- result = _a.sent();
529
- return [2, result === null || result === void 0 ? void 0 : result.data];
530
- case 2:
531
- error_18 = _a.sent();
532
- if ((0, helpers_1.isApiError)(error_18)) {
533
- throw error_18;
534
- }
535
- throw error_18;
536
- case 3: return [2];
537
- }
538
- });
539
- });
540
- };
541
- class_1.csvBulkUpload = function (file) {
542
- return __awaiter(this, void 0, void 0, function () {
543
- var axios, form, result, error_19;
544
- return __generator(this, function (_a) {
545
- switch (_a.label) {
546
- case 0:
547
- _a.trys.push([0, 2, , 3]);
548
- this.logAction("Uploading CSV file with devices");
549
- axios = __1.EdgeIQAPI.getAxios();
550
- form = new FormData();
551
- form.append('gateway_csv_upload', file);
552
- return [4, axios.post(constants_1.Endpoints.device + "/csv_bulk_upload", form, {
553
- headers: {
554
- 'Content-Type': 'multipart/form-data',
555
- },
556
- })];
557
- case 1:
558
- result = _a.sent();
559
- return [2, result === null || result === void 0 ? void 0 : result.data];
560
- case 2:
561
- error_19 = _a.sent();
562
- if ((0, helpers_1.isApiError)(error_19)) {
563
- throw error_19;
564
- }
565
- throw error_19;
566
- case 3: return [2];
567
- }
568
- });
569
- });
570
- };
571
- class_1.csvBulkDownload = function (filters) {
572
- return __awaiter(this, void 0, void 0, function () {
573
- var axios, result, error_20;
574
- return __generator(this, function (_a) {
575
- switch (_a.label) {
576
- case 0:
577
- _a.trys.push([0, 2, , 3]);
578
- this.logAction("Listing devices with following filters: " + (filters !== null && filters !== void 0 ? filters : '{}'));
579
- axios = __1.EdgeIQAPI.getAxios();
580
- return [4, axios.get(constants_1.Endpoints.device + "/csv_bulk_download", {
581
- params: (0, filtersParser_1.parseFilters)(filters, undefined, true),
582
- })];
583
- case 1:
584
- result = _a.sent();
585
- return [2, result === null || result === void 0 ? void 0 : result.data];
586
- case 2:
587
- error_20 = _a.sent();
588
- if ((0, helpers_1.isApiError)(error_20)) {
589
- throw error_20;
590
- }
591
- throw error_20;
592
- case 3: return [2];
593
- }
594
- });
595
- });
596
- };
597
- class_1.getLogs = function (id) {
598
- return __awaiter(this, void 0, void 0, function () {
599
- var axios, result, error_21;
600
- return __generator(this, function (_a) {
601
- switch (_a.label) {
602
- case 0:
603
- _a.trys.push([0, 2, , 3]);
604
- this.logAction("Getting logs attached to device with id " + id);
605
- axios = __1.EdgeIQAPI.getAxios();
606
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/" + constants_1.Endpoints.logs)];
607
- case 1:
608
- result = _a.sent();
609
- return [2, result === null || result === void 0 ? void 0 : result.data];
610
- case 2:
611
- error_21 = _a.sent();
612
- if ((0, helpers_1.isApiError)(error_21)) {
613
- throw error_21;
614
- }
615
- throw error_21;
616
- case 3: return [2];
617
- }
618
- });
619
- });
620
- };
621
- class_1.requestLogs = function (id) {
622
- return __awaiter(this, void 0, void 0, function () {
623
- var axios, result, error_22;
624
- return __generator(this, function (_a) {
625
- switch (_a.label) {
626
- case 0:
627
- _a.trys.push([0, 2, , 3]);
628
- this.logAction("requesting logs for device with " + id);
629
- axios = __1.EdgeIQAPI.getAxios();
630
- return [4, axios.post(constants_1.Endpoints.device + "/" + id + "/" + constants_1.Endpoints.gatewayCommand, {
631
- command_type: 'log_upload',
632
- schedule: null,
633
- })];
634
- case 1:
635
- result = _a.sent();
636
- return [2, result === null || result === void 0 ? void 0 : result.data];
637
- case 2:
638
- error_22 = _a.sent();
639
- if ((0, helpers_1.isApiError)(error_22)) {
640
- throw error_22;
641
- }
642
- throw error_22;
643
- case 3: return [2];
644
- }
645
- });
646
- });
647
- };
648
- class_1.deviceLwm2mObjetLinks = function (id) {
649
- return __awaiter(this, void 0, void 0, function () {
650
- var axios, result, error_23;
651
- return __generator(this, function (_a) {
652
- switch (_a.label) {
653
- case 0:
654
- _a.trys.push([0, 2, , 3]);
655
- this.logAction("Getting lwm2m object links attached to device with id " + id);
656
- axios = __1.EdgeIQAPI.getAxios();
657
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/" + constants_1.Endpoints.deviceLwm2mObjetLinks)];
658
- case 1:
659
- result = _a.sent();
660
- return [2, result === null || result === void 0 ? void 0 : result.data];
661
- case 2:
662
- error_23 = _a.sent();
663
- if ((0, helpers_1.isApiError)(error_23)) {
664
- throw error_23;
665
- }
666
- throw error_23;
667
- case 3: return [2];
668
- }
669
- });
670
- });
671
- };
672
- class_1.processGatewayCommand = function (deviceId, gatewayCommandRequest) {
673
- return __awaiter(this, void 0, void 0, function () {
674
- var axios, data, result, error_24;
675
- return __generator(this, function (_a) {
676
- switch (_a.label) {
677
- case 0:
678
- _a.trys.push([0, 2, , 3]);
679
- this.logAction("Process gateway command: " + gatewayCommandRequest.command_type + ", on device id: " + deviceId);
680
- axios = __1.EdgeIQAPI.getAxios();
681
- data = JSON.stringify(gatewayCommandRequest);
682
- return [4, axios.post(constants_1.Endpoints.device + "/" + deviceId + "/" + gatewayCommandRequest.command_type, data)];
683
- case 1:
684
- result = _a.sent();
685
- return [2, result === null || result === void 0 ? void 0 : result.data];
686
- case 2:
687
- error_24 = _a.sent();
688
- if ((0, helpers_1.isApiError)(error_24)) {
689
- throw error_24;
690
- }
691
- throw error_24;
692
- case 3: return [2];
693
- }
694
- });
695
- });
696
- };
697
- class_1.bulkExecuteGatewayCommand = function (ids, gatewayCommandRequest, generateChildCommandExecutions) {
698
- return __awaiter(this, void 0, void 0, function () {
699
- var axios, result, error_25;
700
- return __generator(this, function (_a) {
701
- switch (_a.label) {
702
- case 0:
703
- _a.trys.push([0, 2, , 3]);
704
- this.logAction("Execute " + gatewayCommandRequest.command_type + " command on devices with IDs: " + ids);
705
- axios = __1.EdgeIQAPI.getAxios();
706
- return [4, axios.post(constants_1.Endpoints.device + "/bulk/gateway_command", __assign(__assign({}, gatewayCommandRequest), { generate_child_command_executions: generateChildCommandExecutions !== null && generateChildCommandExecutions !== void 0 ? generateChildCommandExecutions : false, ids: ids }))];
707
- case 1:
708
- result = _a.sent();
709
- return [2, result === null || result === void 0 ? void 0 : result.data];
710
- case 2:
711
- error_25 = _a.sent();
712
- if ((0, helpers_1.isApiError)(error_25)) {
713
- throw error_25;
714
- }
715
- throw error_25;
716
- case 3: return [2];
717
- }
718
- });
719
- });
720
- };
721
- class_1.bulkExecuteCommand = function (commandId, ids, options, generateChildCommandExecutions) {
722
- return __awaiter(this, void 0, void 0, function () {
723
- var axios, data, result, error_26;
724
- return __generator(this, function (_a) {
725
- switch (_a.label) {
726
- case 0:
727
- _a.trys.push([0, 2, , 3]);
728
- this.logAction("Execute command with ID: " + commandId + " on devices with IDs: " + ids);
729
- axios = __1.EdgeIQAPI.getAxios();
730
- data = {
731
- ids: ids,
732
- generate_child_command_executions: generateChildCommandExecutions !== null && generateChildCommandExecutions !== void 0 ? generateChildCommandExecutions : false,
733
- };
734
- return [4, axios.post(constants_1.Endpoints.device + "/bulk/commands/" + commandId + "/execute", options
735
- ? __assign(__assign({}, data), { options: options }) : __assign({}, data))];
736
- case 1:
737
- result = _a.sent();
738
- return [2, result === null || result === void 0 ? void 0 : result.data];
739
- case 2:
740
- error_26 = _a.sent();
741
- if ((0, helpers_1.isApiError)(error_26)) {
742
- throw error_26;
743
- }
744
- throw error_26;
745
- case 3: return [2];
746
- }
747
- });
748
- });
749
- };
750
- class_1.getFiles = function (id) {
751
- return __awaiter(this, void 0, void 0, function () {
752
- var axios, result, error_27;
753
- return __generator(this, function (_a) {
754
- switch (_a.label) {
755
- case 0:
756
- _a.trys.push([0, 2, , 3]);
757
- this.logAction("Getting files attached to device with id " + id);
758
- axios = __1.EdgeIQAPI.getAxios();
759
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/files")];
760
- case 1:
761
- result = _a.sent();
762
- return [2, result === null || result === void 0 ? void 0 : result.data];
763
- case 2:
764
- error_27 = _a.sent();
765
- if ((0, helpers_1.isApiError)(error_27)) {
766
- throw error_27;
767
- }
768
- throw error_27;
769
- case 3: return [2];
770
- }
771
- });
772
- });
773
- };
774
- class_1.getCommandExecutions = function (id, filters, pagination) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ try {
94
+ this.logAction(`Listing devices with following filters: ${filters !== null && filters !== void 0 ? filters : '{}'}.\n And pagination ${pagination !== null && pagination !== void 0 ? pagination : '{}'}`);
95
+ let endpoint = Endpoints.device;
96
+ if ((boundingBox === null || boundingBox === void 0 ? void 0 : boundingBox.topLeft) && boundingBox.bottomRight) {
97
+ this.logAction(`With bounding box, top left: ${boundingBox.topLeft}, bottom right: ${boundingBox.bottomRight}`);
98
+ endpoint += `/in_bounding_box/${boundingBox.topLeft}/${boundingBox.bottomRight}`;
99
+ }
100
+ const axios = EdgeIQAPI.getAxios();
101
+ const result = yield axios.get(endpoint, {
102
+ params: parseFilters(filters, pagination),
103
+ });
104
+ return {
105
+ devices: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
106
+ pagination: {
107
+ page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
108
+ itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
109
+ total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
110
+ },
111
+ };
112
+ }
113
+ catch (error) {
114
+ if (isApiError(error)) {
115
+ throw error;
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ }
121
+ static getOneById(id) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ try {
124
+ this.logAction(`Getting device with id: ${id}`);
125
+ const axios = EdgeIQAPI.getAxios();
126
+ const result = yield axios.get(`${Endpoints.device}/${id}`);
127
+ return result === null || result === void 0 ? void 0 : result.data;
128
+ }
129
+ catch (error) {
130
+ if (isApiError(error)) {
131
+ throw error;
132
+ }
133
+ throw error;
134
+ }
135
+ });
136
+ }
137
+ static getOneByUniqueId(uniqueId) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ try {
140
+ this.logAction(`Getting device with Unique Id: ${uniqueId}`);
141
+ const axios = EdgeIQAPI.getAxios();
142
+ const result = yield axios.get(Endpoints.device, {
143
+ params: {
144
+ unique_id: uniqueId,
145
+ },
146
+ });
147
+ return result === null || result === void 0 ? void 0 : result.data[0];
148
+ }
149
+ catch (error) {
150
+ if (isApiError(error)) {
151
+ throw error;
152
+ }
153
+ throw error;
154
+ }
155
+ });
156
+ }
157
+ static delete(id) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ try {
160
+ this.logAction(`Deleting device with id ${id}`);
161
+ const axios = EdgeIQAPI.getAxios();
162
+ yield axios.delete(`${Endpoints.device}/${id}`);
163
+ return getReturnDeleteMessage('device');
164
+ }
165
+ catch (error) {
166
+ if (isApiError(error)) {
167
+ throw error;
168
+ }
169
+ throw error;
170
+ }
171
+ });
172
+ }
173
+ static deleteMultiple(ids) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ try {
176
+ this.logAction(`Deleting devices with id ${ids.join(', ')}`);
177
+ const axios = EdgeIQAPI.getAxios();
178
+ const result = yield axios.delete(`${Endpoints.device}/bulk`, {
179
+ data: { ids },
180
+ });
181
+ return result === null || result === void 0 ? void 0 : result.data;
182
+ }
183
+ catch (error) {
184
+ if (isApiError(error)) {
185
+ throw error;
186
+ }
187
+ throw error;
188
+ }
189
+ });
190
+ }
191
+ static attachIngestor(id, ingestorId) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ try {
194
+ this.logAction(`Attach ingestor with id: ${ingestorId} to device with id: ${id}`);
195
+ const axios = EdgeIQAPI.getAxios();
196
+ yield axios.put(`${Endpoints.device}/${id}/ingestors/${ingestorId}`);
197
+ return getAttachMessage('Ingestor', 'attach', 'device');
198
+ }
199
+ catch (error) {
200
+ if (isApiError(error)) {
201
+ throw error;
202
+ }
203
+ throw error;
204
+ }
205
+ });
206
+ }
207
+ static detachIngestor(id, ingestorId) {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ try {
210
+ this.logAction(`Detach ingestor with id: ${ingestorId} from device with id: ${id}`);
211
+ const axios = EdgeIQAPI.getAxios();
212
+ yield axios.delete(`${Endpoints.device}/${id}/ingestors/${ingestorId}`);
213
+ return getAttachMessage('Ingestor', 'detach', 'device');
214
+ }
215
+ catch (error) {
216
+ if (isApiError(error)) {
217
+ throw error;
218
+ }
219
+ throw error;
220
+ }
221
+ });
222
+ }
223
+ static getIngestors(id) {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ try {
226
+ this.logAction(`Getting ingestors attached to device with id ${id}`);
227
+ const axios = EdgeIQAPI.getAxios();
228
+ const result = yield axios.get(`${Endpoints.device}/${id}/ingestors`);
229
+ return result === null || result === void 0 ? void 0 : result.data;
230
+ }
231
+ catch (error) {
232
+ if (isApiError(error)) {
233
+ throw error;
234
+ }
235
+ throw error;
236
+ }
237
+ });
238
+ }
239
+ static attachRule(id, ruleId) {
240
+ return __awaiter(this, void 0, void 0, function* () {
241
+ try {
242
+ this.logAction(`Attach rule with id: ${ruleId} to device with id: ${id}`);
243
+ const axios = EdgeIQAPI.getAxios();
244
+ yield axios.put(`${Endpoints.device}/${id}/rules/${ruleId}`);
245
+ return getAttachMessage('Rule', 'attach', 'device');
246
+ }
247
+ catch (error) {
248
+ if (isApiError(error)) {
249
+ throw error;
250
+ }
251
+ throw error;
252
+ }
253
+ });
254
+ }
255
+ static bulkAttachRules(id, rulesIds) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ try {
258
+ this.logAction(`Attaching ${rulesIds.length} rules with to device with id ${id}`);
259
+ const axios = EdgeIQAPI.getAxios();
260
+ const result = yield axios.post(`${Endpoints.device}/${id}/rules/bulk`, {
261
+ ids: rulesIds,
262
+ });
263
+ return result === null || result === void 0 ? void 0 : result.data;
264
+ }
265
+ catch (error) {
266
+ if (isApiError(error)) {
267
+ throw error;
268
+ }
269
+ throw error;
270
+ }
271
+ });
272
+ }
273
+ static detachRule(id, ruleId) {
274
+ return __awaiter(this, void 0, void 0, function* () {
275
+ try {
276
+ this.logAction(`Detach rule with id: ${ruleId} from device with id: ${id}`);
277
+ const axios = EdgeIQAPI.getAxios();
278
+ yield axios.delete(`${Endpoints.device}/${id}/rules/${ruleId}`);
279
+ return getAttachMessage('Rule', 'detach', 'device');
280
+ }
281
+ catch (error) {
282
+ if (isApiError(error)) {
283
+ throw error;
284
+ }
285
+ throw error;
286
+ }
287
+ });
288
+ }
289
+ static getRules(id) {
290
+ return __awaiter(this, void 0, void 0, function* () {
291
+ try {
292
+ this.logAction(`Getting rules attached to device with id ${id}`);
293
+ const axios = EdgeIQAPI.getAxios();
294
+ const result = yield axios.get(`${Endpoints.device}/${id}/rules`);
295
+ return result === null || result === void 0 ? void 0 : result.data;
296
+ }
297
+ catch (error) {
298
+ if (isApiError(error)) {
299
+ throw error;
300
+ }
301
+ throw error;
302
+ }
303
+ });
304
+ }
305
+ static getAwsThingGroups(id) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ try {
308
+ this.logAction(`Getting AWS thing groups for device with id: ${id}`);
309
+ const axios = EdgeIQAPI.getAxios();
310
+ const result = yield axios.get(`${Endpoints.device}/${id}/aws_thing_groups`);
311
+ return result === null || result === void 0 ? void 0 : result.data;
312
+ }
313
+ catch (error) {
314
+ if (isApiError(error)) {
315
+ throw error;
316
+ }
317
+ throw error;
318
+ }
319
+ });
320
+ }
321
+ static getCommands(id) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ try {
324
+ this.logAction(`Getting commands attached to device with id ${id}`);
325
+ const axios = EdgeIQAPI.getAxios();
326
+ const result = yield axios.get(`${Endpoints.device}/${id}/${Endpoints.command}`);
327
+ return result === null || result === void 0 ? void 0 : result.data;
328
+ }
329
+ catch (error) {
330
+ if (isApiError(error)) {
331
+ throw error;
332
+ }
333
+ throw error;
334
+ }
335
+ });
336
+ }
337
+ static csvBulkUpload(file) {
338
+ return __awaiter(this, void 0, void 0, function* () {
339
+ try {
340
+ this.logAction(`Uploading CSV file with devices`);
341
+ const axios = EdgeIQAPI.getAxios();
342
+ const form = new FormData();
343
+ form.append('gateway_csv_upload', file);
344
+ const result = yield axios.post(`${Endpoints.device}/csv_bulk_upload`, form, {
345
+ headers: {
346
+ 'Content-Type': 'multipart/form-data',
347
+ },
348
+ });
349
+ return result === null || result === void 0 ? void 0 : result.data;
350
+ }
351
+ catch (error) {
352
+ if (isApiError(error)) {
353
+ throw error;
354
+ }
355
+ throw error;
356
+ }
357
+ });
358
+ }
359
+ static csvBulkDownload(filters) {
360
+ return __awaiter(this, void 0, void 0, function* () {
361
+ try {
362
+ this.logAction(`Listing devices with following filters: ${filters !== null && filters !== void 0 ? filters : '{}'}`);
363
+ const axios = EdgeIQAPI.getAxios();
364
+ const result = yield axios.get(`${Endpoints.device}/csv_bulk_download`, {
365
+ params: parseFilters(filters, undefined, true),
366
+ });
367
+ return result === null || result === void 0 ? void 0 : result.data;
368
+ }
369
+ catch (error) {
370
+ if (isApiError(error)) {
371
+ throw error;
372
+ }
373
+ throw error;
374
+ }
375
+ });
376
+ }
377
+ static getLogs(id) {
378
+ return __awaiter(this, void 0, void 0, function* () {
379
+ try {
380
+ this.logAction(`Getting logs attached to device with id ${id}`);
381
+ const axios = EdgeIQAPI.getAxios();
382
+ const result = yield axios.get(`${Endpoints.device}/${id}/${Endpoints.logs}`);
383
+ return result === null || result === void 0 ? void 0 : result.data;
384
+ }
385
+ catch (error) {
386
+ if (isApiError(error)) {
387
+ throw error;
388
+ }
389
+ throw error;
390
+ }
391
+ });
392
+ }
393
+ static requestLogs(id) {
394
+ return __awaiter(this, void 0, void 0, function* () {
395
+ try {
396
+ this.logAction(`requesting logs for device with ${id}`);
397
+ const axios = EdgeIQAPI.getAxios();
398
+ const result = yield axios.post(`${Endpoints.device}/${id}/${Endpoints.gatewayCommand}`, {
399
+ command_type: 'log_upload',
400
+ schedule: null,
401
+ });
402
+ return result === null || result === void 0 ? void 0 : result.data;
403
+ }
404
+ catch (error) {
405
+ if (isApiError(error)) {
406
+ throw error;
407
+ }
408
+ throw error;
409
+ }
410
+ });
411
+ }
412
+ static deviceLwm2mObjetLinks(id) {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ try {
415
+ this.logAction(`Getting lwm2m object links attached to device with id ${id}`);
416
+ const axios = EdgeIQAPI.getAxios();
417
+ const result = yield axios.get(`${Endpoints.device}/${id}/${Endpoints.deviceLwm2mObjetLinks}`);
418
+ return result === null || result === void 0 ? void 0 : result.data;
419
+ }
420
+ catch (error) {
421
+ if (isApiError(error)) {
422
+ throw error;
423
+ }
424
+ throw error;
425
+ }
426
+ });
427
+ }
428
+ static processGatewayCommand(deviceId, gatewayCommandRequest) {
429
+ return __awaiter(this, void 0, void 0, function* () {
430
+ try {
431
+ this.logAction(`Process gateway command: ${gatewayCommandRequest.command_type}, on device id: ${deviceId}`);
432
+ const axios = EdgeIQAPI.getAxios();
433
+ const data = JSON.stringify(gatewayCommandRequest);
434
+ const result = yield axios.post(`${Endpoints.device}/${deviceId}/${gatewayCommandRequest.command_type}`, data);
435
+ return result === null || result === void 0 ? void 0 : result.data;
436
+ }
437
+ catch (error) {
438
+ if (isApiError(error)) {
439
+ throw error;
440
+ }
441
+ throw error;
442
+ }
443
+ });
444
+ }
445
+ static bulkExecuteGatewayCommand(ids, gatewayCommandRequest, generateChildCommandExecutions) {
446
+ return __awaiter(this, void 0, void 0, function* () {
447
+ try {
448
+ this.logAction(`Execute ${gatewayCommandRequest.command_type} command on devices with IDs: ${ids}`);
449
+ const axios = EdgeIQAPI.getAxios();
450
+ const result = yield axios.post(`${Endpoints.device}/bulk/gateway_command`, Object.assign(Object.assign({}, gatewayCommandRequest), { generate_child_command_executions: generateChildCommandExecutions !== null && generateChildCommandExecutions !== void 0 ? generateChildCommandExecutions : false, ids }));
451
+ return result === null || result === void 0 ? void 0 : result.data;
452
+ }
453
+ catch (error) {
454
+ if (isApiError(error)) {
455
+ throw error;
456
+ }
457
+ throw error;
458
+ }
459
+ });
460
+ }
461
+ static bulkExecuteCommand(commandId, ids, options, generateChildCommandExecutions) {
462
+ return __awaiter(this, void 0, void 0, function* () {
463
+ try {
464
+ this.logAction(`Execute command with ID: ${commandId} on devices with IDs: ${ids}`);
465
+ const axios = EdgeIQAPI.getAxios();
466
+ const data = {
467
+ ids,
468
+ generate_child_command_executions: generateChildCommandExecutions !== null && generateChildCommandExecutions !== void 0 ? generateChildCommandExecutions : false,
469
+ };
470
+ const result = yield axios.post(`${Endpoints.device}/bulk/commands/${commandId}/execute`, options
471
+ ? Object.assign(Object.assign({}, data), { options }) : Object.assign({}, data));
472
+ return result === null || result === void 0 ? void 0 : result.data;
473
+ }
474
+ catch (error) {
475
+ if (isApiError(error)) {
476
+ throw error;
477
+ }
478
+ throw error;
479
+ }
480
+ });
481
+ }
482
+ static getFiles(id) {
483
+ return __awaiter(this, void 0, void 0, function* () {
484
+ try {
485
+ this.logAction(`Getting files attached to device with id ${id}`);
486
+ const axios = EdgeIQAPI.getAxios();
487
+ const result = yield axios.get(`${Endpoints.device}/${id}/files`);
488
+ return result === null || result === void 0 ? void 0 : result.data;
489
+ }
490
+ catch (error) {
491
+ if (isApiError(error)) {
492
+ throw error;
493
+ }
494
+ throw error;
495
+ }
496
+ });
497
+ }
498
+ static getCommandExecutions(id, filters, pagination) {
775
499
  var _a, _b, _c, _d;
776
- return __awaiter(this, void 0, void 0, function () {
777
- var axios, result, error_28;
778
- return __generator(this, function (_e) {
779
- switch (_e.label) {
780
- case 0:
781
- _e.trys.push([0, 2, , 3]);
782
- this.logAction("Getting command executions attached to device with id " + id);
783
- axios = __1.EdgeIQAPI.getAxios();
784
- return [4, axios.get(constants_1.Endpoints.command + "/" + id + "/command_executions", {
785
- params: (0, filtersParser_1.parseFilters)(filters, pagination),
786
- })];
787
- case 1:
788
- result = _e.sent();
789
- return [2, {
790
- commandExecutions: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
791
- pagination: {
792
- page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
793
- itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
794
- total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
795
- },
796
- }];
797
- case 2:
798
- error_28 = _e.sent();
799
- if ((0, helpers_1.isApiError)(error_28)) {
800
- throw error_28;
801
- }
802
- throw error_28;
803
- case 3: return [2];
804
- }
805
- });
806
- });
807
- };
808
- class_1.startRemoteTerminal = function (id, executable) {
809
- return __awaiter(this, void 0, void 0, function () {
810
- var axios, error_29;
811
- return __generator(this, function (_a) {
812
- switch (_a.label) {
813
- case 0:
814
- _a.trys.push([0, 2, , 3]);
815
- this.logAction("Start remote terminal with device: " + id);
816
- axios = __1.EdgeIQAPI.getAxios();
817
- return [4, axios.post(constants_1.Endpoints.device + "/" + id + "/start_remote_terminal", {
818
- executable: executable !== null && executable !== void 0 ? executable : 'sh',
819
- })];
820
- case 1:
821
- _a.sent();
822
- return [2, "Remote terminal started for device: " + id];
823
- case 2:
824
- error_29 = _a.sent();
825
- if ((0, helpers_1.isApiError)(error_29)) {
826
- throw error_29;
827
- }
828
- throw error_29;
829
- case 3: return [2];
830
- }
831
- });
832
- });
833
- };
834
- class_1.stopRemoteTerminal = function (id) {
835
- return __awaiter(this, void 0, void 0, function () {
836
- var axios, error_30;
837
- return __generator(this, function (_a) {
838
- switch (_a.label) {
839
- case 0:
840
- _a.trys.push([0, 2, , 3]);
841
- this.logAction("Stops remote terminal with device: " + id);
842
- axios = __1.EdgeIQAPI.getAxios();
843
- return [4, axios.post(constants_1.Endpoints.device + "/" + id + "/stop_remote_terminal")];
844
- case 1:
845
- _a.sent();
846
- return [2, "Remote terminal stoped for device: " + id];
847
- case 2:
848
- error_30 = _a.sent();
849
- if ((0, helpers_1.isApiError)(error_30)) {
850
- throw error_30;
851
- }
852
- throw error_30;
853
- case 3: return [2];
854
- }
855
- });
856
- });
857
- };
858
- class_1.getSettings = function (id, configId) {
859
- return __awaiter(this, void 0, void 0, function () {
860
- var axios, result, error_31;
861
- return __generator(this, function (_a) {
862
- switch (_a.label) {
863
- case 0:
864
- _a.trys.push([0, 2, , 3]);
865
- this.logAction("Getting settings attached to device with id " + id);
866
- axios = __1.EdgeIQAPI.getAxios();
867
- return [4, axios.get(constants_1.Endpoints.device + "/" + id + "/" + constants_1.Endpoints.setting + (configId ? "?configuration_id=" + configId : ''))];
868
- case 1:
869
- result = _a.sent();
870
- return [2, result === null || result === void 0 ? void 0 : result.data];
871
- case 2:
872
- error_31 = _a.sent();
873
- if ((0, helpers_1.isApiError)(error_31)) {
874
- throw error_31;
875
- }
876
- throw error_31;
877
- case 3: return [2];
878
- }
879
- });
880
- });
881
- };
882
- class_1.attachSettings = function (id, sttingsId) {
883
- return __awaiter(this, void 0, void 0, function () {
884
- var axios, error_32;
885
- return __generator(this, function (_a) {
886
- switch (_a.label) {
887
- case 0:
888
- _a.trys.push([0, 2, , 3]);
889
- this.logAction("Attach settings with id: " + sttingsId + " to device with id: " + id);
890
- axios = __1.EdgeIQAPI.getAxios();
891
- return [4, axios.put(constants_1.Endpoints.device + "/" + id + "/settings/" + sttingsId)];
892
- case 1:
893
- _a.sent();
894
- return [2, (0, constants_1.getAttachMessage)('Settings', 'attach', 'device')];
895
- case 2:
896
- error_32 = _a.sent();
897
- if ((0, helpers_1.isApiError)(error_32)) {
898
- throw error_32;
899
- }
900
- throw error_32;
901
- case 3: return [2];
902
- }
903
- });
904
- });
905
- };
906
- class_1.detachSettings = function (id, sttingsId) {
907
- return __awaiter(this, void 0, void 0, function () {
908
- var axios, error_33;
909
- return __generator(this, function (_a) {
910
- switch (_a.label) {
911
- case 0:
912
- _a.trys.push([0, 2, , 3]);
913
- this.logAction("Detach settings with id: " + sttingsId + " from device with id: " + id);
914
- axios = __1.EdgeIQAPI.getAxios();
915
- return [4, axios.delete(constants_1.Endpoints.device + "/" + id + "/settings/" + sttingsId)];
916
- case 1:
917
- _a.sent();
918
- return [2, (0, constants_1.getAttachMessage)('Settings', 'detach', 'device')];
919
- case 2:
920
- error_33 = _a.sent();
921
- if ((0, helpers_1.isApiError)(error_33)) {
922
- throw error_33;
923
- }
924
- throw error_33;
925
- case 3: return [2];
926
- }
927
- });
928
- });
929
- };
930
- class_1.dryRunCommand = function (id, commandId, data) {
931
- return __awaiter(this, void 0, void 0, function () {
932
- var axios, result, error_34;
933
- return __generator(this, function (_a) {
934
- switch (_a.label) {
935
- case 0:
936
- _a.trys.push([0, 2, , 3]);
937
- this.logAction("Dry run command " + commandId + " on device " + id);
938
- axios = __1.EdgeIQAPI.getAxios();
939
- return [4, axios.post(constants_1.Endpoints.device + "/" + id + "/commands/" + commandId + "/dry-run", data)];
940
- case 1:
941
- result = _a.sent();
942
- return [2, result === null || result === void 0 ? void 0 : result.data];
943
- case 2:
944
- error_34 = _a.sent();
945
- if ((0, helpers_1.isApiError)(error_34)) {
946
- throw error_34;
947
- }
948
- throw error_34;
949
- case 3: return [2];
950
- }
951
- });
952
- });
953
- };
954
- class_1.bulkExecuteWorkflow = function (workflowId, ids) {
955
- return __awaiter(this, void 0, void 0, function () {
956
- var axios, data, result, error_35;
957
- return __generator(this, function (_a) {
958
- switch (_a.label) {
959
- case 0:
960
- _a.trys.push([0, 2, , 3]);
961
- this.logAction("Execute workflow with ID: " + workflowId + " on devices with IDs: " + ids);
962
- axios = __1.EdgeIQAPI.getAxios();
963
- data = {
964
- ids: ids,
965
- definition_id: workflowId,
966
- };
967
- return [4, axios.post(constants_1.Endpoints.device + "/bulk_workflow", __assign({}, data))];
968
- case 1:
969
- result = _a.sent();
970
- return [2, result === null || result === void 0 ? void 0 : result.data];
971
- case 2:
972
- error_35 = _a.sent();
973
- if ((0, helpers_1.isApiError)(error_35)) {
974
- throw error_35;
975
- }
976
- throw error_35;
977
- case 3: return [2];
978
- }
979
- });
980
- });
981
- };
982
- return class_1;
983
- }(ModelClass_1.BaseModelClass));
500
+ return __awaiter(this, void 0, void 0, function* () {
501
+ try {
502
+ this.logAction(`Getting command executions attached to device with id ${id}`);
503
+ const axios = EdgeIQAPI.getAxios();
504
+ const result = yield axios.get(`${Endpoints.command}/${id}/command_executions`, {
505
+ params: parseFilters(filters, pagination),
506
+ });
507
+ return {
508
+ commandExecutions: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
509
+ pagination: {
510
+ page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
511
+ itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
512
+ total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
513
+ },
514
+ };
515
+ }
516
+ catch (error) {
517
+ if (isApiError(error)) {
518
+ throw error;
519
+ }
520
+ throw error;
521
+ }
522
+ });
523
+ }
524
+ static startRemoteTerminal(id, executable) {
525
+ return __awaiter(this, void 0, void 0, function* () {
526
+ try {
527
+ this.logAction(`Start remote terminal with device: ${id}`);
528
+ const axios = EdgeIQAPI.getAxios();
529
+ yield axios.post(`${Endpoints.device}/${id}/start_remote_terminal`, {
530
+ executable: executable !== null && executable !== void 0 ? executable : 'sh',
531
+ });
532
+ return `Remote terminal started for device: ${id}`;
533
+ }
534
+ catch (error) {
535
+ if (isApiError(error)) {
536
+ throw error;
537
+ }
538
+ throw error;
539
+ }
540
+ });
541
+ }
542
+ static stopRemoteTerminal(id) {
543
+ return __awaiter(this, void 0, void 0, function* () {
544
+ try {
545
+ this.logAction(`Stops remote terminal with device: ${id}`);
546
+ const axios = EdgeIQAPI.getAxios();
547
+ yield axios.post(`${Endpoints.device}/${id}/stop_remote_terminal`);
548
+ return `Remote terminal stoped for device: ${id}`;
549
+ }
550
+ catch (error) {
551
+ if (isApiError(error)) {
552
+ throw error;
553
+ }
554
+ throw error;
555
+ }
556
+ });
557
+ }
558
+ static getSettings(id, configId) {
559
+ return __awaiter(this, void 0, void 0, function* () {
560
+ try {
561
+ this.logAction(`Getting settings attached to device with id ${id}`);
562
+ const axios = EdgeIQAPI.getAxios();
563
+ const result = yield axios.get(`${Endpoints.device}/${id}/${Endpoints.setting}${configId ? `?configuration_id=${configId}` : ''}`);
564
+ return result === null || result === void 0 ? void 0 : result.data;
565
+ }
566
+ catch (error) {
567
+ if (isApiError(error)) {
568
+ throw error;
569
+ }
570
+ throw error;
571
+ }
572
+ });
573
+ }
574
+ static attachSettings(id, sttingsId) {
575
+ return __awaiter(this, void 0, void 0, function* () {
576
+ try {
577
+ this.logAction(`Attach settings with id: ${sttingsId} to device with id: ${id}`);
578
+ const axios = EdgeIQAPI.getAxios();
579
+ yield axios.put(`${Endpoints.device}/${id}/settings/${sttingsId}`);
580
+ return getAttachMessage('Settings', 'attach', 'device');
581
+ }
582
+ catch (error) {
583
+ if (isApiError(error)) {
584
+ throw error;
585
+ }
586
+ throw error;
587
+ }
588
+ });
589
+ }
590
+ static detachSettings(id, sttingsId) {
591
+ return __awaiter(this, void 0, void 0, function* () {
592
+ try {
593
+ this.logAction(`Detach settings with id: ${sttingsId} from device with id: ${id}`);
594
+ const axios = EdgeIQAPI.getAxios();
595
+ yield axios.delete(`${Endpoints.device}/${id}/settings/${sttingsId}`);
596
+ return getAttachMessage('Settings', 'detach', 'device');
597
+ }
598
+ catch (error) {
599
+ if (isApiError(error)) {
600
+ throw error;
601
+ }
602
+ throw error;
603
+ }
604
+ });
605
+ }
606
+ static dryRunCommand(id, commandId, data) {
607
+ return __awaiter(this, void 0, void 0, function* () {
608
+ try {
609
+ this.logAction(`Dry run command ${commandId} on device ${id}`);
610
+ const axios = EdgeIQAPI.getAxios();
611
+ const result = yield axios.post(`${Endpoints.device}/${id}/commands/${commandId}/dry-run`, data);
612
+ return result === null || result === void 0 ? void 0 : result.data;
613
+ }
614
+ catch (error) {
615
+ if (isApiError(error)) {
616
+ throw error;
617
+ }
618
+ throw error;
619
+ }
620
+ });
621
+ }
622
+ static bulkExecuteWorkflow(workflowId, ids) {
623
+ return __awaiter(this, void 0, void 0, function* () {
624
+ try {
625
+ this.logAction(`Execute workflow with ID: ${workflowId} on devices with IDs: ${ids}`);
626
+ const axios = EdgeIQAPI.getAxios();
627
+ const data = {
628
+ ids,
629
+ definition_id: workflowId,
630
+ };
631
+ const result = yield axios.post(`${Endpoints.device}/bulk_workflow`, Object.assign({}, data));
632
+ return result === null || result === void 0 ? void 0 : result.data;
633
+ }
634
+ catch (error) {
635
+ if (isApiError(error)) {
636
+ throw error;
637
+ }
638
+ throw error;
639
+ }
640
+ });
641
+ }
642
+ };