@kohost/api-client 3.0.0-beta.21 → 3.0.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/defs.js CHANGED
@@ -14,11 +14,10 @@ var require_deviceTypes = __commonJS({
14
14
  "thermostat",
15
15
  "lock",
16
16
  "windowCovering",
17
- "sceneController",
18
17
  "courtesy",
19
18
  "alarm",
20
19
  "camera",
21
- "source",
20
+ "mediaSource",
22
21
  "motionSensor"
23
22
  ];
24
23
  module2.exports = types;
@@ -52,6 +51,7 @@ var require_Client = __commonJS({
52
51
  constructor(options = {
53
52
  url: "",
54
53
  propertyId: "",
54
+ organizationId: "",
55
55
  apiKey: "",
56
56
  headers: {}
57
57
  }) {
@@ -62,6 +62,7 @@ var require_Client = __commonJS({
62
62
  throw new Error("options.property is required");
63
63
  this.options = options;
64
64
  this.isBrowser = typeof window !== "undefined";
65
+ this.isRefreshingToken = false;
65
66
  const config = {
66
67
  baseURL: options.url,
67
68
  responseType: "json",
@@ -120,24 +121,27 @@ var require_Client = __commonJS({
120
121
  this._onLoginRequired();
121
122
  return Promise.reject(error);
122
123
  }
123
- if (expectedError && errorMessage === "No token provided") {
124
+ if (expectedError && errorMessage === "No auth header or cookie provided") {
124
125
  this._onLoginRequired();
125
126
  return Promise.reject(error);
126
127
  }
127
128
  if (expectedError && newTokensNeeded) {
128
- return this.RefreshToken().then(() => {
129
- return this._http(originalReq);
130
- });
129
+ while (!this.isRefreshingToken) {
130
+ this.isRefreshingToken = true;
131
+ return this.RefreshToken().then(() => {
132
+ this.isRefreshingToken = false;
133
+ return this._http(originalReq);
134
+ }).catch((err) => {
135
+ this.isRefreshingToken = false;
136
+ return Promise.reject(err);
137
+ });
138
+ }
131
139
  }
132
140
  } catch (error2) {
133
141
  console.log(error2);
134
142
  }
135
143
  return Promise.reject(error);
136
144
  }
137
- /*
138
- @param {String} token - The token to set
139
- @returns undefined
140
- */
141
145
  _onLoginRequired() {
142
146
  this.emit("LoginRequired");
143
147
  }
@@ -6,6 +6,7 @@ const defs = require("./defs");
6
6
  const utils = require("./utils");
7
7
  const Client = require("./Client");
8
8
  const SocketIoClient = require("./SocketIoClient");
9
+ const AMQPClient = require("./AMQPClient");
9
10
  const Kohost = {
10
11
  Models,
11
12
  Errors,
@@ -13,6 +14,7 @@ const Kohost = {
13
14
  Events,
14
15
  Client,
15
16
  SocketIoClient,
17
+ AMQPClient,
16
18
  defs,
17
19
  utils
18
20
  };
package/dist/cjs/utils.js CHANGED
@@ -25,11 +25,10 @@ var require_deviceTypes = __commonJS({
25
25
  "thermostat",
26
26
  "lock",
27
27
  "windowCovering",
28
- "sceneController",
29
28
  "courtesy",
30
29
  "alarm",
31
30
  "camera",
32
- "source",
31
+ "mediaSource",
33
32
  "motionSensor"
34
33
  ];
35
34
  module2.exports = types;
@@ -53,10 +52,13 @@ var require_common = __commonJS({
53
52
  "src/schemas/definitions/common.json"(exports2, module2) {
54
53
  module2.exports = {
55
54
  $schema: "http://json-schema.org/draft-07/schema",
56
- $id: "https://api.kohost.app/schemas/v3/definitions/common.json",
55
+ $id: "https://api.kohost.io/schemas/v3/definitions/common.json",
57
56
  definitions: {
58
57
  id: {
59
- type: "string"
58
+ type: "string",
59
+ not: {
60
+ enum: ["global", "system"]
61
+ }
60
62
  },
61
63
  systemData: {
62
64
  type: "object",
@@ -122,6 +124,28 @@ var require_common = __commonJS({
122
124
  maxLength: 2
123
125
  }
124
126
  }
127
+ },
128
+ driver: {
129
+ type: "string",
130
+ enum: [
131
+ "aws-kinesis",
132
+ "butler",
133
+ "crestron",
134
+ "ecobee",
135
+ "igor",
136
+ "kohost-k7",
137
+ "kohost-pms",
138
+ "lirc",
139
+ "mews",
140
+ "pelican-wireless",
141
+ "rebrandly",
142
+ "salto",
143
+ "salto-irn",
144
+ "se",
145
+ "sendgrid",
146
+ "stay-n-touch",
147
+ "twilio"
148
+ ]
125
149
  }
126
150
  }
127
151
  };
@@ -133,13 +157,13 @@ var require_device = __commonJS({
133
157
  "src/schemas/definitions/device.json"(exports2, module2) {
134
158
  module2.exports = {
135
159
  $schema: "http://json-schema.org/draft-07/schema",
136
- $id: "https://api.kohost.app/schemas/v3/definitions/device.json",
160
+ $id: "https://api.kohost.io/schemas/v3/definitions/device.json",
137
161
  definitions: {
138
162
  id: {
139
- $ref: "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/id"
163
+ $ref: "https://api.kohost.io/schemas/v3/definitions/common.json#/definitions/id"
140
164
  },
141
165
  systemData: {
142
- $ref: "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/systemData"
166
+ $ref: "https://api.kohost.io/schemas/v3/definitions/common.json#/definitions/systemData"
143
167
  },
144
168
  type: {
145
169
  type: "string",
@@ -239,12 +263,202 @@ var require_schema = __commonJS({
239
263
  }
240
264
  });
241
265
 
266
+ // src/Errors/AppError.js
267
+ var require_AppError = __commonJS({
268
+ "src/Errors/AppError.js"(exports2, module2) {
269
+ module2.exports = /* @__PURE__ */ __name(class AppError extends Error {
270
+ constructor(message = "Internal Server Error", options) {
271
+ super(message, options);
272
+ this.type = this.constructor.name;
273
+ this.statusCode = 500;
274
+ Object.setPrototypeOf(this, AppError.prototype);
275
+ }
276
+ }, "AppError");
277
+ }
278
+ });
279
+
280
+ // src/Errors/AuthenticationError.js
281
+ var require_AuthenticationError = __commonJS({
282
+ "src/Errors/AuthenticationError.js"(exports2, module2) {
283
+ var AppError = require_AppError();
284
+ module2.exports = /* @__PURE__ */ __name(class AuthenticationError extends AppError {
285
+ constructor(message = "Authentication Error", options = {}) {
286
+ super(message, options);
287
+ this.statusCode = 401;
288
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
289
+ }
290
+ }, "AuthenticationError");
291
+ }
292
+ });
293
+
294
+ // src/Errors/AuthorizationError.js
295
+ var require_AuthorizationError = __commonJS({
296
+ "src/Errors/AuthorizationError.js"(exports2, module2) {
297
+ var AppError = require_AppError();
298
+ module2.exports = /* @__PURE__ */ __name(class AuthorizationError extends AppError {
299
+ constructor(message = "Authorization Error", options = {}) {
300
+ super(message, options);
301
+ this.statusCode = 403;
302
+ Object.setPrototypeOf(this, AuthorizationError.prototype);
303
+ }
304
+ }, "AuthorizationError");
305
+ }
306
+ });
307
+
308
+ // src/Errors/DeviceCommError.js
309
+ var require_DeviceCommError = __commonJS({
310
+ "src/Errors/DeviceCommError.js"(exports2, module2) {
311
+ var AppError = require_AppError();
312
+ module2.exports = /* @__PURE__ */ __name(class DeviceCommError extends AppError {
313
+ constructor(message = "Device Communication Error", options = {}) {
314
+ super(message, options);
315
+ this.statusCode = 503;
316
+ Object.setPrototypeOf(this, DeviceCommError.prototype);
317
+ }
318
+ }, "DeviceCommError");
319
+ }
320
+ });
321
+
322
+ // src/Errors/LoginError.js
323
+ var require_LoginError = __commonJS({
324
+ "src/Errors/LoginError.js"(exports2, module2) {
325
+ var AppError = require_AppError();
326
+ module2.exports = /* @__PURE__ */ __name(class LoginError extends AppError {
327
+ constructor(message = "Invalid Login information provided", options = {}) {
328
+ super(message, options);
329
+ this.statusCode = 401;
330
+ Object.setPrototypeOf(this, LoginError.prototype);
331
+ }
332
+ }, "LoginError");
333
+ }
334
+ });
335
+
336
+ // src/Errors/NotFoundError.js
337
+ var require_NotFoundError = __commonJS({
338
+ "src/Errors/NotFoundError.js"(exports2, module2) {
339
+ var AppError = require_AppError();
340
+ module2.exports = /* @__PURE__ */ __name(class NotFoundError extends AppError {
341
+ constructor(message = "Resource Not Found", options = {}) {
342
+ super(message, options);
343
+ this.statusCode = 404;
344
+ Object.setPrototypeOf(this, NotFoundError.prototype);
345
+ }
346
+ }, "NotFoundError");
347
+ }
348
+ });
349
+
350
+ // src/Errors/RequestError.js
351
+ var require_RequestError = __commonJS({
352
+ "src/Errors/RequestError.js"(exports2, module2) {
353
+ var AppError = require_AppError();
354
+ module2.exports = /* @__PURE__ */ __name(class RequestError extends AppError {
355
+ constructor(message = "Bad Request", options = {}) {
356
+ super(message, options);
357
+ this.statusCode = 400;
358
+ Object.setPrototypeOf(this, RequestError.prototype);
359
+ }
360
+ }, "RequestError");
361
+ }
362
+ });
363
+
364
+ // src/Errors/SystemCommError.js
365
+ var require_SystemCommError = __commonJS({
366
+ "src/Errors/SystemCommError.js"(exports2, module2) {
367
+ var AppError = require_AppError();
368
+ module2.exports = /* @__PURE__ */ __name(class SystemCommError extends AppError {
369
+ constructor(message = "System Communication Error", options = {}) {
370
+ super(message, options);
371
+ this.statusCode = 503;
372
+ Object.setPrototypeOf(this, SystemCommError.prototype);
373
+ }
374
+ }, "SystemCommError");
375
+ }
376
+ });
377
+
378
+ // src/Errors/TokenExpiredError.js
379
+ var require_TokenExpiredError = __commonJS({
380
+ "src/Errors/TokenExpiredError.js"(exports2, module2) {
381
+ var AppError = require_AppError();
382
+ module2.exports = /* @__PURE__ */ __name(class TokenExpiredError extends AppError {
383
+ constructor(message = "Token Expired", options = {}) {
384
+ super(message, options);
385
+ this.statusCode = 401;
386
+ Object.setPrototypeOf(this, TokenExpiredError.prototype);
387
+ }
388
+ }, "TokenExpiredError");
389
+ }
390
+ });
391
+
392
+ // src/Errors/UnprocessableRequestError.js
393
+ var require_UnprocessableRequestError = __commonJS({
394
+ "src/Errors/UnprocessableRequestError.js"(exports2, module2) {
395
+ var AppError = require_AppError();
396
+ module2.exports = /* @__PURE__ */ __name(class UnprocessableRequestError extends AppError {
397
+ constructor(message = "Unprocessable Request Error", options = {}) {
398
+ super(message, options);
399
+ this.statusCode = 422;
400
+ Object.setPrototypeOf(this, UnprocessableRequestError.prototype);
401
+ }
402
+ }, "UnprocessableRequestError");
403
+ }
404
+ });
405
+
406
+ // src/Errors/ValidationError.js
407
+ var require_ValidationError = __commonJS({
408
+ "src/Errors/ValidationError.js"(exports2, module2) {
409
+ var AppError = require_AppError();
410
+ module2.exports = /* @__PURE__ */ __name(class ValidationError extends AppError {
411
+ constructor(message = "Validation Error", options = {}) {
412
+ super(message, options);
413
+ this.statusCode = 400;
414
+ Object.setPrototypeOf(this, ValidationError.prototype);
415
+ }
416
+ }, "ValidationError");
417
+ }
418
+ });
419
+
420
+ // src/Errors/index.js
421
+ var require_Errors = __commonJS({
422
+ "src/Errors/index.js"(exports2, module2) {
423
+ var Errors = {
424
+ AppError: require_AppError(),
425
+ AuthenticationError: require_AuthenticationError(),
426
+ AuthorizationError: require_AuthorizationError(),
427
+ DeviceCommError: require_DeviceCommError(),
428
+ LoginError: require_LoginError(),
429
+ NotFoundError: require_NotFoundError(),
430
+ RequestError: require_RequestError(),
431
+ SystemCommError: require_SystemCommError(),
432
+ TokenExpiredError: require_TokenExpiredError(),
433
+ UnprocessableRequestError: require_UnprocessableRequestError(),
434
+ ValidationError: require_ValidationError()
435
+ };
436
+ module2.exports = Errors;
437
+ }
438
+ });
439
+
440
+ // src/utils/errorFactory.js
441
+ var require_errorFactory = __commonJS({
442
+ "src/utils/errorFactory.js"(exports2, module2) {
443
+ var Errors = require_Errors();
444
+ module2.exports = /* @__PURE__ */ __name(function errorFactory2(errName) {
445
+ const AllErrors = Object.values(Errors);
446
+ const TheError = AllErrors.find((E) => E.prototype.name === errName);
447
+ if (!TheError)
448
+ return new Error("Invalid error name: " + errName);
449
+ return TheError;
450
+ }, "errorFactory");
451
+ }
452
+ });
453
+
242
454
  // src/utils/index.js
243
455
  var getFormalDeviceType = require_getFormalDeviceType();
244
456
  var getDeviceTypes = require_getDeviceTypes();
245
457
  var schema = require_schema();
458
+ var errorFactory = require_errorFactory();
246
459
  module.exports = {
247
460
  getFormalDeviceType,
248
461
  getDeviceTypes,
249
- schema
462
+ schema,
463
+ errorFactory
250
464
  };
@@ -5390,8 +5390,9 @@ var require_axios = __commonJS({
5390
5390
  var isFileList = kindOfTest("FileList");
5391
5391
  var isStream = /* @__PURE__ */ __name((val) => isObject(val) && isFunction(val.pipe), "isStream");
5392
5392
  var isFormData = /* @__PURE__ */ __name((thing) => {
5393
- const pattern = "[object FormData]";
5394
- return thing && (typeof FormData === "function" && thing instanceof FormData || toString.call(thing) === pattern || isFunction(thing.toString) && thing.toString() === pattern);
5393
+ let kind;
5394
+ return thing && (typeof FormData === "function" && thing instanceof FormData || isFunction(thing.append) && ((kind = kindOf(thing)) === "formdata" || // detect form-data instance
5395
+ kind === "object" && isFunction(thing.toString) && thing.toString() === "[object FormData]"));
5395
5396
  }, "isFormData");
5396
5397
  var isURLSearchParams = kindOfTest("URLSearchParams");
5397
5398
  var trim = /* @__PURE__ */ __name((str) => str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""), "trim");
@@ -6286,10 +6287,7 @@ var require_axios = __commonJS({
6286
6287
  return tokens;
6287
6288
  }
6288
6289
  __name(parseTokens, "parseTokens");
6289
- function isValidHeaderName(str) {
6290
- return /^[-_a-zA-Z]+$/.test(str.trim());
6291
- }
6292
- __name(isValidHeaderName, "isValidHeaderName");
6290
+ var isValidHeaderName = /* @__PURE__ */ __name((str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim()), "isValidHeaderName");
6293
6291
  function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
6294
6292
  if (utils.isFunction(filter)) {
6295
6293
  return filter.call(this, value, header);
@@ -6995,7 +6993,7 @@ var require_axios = __commonJS({
6995
6993
  return config;
6996
6994
  }
6997
6995
  __name(mergeConfig, "mergeConfig");
6998
- var VERSION = "1.3.4";
6996
+ var VERSION = "1.3.6";
6999
6997
  var validators$1 = {};
7000
6998
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
7001
6999
  validators$1[type] = /* @__PURE__ */ __name(function validator2(thing) {
@@ -7087,11 +7085,17 @@ var require_axios = __commonJS({
7087
7085
  clarifyTimeoutError: validators.transitional(validators.boolean)
7088
7086
  }, false);
7089
7087
  }
7090
- if (paramsSerializer !== void 0) {
7091
- validator.assertOptions(paramsSerializer, {
7092
- encode: validators.function,
7093
- serialize: validators.function
7094
- }, true);
7088
+ if (paramsSerializer != null) {
7089
+ if (utils.isFunction(paramsSerializer)) {
7090
+ config.paramsSerializer = {
7091
+ serialize: paramsSerializer
7092
+ };
7093
+ } else {
7094
+ validator.assertOptions(paramsSerializer, {
7095
+ encode: validators.function,
7096
+ serialize: validators.function
7097
+ }, true);
7098
+ }
7095
7099
  }
7096
7100
  config.method = (config.method || this.defaults.method || "get").toLowerCase();
7097
7101
  let contextHeaders;
@@ -7540,6 +7544,7 @@ var require_Client = __commonJS({
7540
7544
  constructor(options = {
7541
7545
  url: "",
7542
7546
  propertyId: "",
7547
+ organizationId: "",
7543
7548
  apiKey: "",
7544
7549
  headers: {}
7545
7550
  }) {
@@ -7550,6 +7555,7 @@ var require_Client = __commonJS({
7550
7555
  throw new Error("options.property is required");
7551
7556
  this.options = options;
7552
7557
  this.isBrowser = typeof window !== "undefined";
7558
+ this.isRefreshingToken = false;
7553
7559
  const config = {
7554
7560
  baseURL: options.url,
7555
7561
  responseType: "json",
@@ -7606,24 +7612,27 @@ var require_Client = __commonJS({
7606
7612
  this._onLoginRequired();
7607
7613
  return Promise.reject(error);
7608
7614
  }
7609
- if (expectedError && errorMessage === "No token provided") {
7615
+ if (expectedError && errorMessage === "No auth header or cookie provided") {
7610
7616
  this._onLoginRequired();
7611
7617
  return Promise.reject(error);
7612
7618
  }
7613
7619
  if (expectedError && newTokensNeeded) {
7614
- return this.RefreshToken().then(() => {
7615
- return this._http(originalReq);
7616
- });
7620
+ while (!this.isRefreshingToken) {
7621
+ this.isRefreshingToken = true;
7622
+ return this.RefreshToken().then(() => {
7623
+ this.isRefreshingToken = false;
7624
+ return this._http(originalReq);
7625
+ }).catch((err) => {
7626
+ this.isRefreshingToken = false;
7627
+ return Promise.reject(err);
7628
+ });
7629
+ }
7617
7630
  }
7618
7631
  } catch (error2) {
7619
7632
  console.log(error2);
7620
7633
  }
7621
7634
  return Promise.reject(error);
7622
7635
  }
7623
- /*
7624
- @param {String} token - The token to set
7625
- @returns undefined
7626
- */
7627
7636
  _onLoginRequired() {
7628
7637
  this.emit("LoginRequired");
7629
7638
  }