@edgeiq/edgeiq-api-js 1.2.3 → 1.2.4

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 (172) hide show
  1. package/README.md +55 -55
  2. package/dist/__tests__/auth.test.d.ts +1 -1
  3. package/dist/__tests__/auth.test.js +143 -143
  4. package/dist/__tests__/command.test.d.ts +1 -0
  5. package/dist/__tests__/command.test.js +201 -0
  6. package/dist/__tests__/companies.test.d.ts +1 -1
  7. package/dist/__tests__/companies.test.js +196 -196
  8. package/dist/__tests__/deviceErrors.test.d.ts +1 -0
  9. package/dist/__tests__/deviceErrors.test.js +72 -0
  10. package/dist/__tests__/deviceTypes.test.d.ts +1 -1
  11. package/dist/__tests__/deviceTypes.test.js +172 -172
  12. package/dist/__tests__/devices.test.d.ts +1 -1
  13. package/dist/__tests__/devices.test.js +204 -204
  14. package/dist/__tests__/discoveredDevice.test.d.ts +1 -1
  15. package/dist/__tests__/discoveredDevice.test.js +126 -126
  16. package/dist/__tests__/ingestors.test.d.ts +1 -1
  17. package/dist/__tests__/ingestors.test.js +172 -172
  18. package/dist/__tests__/integrations.test.d.ts +1 -1
  19. package/dist/__tests__/integrations.test.js +192 -192
  20. package/dist/__tests__/notifications.test.d.ts +1 -1
  21. package/dist/__tests__/notifications.test.js +72 -72
  22. package/dist/__tests__/pollableAttributes.test.d.ts +1 -1
  23. package/dist/__tests__/pollableAttributes.test.js +172 -172
  24. package/dist/__tests__/rules.test.d.ts +1 -1
  25. package/dist/__tests__/rules.test.js +172 -172
  26. package/dist/__tests__/testConstants.d.ts +7 -0
  27. package/dist/__tests__/testConstants.js +14 -0
  28. package/dist/__tests__/translators.test.d.ts +1 -1
  29. package/dist/__tests__/translators.test.js +172 -172
  30. package/dist/__tests__/users.test.d.ts +1 -1
  31. package/dist/__tests__/users.test.js +208 -208
  32. package/dist/auth/index.d.ts +8 -8
  33. package/dist/auth/index.js +158 -158
  34. package/dist/bulkResponses/index.d.ts +8 -8
  35. package/dist/bulkResponses/index.js +124 -124
  36. package/dist/bulkResponses/models.d.ts +43 -43
  37. package/dist/bulkResponses/models.js +2 -2
  38. package/dist/commands/index.d.ts +13 -9
  39. package/dist/commands/index.js +344 -224
  40. package/dist/commands/models.d.ts +38 -28
  41. package/dist/commands/models.js +15 -2
  42. package/dist/companies/index.d.ts +7 -7
  43. package/dist/companies/index.js +198 -198
  44. package/dist/companies/models.d.ts +94 -94
  45. package/dist/companies/models.js +2 -2
  46. package/dist/constants.d.ts +135 -132
  47. package/dist/constants.js +151 -148
  48. package/dist/core/ModelClass.d.ts +13 -13
  49. package/dist/core/ModelClass.js +19 -19
  50. package/dist/core/handleResponseError.d.ts +2 -2
  51. package/dist/core/handleResponseError.js +167 -167
  52. package/dist/core/index.d.ts +19 -19
  53. package/dist/core/index.js +63 -63
  54. package/dist/deviceConfigs/index.d.ts +9 -9
  55. package/dist/deviceConfigs/index.js +224 -224
  56. package/dist/deviceConfigs/models.d.ts +38 -38
  57. package/dist/deviceConfigs/models.js +2 -2
  58. package/dist/deviceErrors/index.d.ts +8 -0
  59. package/dist/deviceErrors/index.js +124 -0
  60. package/dist/deviceErrors/models.d.ts +19 -0
  61. package/dist/deviceErrors/models.js +2 -0
  62. package/dist/deviceLocationObservations/index.d.ts +5 -5
  63. package/dist/deviceLocationObservations/index.js +189 -189
  64. package/dist/deviceLocationObservations/models.d.ts +26 -26
  65. package/dist/deviceLocationObservations/models.js +2 -2
  66. package/dist/deviceTemplates/index.d.ts +9 -9
  67. package/dist/deviceTemplates/index.js +226 -226
  68. package/dist/deviceTemplates/models.d.ts +36 -36
  69. package/dist/deviceTemplates/models.js +2 -2
  70. package/dist/deviceTransferRequests/index.d.ts +7 -7
  71. package/dist/deviceTransferRequests/index.js +198 -198
  72. package/dist/deviceTransferRequests/models.d.ts +26 -26
  73. package/dist/deviceTransferRequests/models.js +2 -2
  74. package/dist/deviceTypes/index.d.ts +20 -19
  75. package/dist/deviceTypes/index.js +464 -440
  76. package/dist/deviceTypes/models.d.ts +104 -104
  77. package/dist/deviceTypes/models.js +2 -2
  78. package/dist/devices/index.d.ts +21 -20
  79. package/dist/devices/index.js +511 -487
  80. package/dist/devices/models.d.ts +114 -114
  81. package/dist/devices/models.js +2 -2
  82. package/dist/discoveredDevices/index.d.ts +14 -14
  83. package/dist/discoveredDevices/index.js +335 -335
  84. package/dist/discoveredDevices/models.d.ts +41 -41
  85. package/dist/discoveredDevices/models.js +2 -2
  86. package/dist/downstreamSystems/index.d.ts +7 -7
  87. package/dist/downstreamSystems/index.js +198 -198
  88. package/dist/downstreamSystems/models.d.ts +17 -17
  89. package/dist/downstreamSystems/models.js +2 -2
  90. package/dist/escrowDevices/index.d.ts +9 -9
  91. package/dist/escrowDevices/index.js +224 -224
  92. package/dist/escrowDevices/models.d.ts +21 -21
  93. package/dist/escrowDevices/models.js +2 -2
  94. package/dist/example/index.d.ts +1 -0
  95. package/dist/example/index.js +5 -0
  96. package/dist/filtersParser.d.ts +5 -5
  97. package/dist/filtersParser.js +52 -52
  98. package/dist/gatewayCommands/index.d.ts +10 -10
  99. package/dist/gatewayCommands/index.js +261 -261
  100. package/dist/gatewayCommands/models.d.ts +41 -41
  101. package/dist/gatewayCommands/models.js +2 -2
  102. package/dist/helpers.d.ts +3 -3
  103. package/dist/helpers.js +11 -11
  104. package/dist/index.d.ts +60 -58
  105. package/dist/index.js +104 -101
  106. package/dist/ingestors/index.d.ts +9 -9
  107. package/dist/ingestors/index.js +224 -224
  108. package/dist/ingestors/models.d.ts +37 -37
  109. package/dist/ingestors/models.js +2 -2
  110. package/dist/integrations/index.d.ts +9 -9
  111. package/dist/integrations/index.js +306 -306
  112. package/dist/integrations/models.d.ts +61 -61
  113. package/dist/integrations/models.js +2 -2
  114. package/dist/models/index.d.ts +1893 -1893
  115. package/dist/models/index.js +2 -2
  116. package/dist/models.d.ts +67 -67
  117. package/dist/models.js +2 -2
  118. package/dist/notifications/index.d.ts +8 -8
  119. package/dist/notifications/index.js +124 -124
  120. package/dist/notifications/models.d.ts +19 -19
  121. package/dist/notifications/models.js +2 -2
  122. package/dist/pollableAttributes/index.d.ts +7 -7
  123. package/dist/pollableAttributes/index.js +198 -198
  124. package/dist/pollableAttributes/models.d.ts +28 -28
  125. package/dist/pollableAttributes/models.js +2 -2
  126. package/dist/regions/index.d.ts +5 -5
  127. package/dist/regions/index.js +173 -173
  128. package/dist/regions/models.d.ts +17 -17
  129. package/dist/regions/models.js +2 -2
  130. package/dist/reports/index.d.ts +8 -8
  131. package/dist/reports/index.js +199 -199
  132. package/dist/reports/models.d.ts +25 -25
  133. package/dist/reports/models.js +2 -2
  134. package/dist/rules/index.d.ts +9 -9
  135. package/dist/rules/index.js +224 -224
  136. package/dist/rules/models.d.ts +108 -108
  137. package/dist/rules/models.js +2 -2
  138. package/dist/secrets/index.d.ts +5 -5
  139. package/dist/secrets/index.js +173 -173
  140. package/dist/secrets/models.d.ts +16 -16
  141. package/dist/secrets/models.js +2 -2
  142. package/dist/softwareUpdates/index.d.ts +9 -9
  143. package/dist/softwareUpdates/index.js +224 -224
  144. package/dist/softwareUpdates/models.d.ts +22 -22
  145. package/dist/softwareUpdates/models.js +2 -2
  146. package/dist/stats/index.d.ts +9 -8
  147. package/dist/stats/index.js +140 -116
  148. package/dist/stats/models.d.ts +27 -27
  149. package/dist/stats/models.js +2 -2
  150. package/dist/systemCommandJobs/index.d.ts +5 -5
  151. package/dist/systemCommandJobs/index.js +173 -173
  152. package/dist/systemCommandJobs/models.d.ts +32 -32
  153. package/dist/systemCommandJobs/models.js +2 -2
  154. package/dist/systemCommands/index.d.ts +7 -7
  155. package/dist/systemCommands/index.js +198 -198
  156. package/dist/systemCommands/models.d.ts +32 -32
  157. package/dist/systemCommands/models.js +2 -2
  158. package/dist/testConstants.d.ts +47 -46
  159. package/dist/testConstants.js +229 -221
  160. package/dist/translators/index.d.ts +9 -9
  161. package/dist/translators/index.js +224 -224
  162. package/dist/translators/models.d.ts +21 -21
  163. package/dist/translators/models.js +2 -2
  164. package/dist/userTypes/index.d.ts +7 -7
  165. package/dist/userTypes/index.js +198 -198
  166. package/dist/userTypes/models.d.ts +79 -79
  167. package/dist/userTypes/models.js +2 -2
  168. package/dist/users/index.d.ts +12 -12
  169. package/dist/users/index.js +300 -300
  170. package/dist/users/models.d.ts +41 -41
  171. package/dist/users/models.js +2 -2
  172. package/package.json +56 -56
