@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/AMQPClient.js +427 -0
- package/dist/cjs/Client.js +13 -8
- package/dist/cjs/Commands.js +0 -54
- package/dist/cjs/Events.js +79 -13
- package/dist/cjs/Models.js +306 -254
- package/dist/cjs/defs.js +14 -10
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/utils.js +222 -8
- package/dist/esm/Client.js +29 -20
- package/dist/esm/Client.js.map +2 -2
- package/dist/esm/Commands.js +0 -54
- package/dist/esm/Commands.js.map +2 -2
- package/dist/esm/Events.js +79 -13
- package/dist/esm/Events.js.map +3 -3
- package/dist/esm/Models.js +306 -254
- package/dist/esm/Models.js.map +4 -4
- package/dist/esm/defs.js +30 -22
- package/dist/esm/defs.js.map +2 -2
- package/dist/esm/utils.js +222 -8
- package/dist/esm/utils.js.map +3 -3
- package/package.json +4 -1
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
5
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/Errors/AppError.js
|
|
9
|
+
var require_AppError = __commonJS({
|
|
10
|
+
"src/Errors/AppError.js"(exports2, module2) {
|
|
11
|
+
module2.exports = /* @__PURE__ */ __name(class AppError extends Error {
|
|
12
|
+
constructor(message = "Internal Server Error", options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.type = this.constructor.name;
|
|
15
|
+
this.statusCode = 500;
|
|
16
|
+
Object.setPrototypeOf(this, AppError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}, "AppError");
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/Errors/AuthenticationError.js
|
|
23
|
+
var require_AuthenticationError = __commonJS({
|
|
24
|
+
"src/Errors/AuthenticationError.js"(exports2, module2) {
|
|
25
|
+
var AppError = require_AppError();
|
|
26
|
+
module2.exports = /* @__PURE__ */ __name(class AuthenticationError extends AppError {
|
|
27
|
+
constructor(message = "Authentication Error", options = {}) {
|
|
28
|
+
super(message, options);
|
|
29
|
+
this.statusCode = 401;
|
|
30
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
31
|
+
}
|
|
32
|
+
}, "AuthenticationError");
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// src/Errors/AuthorizationError.js
|
|
37
|
+
var require_AuthorizationError = __commonJS({
|
|
38
|
+
"src/Errors/AuthorizationError.js"(exports2, module2) {
|
|
39
|
+
var AppError = require_AppError();
|
|
40
|
+
module2.exports = /* @__PURE__ */ __name(class AuthorizationError extends AppError {
|
|
41
|
+
constructor(message = "Authorization Error", options = {}) {
|
|
42
|
+
super(message, options);
|
|
43
|
+
this.statusCode = 403;
|
|
44
|
+
Object.setPrototypeOf(this, AuthorizationError.prototype);
|
|
45
|
+
}
|
|
46
|
+
}, "AuthorizationError");
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// src/Errors/DeviceCommError.js
|
|
51
|
+
var require_DeviceCommError = __commonJS({
|
|
52
|
+
"src/Errors/DeviceCommError.js"(exports2, module2) {
|
|
53
|
+
var AppError = require_AppError();
|
|
54
|
+
module2.exports = /* @__PURE__ */ __name(class DeviceCommError extends AppError {
|
|
55
|
+
constructor(message = "Device Communication Error", options = {}) {
|
|
56
|
+
super(message, options);
|
|
57
|
+
this.statusCode = 503;
|
|
58
|
+
Object.setPrototypeOf(this, DeviceCommError.prototype);
|
|
59
|
+
}
|
|
60
|
+
}, "DeviceCommError");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// src/Errors/LoginError.js
|
|
65
|
+
var require_LoginError = __commonJS({
|
|
66
|
+
"src/Errors/LoginError.js"(exports2, module2) {
|
|
67
|
+
var AppError = require_AppError();
|
|
68
|
+
module2.exports = /* @__PURE__ */ __name(class LoginError extends AppError {
|
|
69
|
+
constructor(message = "Invalid Login information provided", options = {}) {
|
|
70
|
+
super(message, options);
|
|
71
|
+
this.statusCode = 401;
|
|
72
|
+
Object.setPrototypeOf(this, LoginError.prototype);
|
|
73
|
+
}
|
|
74
|
+
}, "LoginError");
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// src/Errors/NotFoundError.js
|
|
79
|
+
var require_NotFoundError = __commonJS({
|
|
80
|
+
"src/Errors/NotFoundError.js"(exports2, module2) {
|
|
81
|
+
var AppError = require_AppError();
|
|
82
|
+
module2.exports = /* @__PURE__ */ __name(class NotFoundError extends AppError {
|
|
83
|
+
constructor(message = "Resource Not Found", options = {}) {
|
|
84
|
+
super(message, options);
|
|
85
|
+
this.statusCode = 404;
|
|
86
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
87
|
+
}
|
|
88
|
+
}, "NotFoundError");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// src/Errors/RequestError.js
|
|
93
|
+
var require_RequestError = __commonJS({
|
|
94
|
+
"src/Errors/RequestError.js"(exports2, module2) {
|
|
95
|
+
var AppError = require_AppError();
|
|
96
|
+
module2.exports = /* @__PURE__ */ __name(class RequestError extends AppError {
|
|
97
|
+
constructor(message = "Bad Request", options = {}) {
|
|
98
|
+
super(message, options);
|
|
99
|
+
this.statusCode = 400;
|
|
100
|
+
Object.setPrototypeOf(this, RequestError.prototype);
|
|
101
|
+
}
|
|
102
|
+
}, "RequestError");
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// src/Errors/SystemCommError.js
|
|
107
|
+
var require_SystemCommError = __commonJS({
|
|
108
|
+
"src/Errors/SystemCommError.js"(exports2, module2) {
|
|
109
|
+
var AppError = require_AppError();
|
|
110
|
+
module2.exports = /* @__PURE__ */ __name(class SystemCommError extends AppError {
|
|
111
|
+
constructor(message = "System Communication Error", options = {}) {
|
|
112
|
+
super(message, options);
|
|
113
|
+
this.statusCode = 503;
|
|
114
|
+
Object.setPrototypeOf(this, SystemCommError.prototype);
|
|
115
|
+
}
|
|
116
|
+
}, "SystemCommError");
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/Errors/TokenExpiredError.js
|
|
121
|
+
var require_TokenExpiredError = __commonJS({
|
|
122
|
+
"src/Errors/TokenExpiredError.js"(exports2, module2) {
|
|
123
|
+
var AppError = require_AppError();
|
|
124
|
+
module2.exports = /* @__PURE__ */ __name(class TokenExpiredError extends AppError {
|
|
125
|
+
constructor(message = "Token Expired", options = {}) {
|
|
126
|
+
super(message, options);
|
|
127
|
+
this.statusCode = 401;
|
|
128
|
+
Object.setPrototypeOf(this, TokenExpiredError.prototype);
|
|
129
|
+
}
|
|
130
|
+
}, "TokenExpiredError");
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// src/Errors/UnprocessableRequestError.js
|
|
135
|
+
var require_UnprocessableRequestError = __commonJS({
|
|
136
|
+
"src/Errors/UnprocessableRequestError.js"(exports2, module2) {
|
|
137
|
+
var AppError = require_AppError();
|
|
138
|
+
module2.exports = /* @__PURE__ */ __name(class UnprocessableRequestError extends AppError {
|
|
139
|
+
constructor(message = "Unprocessable Request Error", options = {}) {
|
|
140
|
+
super(message, options);
|
|
141
|
+
this.statusCode = 422;
|
|
142
|
+
Object.setPrototypeOf(this, UnprocessableRequestError.prototype);
|
|
143
|
+
}
|
|
144
|
+
}, "UnprocessableRequestError");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// src/Errors/ValidationError.js
|
|
149
|
+
var require_ValidationError = __commonJS({
|
|
150
|
+
"src/Errors/ValidationError.js"(exports2, module2) {
|
|
151
|
+
var AppError = require_AppError();
|
|
152
|
+
module2.exports = /* @__PURE__ */ __name(class ValidationError extends AppError {
|
|
153
|
+
constructor(message = "Validation Error", options = {}) {
|
|
154
|
+
super(message, options);
|
|
155
|
+
this.statusCode = 400;
|
|
156
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
157
|
+
}
|
|
158
|
+
}, "ValidationError");
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// src/Errors/index.js
|
|
163
|
+
var require_Errors = __commonJS({
|
|
164
|
+
"src/Errors/index.js"(exports2, module2) {
|
|
165
|
+
var Errors2 = {
|
|
166
|
+
AppError: require_AppError(),
|
|
167
|
+
AuthenticationError: require_AuthenticationError(),
|
|
168
|
+
AuthorizationError: require_AuthorizationError(),
|
|
169
|
+
DeviceCommError: require_DeviceCommError(),
|
|
170
|
+
LoginError: require_LoginError(),
|
|
171
|
+
NotFoundError: require_NotFoundError(),
|
|
172
|
+
RequestError: require_RequestError(),
|
|
173
|
+
SystemCommError: require_SystemCommError(),
|
|
174
|
+
TokenExpiredError: require_TokenExpiredError(),
|
|
175
|
+
UnprocessableRequestError: require_UnprocessableRequestError(),
|
|
176
|
+
ValidationError: require_ValidationError()
|
|
177
|
+
};
|
|
178
|
+
module2.exports = Errors2;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// src/AMQPClient/index.js
|
|
183
|
+
var Errors = require_Errors();
|
|
184
|
+
var amqp = require("amqplib");
|
|
185
|
+
var crypto = require("crypto");
|
|
186
|
+
var isFatalError = require("amqplib/lib/connection").isFatalError;
|
|
187
|
+
var debug = require("debug")("kohost:amqp-client");
|
|
188
|
+
var HEADER_KEY_ORGANIZATION_ID = "organization-id";
|
|
189
|
+
var HEADER_KEY_PROPERTY_ID = "property-id";
|
|
190
|
+
var HEADER_KEY_DRIVER = "driver";
|
|
191
|
+
var exchanges = {
|
|
192
|
+
// routes commands based on `command-name` header and in many cases `property-id` header
|
|
193
|
+
Commands: {
|
|
194
|
+
name: "kohost.commands",
|
|
195
|
+
type: "headers",
|
|
196
|
+
options: {
|
|
197
|
+
durable: true
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
// routes events based on routing keys
|
|
201
|
+
Events: {
|
|
202
|
+
name: "kohost.events",
|
|
203
|
+
type: "topic",
|
|
204
|
+
options: {
|
|
205
|
+
durable: true
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
Direct: {
|
|
209
|
+
name: "kohost.direct",
|
|
210
|
+
type: "direct",
|
|
211
|
+
options: {
|
|
212
|
+
durable: true
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
Replies: {
|
|
216
|
+
name: "kohost.replies",
|
|
217
|
+
type: "topic",
|
|
218
|
+
options: {
|
|
219
|
+
durable: true
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
// dead letter exchange
|
|
223
|
+
dlx: {
|
|
224
|
+
name: "kohost.dlx",
|
|
225
|
+
type: "direct"
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var KohostAMQPClient = class {
|
|
229
|
+
static get Message() {
|
|
230
|
+
return Message;
|
|
231
|
+
}
|
|
232
|
+
static get exchanges() {
|
|
233
|
+
return exchanges;
|
|
234
|
+
}
|
|
235
|
+
static generateCorrelationId() {
|
|
236
|
+
return crypto.randomUUID();
|
|
237
|
+
}
|
|
238
|
+
static validateMessage(message) {
|
|
239
|
+
if (!message)
|
|
240
|
+
throw new Error("Message is required");
|
|
241
|
+
}
|
|
242
|
+
static parseError(err) {
|
|
243
|
+
let type;
|
|
244
|
+
let message;
|
|
245
|
+
let options = {};
|
|
246
|
+
if (err.message && err.type) {
|
|
247
|
+
const { message: errMessage, type: errType, ...rest } = err;
|
|
248
|
+
type = errType;
|
|
249
|
+
message = errMessage;
|
|
250
|
+
options = rest;
|
|
251
|
+
} else {
|
|
252
|
+
message = "Unknown Error";
|
|
253
|
+
}
|
|
254
|
+
debug("parseError", type, message, options);
|
|
255
|
+
switch (type) {
|
|
256
|
+
case "RequestError":
|
|
257
|
+
return new Errors.RequestError(message, options);
|
|
258
|
+
case "AuthenticationError":
|
|
259
|
+
return new Errors.AuthenticationError(message, options);
|
|
260
|
+
case "ValidationError":
|
|
261
|
+
return new Errors.ValidationError(message, options);
|
|
262
|
+
case "NotFoundError":
|
|
263
|
+
return new Errors.NotFoundError(message, options);
|
|
264
|
+
case "UnprocessableRequestError":
|
|
265
|
+
return new Errors.UnprocessableRequestError(message, options);
|
|
266
|
+
default:
|
|
267
|
+
return new Error(message, options);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
static parseMessage(message) {
|
|
271
|
+
var _a, _b, _c, _d, _e;
|
|
272
|
+
debug("parseMessage input %o", message);
|
|
273
|
+
let error = null;
|
|
274
|
+
let data = {};
|
|
275
|
+
let params = {};
|
|
276
|
+
let query = {};
|
|
277
|
+
let context = {};
|
|
278
|
+
let headers = {};
|
|
279
|
+
const isCommand = ((_a = message == null ? void 0 : message.properties) == null ? void 0 : _a.type) === "Command";
|
|
280
|
+
const isEvent = ((_b = message == null ? void 0 : message.properties) == null ? void 0 : _b.type) === "Event";
|
|
281
|
+
const messageHeaders = ((_c = message == null ? void 0 : message.properties) == null ? void 0 : _c.headers) || {};
|
|
282
|
+
const commandName = messageHeaders["command-name"] || null;
|
|
283
|
+
const eventName = messageHeaders["event-name"] || null;
|
|
284
|
+
if (message.content) {
|
|
285
|
+
try {
|
|
286
|
+
const payload = ((_d = message.properties) == null ? void 0 : _d.contentType) === "application/json" ? JSON.parse(message.content.toString()) : message.content.toString();
|
|
287
|
+
data = (payload == null ? void 0 : payload.data) || {};
|
|
288
|
+
error = payload == null ? void 0 : payload.error;
|
|
289
|
+
params = (payload == null ? void 0 : payload.params) || {};
|
|
290
|
+
query = (payload == null ? void 0 : payload.query) || {};
|
|
291
|
+
context = (payload == null ? void 0 : payload.context) || {};
|
|
292
|
+
} catch (error2) {
|
|
293
|
+
data = message.content.toString();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if ((_e = message == null ? void 0 : message.properties) == null ? void 0 : _e.headers) {
|
|
297
|
+
const orgHeader = message.properties.headers[HEADER_KEY_ORGANIZATION_ID];
|
|
298
|
+
const propertyHeader = message.properties.headers[HEADER_KEY_PROPERTY_ID];
|
|
299
|
+
const driverHeader = message.properties.headers[HEADER_KEY_DRIVER];
|
|
300
|
+
if (orgHeader) {
|
|
301
|
+
context.organizationId = orgHeader;
|
|
302
|
+
headers[HEADER_KEY_ORGANIZATION_ID] = orgHeader;
|
|
303
|
+
}
|
|
304
|
+
if (propertyHeader) {
|
|
305
|
+
context.propertyId = propertyHeader;
|
|
306
|
+
headers[HEADER_KEY_PROPERTY_ID] = propertyHeader;
|
|
307
|
+
}
|
|
308
|
+
if (driverHeader) {
|
|
309
|
+
context.driver = driverHeader;
|
|
310
|
+
headers[HEADER_KEY_DRIVER] = driverHeader;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const parsed = {};
|
|
314
|
+
if (error)
|
|
315
|
+
parsed.error = this.parseError(error);
|
|
316
|
+
parsed.data = data;
|
|
317
|
+
parsed.params = params;
|
|
318
|
+
parsed.query = query;
|
|
319
|
+
parsed.context = context;
|
|
320
|
+
parsed.headers = headers;
|
|
321
|
+
if (isEvent && eventName)
|
|
322
|
+
parsed.event = eventName;
|
|
323
|
+
else if (isCommand && commandName)
|
|
324
|
+
parsed.command = commandName;
|
|
325
|
+
debug("parseMessage parsed %o", parsed);
|
|
326
|
+
return parsed;
|
|
327
|
+
}
|
|
328
|
+
static getMessage(message) {
|
|
329
|
+
if (!(message == null ? void 0 : message.content))
|
|
330
|
+
return null;
|
|
331
|
+
const payload = JSON.parse(message.content.toString());
|
|
332
|
+
const data = payload == null ? void 0 : payload.data;
|
|
333
|
+
return data;
|
|
334
|
+
}
|
|
335
|
+
static isFatalError(err) {
|
|
336
|
+
return isFatalError(err);
|
|
337
|
+
}
|
|
338
|
+
async createConnection(connection, options = {}) {
|
|
339
|
+
return await amqp.connect(connection, options);
|
|
340
|
+
}
|
|
341
|
+
static createMessage(content) {
|
|
342
|
+
return new Message(content);
|
|
343
|
+
}
|
|
344
|
+
async createChannel(connection) {
|
|
345
|
+
const channel = await connection.createChannel();
|
|
346
|
+
return channel;
|
|
347
|
+
}
|
|
348
|
+
async assertExchange(channel, { exchange, type, options }) {
|
|
349
|
+
return await channel.assertExchange(exchange, type, options);
|
|
350
|
+
}
|
|
351
|
+
async assertQueue(channel, { queue, options }) {
|
|
352
|
+
return await channel.assertQueue(queue, options);
|
|
353
|
+
}
|
|
354
|
+
async bindQueue(channel, { queue, exchange, routingKey, args }) {
|
|
355
|
+
return await channel.bindQueue(queue, exchange, routingKey, args);
|
|
356
|
+
}
|
|
357
|
+
async bindExchange(channel, { source, destination, routingKey, args }) {
|
|
358
|
+
return await channel.bindExchange(destination, source, routingKey, args);
|
|
359
|
+
}
|
|
360
|
+
async subscribeToQueue(channel, { queue, cb, options }) {
|
|
361
|
+
return await channel.consume(queue, cb, options);
|
|
362
|
+
}
|
|
363
|
+
publishToExchange(channel, { exchange, routingKey, content, options }) {
|
|
364
|
+
return channel.publish(exchange, routingKey, content, options);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
__name(KohostAMQPClient, "KohostAMQPClient");
|
|
368
|
+
var Message = class {
|
|
369
|
+
constructor(content) {
|
|
370
|
+
this.toExchange = null;
|
|
371
|
+
this.content = content;
|
|
372
|
+
this.options = {
|
|
373
|
+
contentType: "application/json"
|
|
374
|
+
};
|
|
375
|
+
this.routingKey = "";
|
|
376
|
+
}
|
|
377
|
+
get correlationId() {
|
|
378
|
+
return this.options.correlationId || null;
|
|
379
|
+
}
|
|
380
|
+
to({ exchange }) {
|
|
381
|
+
if (typeof exchange === "undefined")
|
|
382
|
+
throw new Error("Exchange is required");
|
|
383
|
+
this.toExchange = exchange;
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
withType(type) {
|
|
387
|
+
this.options.type = type;
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
390
|
+
withRoutingKey(routingKey) {
|
|
391
|
+
this.routingKey = routingKey;
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
withHeaders(headers) {
|
|
395
|
+
if (!this.options.headers)
|
|
396
|
+
this.options.headers = {};
|
|
397
|
+
this.options.headers = { ...this.options.headers, ...headers };
|
|
398
|
+
return this;
|
|
399
|
+
}
|
|
400
|
+
withContext(context) {
|
|
401
|
+
for (let key in context) {
|
|
402
|
+
this.withHeaders({ [key]: context[key] });
|
|
403
|
+
}
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
withCorrelationId(correlationId) {
|
|
407
|
+
this.options.correlationId = correlationId;
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
withReplyTo(queue) {
|
|
411
|
+
this.options.replyTo = queue;
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
build() {
|
|
415
|
+
let content = this.content;
|
|
416
|
+
if (content.build && typeof content.build === "function")
|
|
417
|
+
content = content.build();
|
|
418
|
+
return {
|
|
419
|
+
exchange: this.toExchange,
|
|
420
|
+
content: Buffer.from(JSON.stringify(content)),
|
|
421
|
+
options: this.options,
|
|
422
|
+
routingKey: this.routingKey
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
__name(Message, "Message");
|
|
427
|
+
module.exports = KohostAMQPClient;
|
package/dist/cjs/Client.js
CHANGED
|
@@ -5089,6 +5089,7 @@ var KohostApiClient = class extends EventEmitter {
|
|
|
5089
5089
|
constructor(options = {
|
|
5090
5090
|
url: "",
|
|
5091
5091
|
propertyId: "",
|
|
5092
|
+
organizationId: "",
|
|
5092
5093
|
apiKey: "",
|
|
5093
5094
|
headers: {}
|
|
5094
5095
|
}) {
|
|
@@ -5099,6 +5100,7 @@ var KohostApiClient = class extends EventEmitter {
|
|
|
5099
5100
|
throw new Error("options.property is required");
|
|
5100
5101
|
this.options = options;
|
|
5101
5102
|
this.isBrowser = typeof window !== "undefined";
|
|
5103
|
+
this.isRefreshingToken = false;
|
|
5102
5104
|
const config = {
|
|
5103
5105
|
baseURL: options.url,
|
|
5104
5106
|
responseType: "json",
|
|
@@ -5157,24 +5159,27 @@ var KohostApiClient = class extends EventEmitter {
|
|
|
5157
5159
|
this._onLoginRequired();
|
|
5158
5160
|
return Promise.reject(error);
|
|
5159
5161
|
}
|
|
5160
|
-
if (expectedError && errorMessage === "No
|
|
5162
|
+
if (expectedError && errorMessage === "No auth header or cookie provided") {
|
|
5161
5163
|
this._onLoginRequired();
|
|
5162
5164
|
return Promise.reject(error);
|
|
5163
5165
|
}
|
|
5164
5166
|
if (expectedError && newTokensNeeded) {
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5167
|
+
while (!this.isRefreshingToken) {
|
|
5168
|
+
this.isRefreshingToken = true;
|
|
5169
|
+
return this.RefreshToken().then(() => {
|
|
5170
|
+
this.isRefreshingToken = false;
|
|
5171
|
+
return this._http(originalReq);
|
|
5172
|
+
}).catch((err) => {
|
|
5173
|
+
this.isRefreshingToken = false;
|
|
5174
|
+
return Promise.reject(err);
|
|
5175
|
+
});
|
|
5176
|
+
}
|
|
5168
5177
|
}
|
|
5169
5178
|
} catch (error2) {
|
|
5170
5179
|
console.log(error2);
|
|
5171
5180
|
}
|
|
5172
5181
|
return Promise.reject(error);
|
|
5173
5182
|
}
|
|
5174
|
-
/*
|
|
5175
|
-
@param {String} token - The token to set
|
|
5176
|
-
@returns undefined
|
|
5177
|
-
*/
|
|
5178
5183
|
_onLoginRequired() {
|
|
5179
5184
|
this.emit("LoginRequired");
|
|
5180
5185
|
}
|
package/dist/cjs/Commands.js
CHANGED
|
@@ -31,9 +31,6 @@ var require_Command = __commonJS({
|
|
|
31
31
|
get exchange() {
|
|
32
32
|
return "Commands";
|
|
33
33
|
}
|
|
34
|
-
get replyTo() {
|
|
35
|
-
return "amq.rabbitmq.reply-to";
|
|
36
|
-
}
|
|
37
34
|
build() {
|
|
38
35
|
return { data: { ...this.data } };
|
|
39
36
|
}
|
|
@@ -57,9 +54,6 @@ var require_SetAlarmCommand = __commonJS({
|
|
|
57
54
|
get routingKey() {
|
|
58
55
|
return `alarm.${this.data.id}.set`;
|
|
59
56
|
}
|
|
60
|
-
get replyTo() {
|
|
61
|
-
return "system.response.devices";
|
|
62
|
-
}
|
|
63
57
|
};
|
|
64
58
|
__name(SetAlarmCommand2, "SetAlarmCommand");
|
|
65
59
|
module2.exports = SetAlarmCommand2;
|
|
@@ -80,9 +74,6 @@ var require_SetDimmerCommand = __commonJS({
|
|
|
80
74
|
get routingKey() {
|
|
81
75
|
return `dimmer.${this.data.id}.set`;
|
|
82
76
|
}
|
|
83
|
-
get replyTo() {
|
|
84
|
-
return "system.response.devices";
|
|
85
|
-
}
|
|
86
77
|
};
|
|
87
78
|
__name(SetDimmerCommand2, "SetDimmerCommand");
|
|
88
79
|
module2.exports = SetDimmerCommand2;
|
|
@@ -103,9 +94,6 @@ var require_SetSwitchCommand = __commonJS({
|
|
|
103
94
|
get routingKey() {
|
|
104
95
|
return `switch.${this.data.id}.set`;
|
|
105
96
|
}
|
|
106
|
-
get replyTo() {
|
|
107
|
-
return "system.response.devices";
|
|
108
|
-
}
|
|
109
97
|
};
|
|
110
98
|
__name(SetSwitchCommand2, "SetSwitchCommand");
|
|
111
99
|
module2.exports = SetSwitchCommand2;
|
|
@@ -126,9 +114,6 @@ var require_SetThermostatCommand = __commonJS({
|
|
|
126
114
|
get routingKey() {
|
|
127
115
|
return `thermostat.${this.data.id}.set`;
|
|
128
116
|
}
|
|
129
|
-
get replyTo() {
|
|
130
|
-
return "system.response.devices";
|
|
131
|
-
}
|
|
132
117
|
};
|
|
133
118
|
__name(SetThermostatCommand2, "SetThermostatCommand");
|
|
134
119
|
module2.exports = SetThermostatCommand2;
|
|
@@ -149,9 +134,6 @@ var require_SetLockCommand = __commonJS({
|
|
|
149
134
|
get routingKey() {
|
|
150
135
|
return `lock.${this.data.id}.set`;
|
|
151
136
|
}
|
|
152
|
-
get replyTo() {
|
|
153
|
-
return "system.response.devices";
|
|
154
|
-
}
|
|
155
137
|
};
|
|
156
138
|
__name(SetLockCommand2, "SetLockCommand");
|
|
157
139
|
module2.exports = SetLockCommand2;
|
|
@@ -172,9 +154,6 @@ var require_SetSceneControllerCommand = __commonJS({
|
|
|
172
154
|
get routingKey() {
|
|
173
155
|
return `sceneController.${this.data.id}.set`;
|
|
174
156
|
}
|
|
175
|
-
get replyTo() {
|
|
176
|
-
return "system.response.devices";
|
|
177
|
-
}
|
|
178
157
|
};
|
|
179
158
|
__name(SetSceneControllerCommand2, "SetSceneControllerCommand");
|
|
180
159
|
module2.exports = SetSceneControllerCommand2;
|
|
@@ -195,9 +174,6 @@ var require_SetWindowCoveringCommand = __commonJS({
|
|
|
195
174
|
get routingKey() {
|
|
196
175
|
return `windowCovering.${this.data.id}.set`;
|
|
197
176
|
}
|
|
198
|
-
get replyTo() {
|
|
199
|
-
return "system.response.devices";
|
|
200
|
-
}
|
|
201
177
|
};
|
|
202
178
|
__name(SetWindowCoveringCommand2, "SetWindowCoveringCommand");
|
|
203
179
|
module2.exports = SetWindowCoveringCommand2;
|
|
@@ -218,9 +194,6 @@ var require_SetCourtesyCommand = __commonJS({
|
|
|
218
194
|
get routingKey() {
|
|
219
195
|
return `courtesy.${this.data.id}.set`;
|
|
220
196
|
}
|
|
221
|
-
get replyTo() {
|
|
222
|
-
return "system.response.devices";
|
|
223
|
-
}
|
|
224
197
|
};
|
|
225
198
|
__name(SetCourtesyCommand2, "SetCourtesyCommand");
|
|
226
199
|
module2.exports = SetCourtesyCommand2;
|
|
@@ -245,9 +218,6 @@ var require_DiscoverUsersCommand = __commonJS({
|
|
|
245
218
|
return "users.batch.get";
|
|
246
219
|
return "users.get";
|
|
247
220
|
}
|
|
248
|
-
get replyTo() {
|
|
249
|
-
return "system.response.users";
|
|
250
|
-
}
|
|
251
221
|
};
|
|
252
222
|
__name(DiscoverUsersCommand2, "DiscoverUsersCommand");
|
|
253
223
|
module2.exports = DiscoverUsersCommand2;
|
|
@@ -296,9 +266,6 @@ var require_OCRDocumentCommand = __commonJS({
|
|
|
296
266
|
get name() {
|
|
297
267
|
return "OCRDocument";
|
|
298
268
|
}
|
|
299
|
-
get routingKey() {
|
|
300
|
-
return `document.${this.data.type}.ocr`;
|
|
301
|
-
}
|
|
302
269
|
};
|
|
303
270
|
__name(OCRDocumentCommand2, "OCRDocumentCommand");
|
|
304
271
|
module2.exports = OCRDocumentCommand2;
|
|
@@ -322,9 +289,6 @@ var require_CheckInReservationCommand = __commonJS({
|
|
|
322
289
|
get routingKey() {
|
|
323
290
|
return `reservation.${this.data.id}.checkin`;
|
|
324
291
|
}
|
|
325
|
-
get replyTo() {
|
|
326
|
-
return "system.response.reservations";
|
|
327
|
-
}
|
|
328
292
|
};
|
|
329
293
|
__name(CheckInReservationCommand2, "CheckInReservationCommand");
|
|
330
294
|
module2.exports = CheckInReservationCommand2;
|
|
@@ -551,9 +515,6 @@ var require_DiscoverReservationsCommand = __commonJS({
|
|
|
551
515
|
get routingKey() {
|
|
552
516
|
return "reservation.discover";
|
|
553
517
|
}
|
|
554
|
-
get replyTo() {
|
|
555
|
-
return "system.response.reservations";
|
|
556
|
-
}
|
|
557
518
|
};
|
|
558
519
|
__name(DiscoverReservationsCommand2, "DiscoverReservationsCommand");
|
|
559
520
|
module2.exports = DiscoverReservationsCommand2;
|
|
@@ -585,9 +546,6 @@ var require_DiscoverRoomsCommand = __commonJS({
|
|
|
585
546
|
return "rooms.batch.get";
|
|
586
547
|
return "rooms.get";
|
|
587
548
|
}
|
|
588
|
-
get replyTo() {
|
|
589
|
-
return "system.response.users";
|
|
590
|
-
}
|
|
591
549
|
};
|
|
592
550
|
__name(DiscoverRoomsCommand2, "DiscoverRoomsCommand");
|
|
593
551
|
module2.exports = DiscoverRoomsCommand2;
|
|
@@ -612,9 +570,6 @@ var require_DiscoverRoomTypesCommand = __commonJS({
|
|
|
612
570
|
return "rooms.batch.get";
|
|
613
571
|
return "rooms.get";
|
|
614
572
|
}
|
|
615
|
-
get replyTo() {
|
|
616
|
-
return "system.response.users";
|
|
617
|
-
}
|
|
618
573
|
};
|
|
619
574
|
__name(DiscoverRoomTypesCommand2, "DiscoverRoomTypesCommand");
|
|
620
575
|
module2.exports = DiscoverRoomTypesCommand2;
|
|
@@ -663,9 +618,6 @@ var require_UpdateReservationCommand = __commonJS({
|
|
|
663
618
|
get routingKey() {
|
|
664
619
|
return `reservation.${this.data.id}.update`;
|
|
665
620
|
}
|
|
666
|
-
get replyTo() {
|
|
667
|
-
return "system.response.reservations";
|
|
668
|
-
}
|
|
669
621
|
};
|
|
670
622
|
__name(UpdateReservationCommand2, "UpdateReservationCommand");
|
|
671
623
|
module2.exports = UpdateReservationCommand2;
|
|
@@ -709,9 +661,6 @@ var require_UpdateUserCommand = __commonJS({
|
|
|
709
661
|
get routingKey() {
|
|
710
662
|
return `user.${this.data.id}.update`;
|
|
711
663
|
}
|
|
712
|
-
get replyTo() {
|
|
713
|
-
return "system.response.users";
|
|
714
|
-
}
|
|
715
664
|
};
|
|
716
665
|
__name(UpdateUserCommand2, "UpdateUserCommand");
|
|
717
666
|
module2.exports = UpdateUserCommand2;
|
|
@@ -739,9 +688,6 @@ var require_GetMobileKeyCommand = __commonJS({
|
|
|
739
688
|
get routingKey() {
|
|
740
689
|
return `lock.${this.data.id}.set`;
|
|
741
690
|
}
|
|
742
|
-
get replyTo() {
|
|
743
|
-
return "system.response.devices";
|
|
744
|
-
}
|
|
745
691
|
};
|
|
746
692
|
__name(GetMobileKeyCommand2, "GetMobileKeyCommand");
|
|
747
693
|
module2.exports = GetMobileKeyCommand2;
|