@@ -1,306 +1,306 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- 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;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.Integrations = void 0;
55
- var __1 = require("..");
56
- var constants_1 = require("../constants");
57
- var ModelClass_1 = require("../core/ModelClass");
58
- var filtersParser_1 = require("../filtersParser");
59
- var helpers_1 = require("../helpers");
60
- var unEditableIntegrationTypes = [
61
- 'aws_device_integrations',
62
- 'azure_device_integrations',
63
- ];
64
- exports.Integrations = (function (_super) {
65
- __extends(class_1, _super);
66
- function class_1() {
67
- return _super !== null && _super.apply(this, arguments) || this;
68
- }
69
- class_1.create = function (integration) {
70
- return __awaiter(this, void 0, void 0, function () {
71
- var requiredValues, axios, data, result, error_1;
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0:
75
- _a.trys.push([0, 2, , 3]);
76
- this.logAction("Creating integration with name: " + integration.name);
77
- requiredValues = checkRequiredValuesByType(integration);
78
- if (requiredValues.length !== 0) {
79
- return [2, Promise.reject({
80
- name: constants_1.ResponseErrorsNames.integrationMissinValues,
81
- message: constants_1.ResponseErrorsMessages.integrationMissinValues(integration.type, requiredValues),
82
- })];
83
- }
84
- axios = __1.EdgeIQAPI.getAxios();
85
- data = JSON.stringify(integration);
86
- return [4, axios.post(constants_1.Endpoints.integration, 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.update = function (integration) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var axios, data, 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("Updating integration with unique ID: " + integration._id);
109
- if (unEditableIntegrationTypes.includes(integration.type)) {
110
- return [2, Promise.reject({
111
- name: constants_1.ResponseErrorsNames.unEditableIntegration,
112
- message: constants_1.ResponseErrorsMessages.unEditableIntegration(integration.type),
113
- })];
114
- }
115
- axios = __1.EdgeIQAPI.getAxios();
116
- data = JSON.stringify(integration);
117
- return [4, axios.put(constants_1.Endpoints.integration + "/" + integration._id, data)];
118
- case 1:
119
- result = _a.sent();
120
- return [2, result === null || result === void 0 ? void 0 : result.data];
121
- case 2:
122
- error_2 = _a.sent();
123
- if ((0, helpers_1.isApiError)(error_2)) {
124
- throw error_2;
125
- }
126
- throw error_2;
127
- case 3: return [2];
128
- }
129
- });
130
- });
131
- };
132
- class_1.list = function (filters, pagination) {
133
- var _a, _b, _c, _d;
134
- return __awaiter(this, void 0, void 0, function () {
135
- var axios, result, error_3;
136
- return __generator(this, function (_e) {
137
- switch (_e.label) {
138
- case 0:
139
- _e.trys.push([0, 2, , 3]);
140
- this.logAction("Listing integrations with following filters: " + (filters !== null && filters !== void 0 ? filters : '{}') + ".\n And pagination " + (pagination !== null && pagination !== void 0 ? pagination : '{}'));
141
- axios = __1.EdgeIQAPI.getAxios();
142
- return [4, axios.get(constants_1.Endpoints.integration, {
143
- params: (0, filtersParser_1.parseFilters)(filters, pagination),
144
- })];
145
- case 1:
146
- result = _e.sent();
147
- return [2, {
148
- integrations: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
149
- pagination: {
150
- page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
151
- itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
152
- total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
153
- },
154
- }];
155
- case 2:
156
- error_3 = _e.sent();
157
- if ((0, helpers_1.isApiError)(error_3)) {
158
- throw error_3;
159
- }
160
- throw error_3;
161
- case 3: return [2];
162
- }
163
- });
164
- });
165
- };
166
- class_1.getOneById = function (id) {
167
- return __awaiter(this, void 0, void 0, function () {
168
- var axios, result, error_4;
169
- return __generator(this, function (_a) {
170
- switch (_a.label) {
171
- case 0:
172
- _a.trys.push([0, 2, , 3]);
173
- this.logAction("Getting integration with id: " + id);
174
- axios = __1.EdgeIQAPI.getAxios();
175
- return [4, axios.get(constants_1.Endpoints.integration + "/" + id)];
176
- case 1:
177
- result = _a.sent();
178
- return [2, result === null || result === void 0 ? void 0 : result.data];
179
- case 2:
180
- error_4 = _a.sent();
181
- if ((0, helpers_1.isApiError)(error_4)) {
182
- throw error_4;
183
- }
184
- throw error_4;
185
- case 3: return [2];
186
- }
187
- });
188
- });
189
- };
190
- class_1.delete = function (id) {
191
- return __awaiter(this, void 0, void 0, function () {
192
- var axios, error_5;
193
- return __generator(this, function (_a) {
194
- switch (_a.label) {
195
- case 0:
196
- _a.trys.push([0, 2, , 3]);
197
- this.logAction("Deleting integration with id " + id);
198
- axios = __1.EdgeIQAPI.getAxios();
199
- return [4, axios.delete(constants_1.Endpoints.integration + "/" + id)];
200
- case 1:
201
- _a.sent();
202
- return [2, (0, helpers_1.getReturnDeleteMessage)('integration')];
203
- case 2:
204
- error_5 = _a.sent();
205
- if ((0, helpers_1.isApiError)(error_5)) {
206
- throw error_5;
207
- }
208
- throw error_5;
209
- case 3: return [2];
210
- }
211
- });
212
- });
213
- };
214
- class_1.deleteMultiple = function (ids) {
215
- return __awaiter(this, void 0, void 0, function () {
216
- var axios, result, error_6;
217
- return __generator(this, function (_a) {
218
- switch (_a.label) {
219
- case 0:
220
- _a.trys.push([0, 2, , 3]);
221
- this.logAction("Deleting integrations with ids " + ids.join(', '));
222
- axios = __1.EdgeIQAPI.getAxios();
223
- return [4, axios.delete(constants_1.Endpoints.integration + "/bulk", {
224
- data: { ids: ids },
225
- })];
226
- case 1:
227
- result = _a.sent();
228
- return [2, result === null || result === void 0 ? void 0 : result.data];
229
- case 2:
230
- error_6 = _a.sent();
231
- if ((0, helpers_1.isApiError)(error_6)) {
232
- throw error_6;
233
- }
234
- throw error_6;
235
- case 3: return [2];
236
- }
237
- });
238
- });
239
- };
240
- return class_1;
241
- }(ModelClass_1.BaseModelClass));
242
- var checkRequiredValuesByType = function (integraion) {
243
- var missingValues = [];
244
- if (integraion.type === 'aws_device_integrations') {
245
- missingValues = getRequiredValues(integraion, [
246
- 'region',
247
- 'external_id',
248
- 'role_arn',
249
- ]);
250
- }
251
- if (integraion.type === 'azure_device_integrations') {
252
- missingValues = getRequiredValues(integraion, [
253
- 'iot_hub_hostname',
254
- 'shared_access_key',
255
- 'access_policy_name',
256
- ]);
257
- }
258
- if (integraion.type === 'gcp_cloud_native_device_integrations') {
259
- missingValues = getRequiredValues(integraion, [
260
- 'gcp_project_id',
261
- 'gcp_service_account_key_secret_id',
262
- ]);
263
- }
264
- if (integraion.type === 'inmarsat_cloud_native_device_integrations') {
265
- missingValues = getRequiredValues(integraion, [
266
- 'inmarsat_client_id',
267
- 'inmarsat_secret',
268
- 'inmarsat_username',
269
- 'inmarsat_password',
270
- 'inmarsat_customer_id',
271
- 'inmarsat_scap_id',
272
- 'inmarsat_industry_code',
273
- 'inmarsat_mailbox_id',
274
- ]);
275
- }
276
- if (integraion.type === 'orbcomm_cloud_native_device_integrations') {
277
- missingValues = getRequiredValues(integraion, [
278
- 'orbcomm_username',
279
- 'orbcomm_password',
280
- 'orbcomm_solution_provider_id',
281
- 'orbcomm_gateway_account_id',
282
- ]);
283
- }
284
- if (integraion.type === 'postmark_rule_action_integrations') {
285
- missingValues = getRequiredValues(integraion, ['token']);
286
- }
287
- if (integraion.type === 'smtp_rule_action_integrations') {
288
- missingValues = getRequiredValues(integraion, [
289
- 'server',
290
- 'username',
291
- 'password',
292
- ]);
293
- }
294
- if (integraion.type === 'twilio_rule_action_integrations') {
295
- missingValues = getRequiredValues(integraion, ['sid', 'token', 'from']);
296
- }
297
- return missingValues;
298
- };
299
- var getRequiredValues = function (integraion, requiredValues) {
300
- return requiredValues.filter(function (value) {
301
- if (!integraion[value]) {
302
- return true;
303
- }
304
- return false;
305
- });
306
- };
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.Integrations = void 0;
55
+ var __1 = require("..");
56
+ var constants_1 = require("../constants");
57
+ var ModelClass_1 = require("../core/ModelClass");
58
+ var filtersParser_1 = require("../filtersParser");
59
+ var helpers_1 = require("../helpers");
60
+ var unEditableIntegrationTypes = [
61
+ 'aws_device_integrations',
62
+ 'azure_device_integrations',
63
+ ];
64
+ exports.Integrations = (function (_super) {
65
+ __extends(class_1, _super);
66
+ function class_1() {
67
+ return _super !== null && _super.apply(this, arguments) || this;
68
+ }
69
+ class_1.create = function (integration) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var requiredValues, axios, data, result, error_1;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ _a.trys.push([0, 2, , 3]);
76
+ this.logAction("Creating integration with name: " + integration.name);
77
+ requiredValues = checkRequiredValuesByType(integration);
78
+ if (requiredValues.length !== 0) {
79
+ return [2, Promise.reject({
80
+ name: constants_1.ResponseErrorsNames.integrationMissinValues,
81
+ message: constants_1.ResponseErrorsMessages.integrationMissinValues(integration.type, requiredValues),
82
+ })];
83
+ }
84
+ axios = __1.EdgeIQAPI.getAxios();
85
+ data = JSON.stringify(integration);
86
+ return [4, axios.post(constants_1.Endpoints.integration, 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.update = function (integration) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var axios, data, 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("Updating integration with unique ID: " + integration._id);
109
+ if (unEditableIntegrationTypes.includes(integration.type)) {
110
+ return [2, Promise.reject({
111
+ name: constants_1.ResponseErrorsNames.unEditableIntegration,
112
+ message: constants_1.ResponseErrorsMessages.unEditableIntegration(integration.type),
113
+ })];
114
+ }
115
+ axios = __1.EdgeIQAPI.getAxios();
116
+ data = JSON.stringify(integration);
117
+ return [4, axios.put(constants_1.Endpoints.integration + "/" + integration._id, data)];
118
+ case 1:
119
+ result = _a.sent();
120
+ return [2, result === null || result === void 0 ? void 0 : result.data];
121
+ case 2:
122
+ error_2 = _a.sent();
123
+ if ((0, helpers_1.isApiError)(error_2)) {
124
+ throw error_2;
125
+ }
126
+ throw error_2;
127
+ case 3: return [2];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ class_1.list = function (filters, pagination) {
133
+ var _a, _b, _c, _d;
134
+ return __awaiter(this, void 0, void 0, function () {
135
+ var axios, result, error_3;
136
+ return __generator(this, function (_e) {
137
+ switch (_e.label) {
138
+ case 0:
139
+ _e.trys.push([0, 2, , 3]);
140
+ this.logAction("Listing integrations with following filters: " + (filters !== null && filters !== void 0 ? filters : '{}') + ".\n And pagination " + (pagination !== null && pagination !== void 0 ? pagination : '{}'));
141
+ axios = __1.EdgeIQAPI.getAxios();
142
+ return [4, axios.get(constants_1.Endpoints.integration, {
143
+ params: (0, filtersParser_1.parseFilters)(filters, pagination),
144
+ })];
145
+ case 1:
146
+ result = _e.sent();
147
+ return [2, {
148
+ integrations: (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.resources,
149
+ pagination: {
150
+ page: (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.page,
151
+ itemsPerPage: (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.per_page,
152
+ total: (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.total,
153
+ },
154
+ }];
155
+ case 2:
156
+ error_3 = _e.sent();
157
+ if ((0, helpers_1.isApiError)(error_3)) {
158
+ throw error_3;
159
+ }
160
+ throw error_3;
161
+ case 3: return [2];
162
+ }
163
+ });
164
+ });
165
+ };
166
+ class_1.getOneById = function (id) {
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var axios, result, error_4;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ _a.trys.push([0, 2, , 3]);
173
+ this.logAction("Getting integration with id: " + id);
174
+ axios = __1.EdgeIQAPI.getAxios();
175
+ return [4, axios.get(constants_1.Endpoints.integration + "/" + id)];
176
+ case 1:
177
+ result = _a.sent();
178
+ return [2, result === null || result === void 0 ? void 0 : result.data];
179
+ case 2:
180
+ error_4 = _a.sent();
181
+ if ((0, helpers_1.isApiError)(error_4)) {
182
+ throw error_4;
183
+ }
184
+ throw error_4;
185
+ case 3: return [2];
186
+ }
187
+ });
188
+ });
189
+ };
190
+ class_1.delete = function (id) {
191
+ return __awaiter(this, void 0, void 0, function () {
192
+ var axios, error_5;
193
+ return __generator(this, function (_a) {
194
+ switch (_a.label) {
195
+ case 0:
196
+ _a.trys.push([0, 2, , 3]);
197
+ this.logAction("Deleting integration with id " + id);
198
+ axios = __1.EdgeIQAPI.getAxios();
199
+ return [4, axios.delete(constants_1.Endpoints.integration + "/" + id)];
200
+ case 1:
201
+ _a.sent();
202
+ return [2, (0, helpers_1.getReturnDeleteMessage)('integration')];
203
+ case 2:
204
+ error_5 = _a.sent();
205
+ if ((0, helpers_1.isApiError)(error_5)) {
206
+ throw error_5;
207
+ }
208
+ throw error_5;
209
+ case 3: return [2];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ class_1.deleteMultiple = function (ids) {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ var axios, result, error_6;
217
+ return __generator(this, function (_a) {
218
+ switch (_a.label) {
219
+ case 0:
220
+ _a.trys.push([0, 2, , 3]);
221
+ this.logAction("Deleting integrations with ids " + ids.join(', '));
222
+ axios = __1.EdgeIQAPI.getAxios();
223
+ return [4, axios.delete(constants_1.Endpoints.integration + "/bulk", {
224
+ data: { ids: ids },
225
+ })];
226
+ case 1:
227
+ result = _a.sent();
228
+ return [2, result === null || result === void 0 ? void 0 : result.data];
229
+ case 2:
230
+ error_6 = _a.sent();
231
+ if ((0, helpers_1.isApiError)(error_6)) {
232
+ throw error_6;
233
+ }
234
+ throw error_6;
235
+ case 3: return [2];
236
+ }
237
+ });
238
+ });
239
+ };
240
+ return class_1;
241
+ }(ModelClass_1.BaseModelClass));
242
+ var checkRequiredValuesByType = function (integraion) {
243
+ var missingValues = [];
244
+ if (integraion.type === 'aws_device_integrations') {
245
+ missingValues = getRequiredValues(integraion, [
246
+ 'region',
247
+ 'external_id',
248
+ 'role_arn',
249
+ ]);
250
+ }
251
+ if (integraion.type === 'azure_device_integrations') {
252
+ missingValues = getRequiredValues(integraion, [
253
+ 'iot_hub_hostname',
254
+ 'shared_access_key',
255
+ 'access_policy_name',
256
+ ]);
257
+ }
258
+ if (integraion.type === 'gcp_cloud_native_device_integrations') {
259
+ missingValues = getRequiredValues(integraion, [
260
+ 'gcp_project_id',
261
+ 'gcp_service_account_key_secret_id',
262
+ ]);
263
+ }
264
+ if (integraion.type === 'inmarsat_cloud_native_device_integrations') {
265
+ missingValues = getRequiredValues(integraion, [
266
+ 'inmarsat_client_id',
267
+ 'inmarsat_secret',
268
+ 'inmarsat_username',
269
+ 'inmarsat_password',
270
+ 'inmarsat_customer_id',
271
+ 'inmarsat_scap_id',
272
+ 'inmarsat_industry_code',
273
+ 'inmarsat_mailbox_id',
274
+ ]);
275
+ }
276
+ if (integraion.type === 'orbcomm_cloud_native_device_integrations') {
277
+ missingValues = getRequiredValues(integraion, [
278
+ 'orbcomm_username',
279
+ 'orbcomm_password',
280
+ 'orbcomm_solution_provider_id',
281
+ 'orbcomm_gateway_account_id',
282
+ ]);
283
+ }
284
+ if (integraion.type === 'postmark_rule_action_integrations') {
285
+ missingValues = getRequiredValues(integraion, ['token']);
286
+ }
287
+ if (integraion.type === 'smtp_rule_action_integrations') {
288
+ missingValues = getRequiredValues(integraion, [
289
+ 'server',
290
+ 'username',
291
+ 'password',
292
+ ]);
293
+ }
294
+ if (integraion.type === 'twilio_rule_action_integrations') {
295
+ missingValues = getRequiredValues(integraion, ['sid', 'token', 'from']);
296
+ }
297
+ return missingValues;
298
+ };
299
+ var getRequiredValues = function (integraion, requiredValues) {
300
+ return requiredValues.filter(function (value) {
301
+ if (!integraion[value]) {
302
+ return true;
303
+ }
304
+ return false;
305
+ });
306
+ };