@kohost/api-client 4.0.4 → 4.0.6
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/{chunk-EBJTC6MA.js → chunk-5I2BBUZP.js} +11 -1
- package/dist/{chunk-EBJTC6MA.js.map → chunk-5I2BBUZP.js.map} +1 -1
- package/dist/{chunk-HKJ2B2AA.js → chunk-FU4IK6I4.js} +3 -1
- package/dist/{chunk-KBBL6OJS.js → chunk-SLDNFNED.js} +290 -90
- package/dist/{chunk-KBBL6OJS.js.map → chunk-SLDNFNED.js.map} +1 -1
- package/dist/{chunk-36WNTEIW.js → chunk-SORMAXAX.js} +35 -2
- package/dist/{chunk-36WNTEIW.js.map → chunk-SORMAXAX.js.map} +1 -1
- package/dist/{chunk-MYWOGDCQ.js → chunk-TBEXLKDH.js} +25 -21
- package/dist/chunk-TBEXLKDH.js.map +1 -0
- package/dist/{chunk-W2G36LNI.js → chunk-UZQ2AWUY.js} +8 -1
- package/dist/{chunk-W2G36LNI.js.map → chunk-UZQ2AWUY.js.map} +1 -1
- package/dist/client.cjs +39 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +39 -9
- package/dist/client.js.map +1 -1
- package/dist/commands.cjs +85 -0
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.js +87 -1
- package/dist/commands.js.map +1 -1
- package/dist/defs.js +1 -1
- package/dist/errors.cjs +37 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +3 -3
- package/dist/events.cjs +16 -12
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.cts +7 -7
- package/dist/events.d.ts +7 -7
- package/dist/events.js +14 -14
- package/dist/index.cjs +1110 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +1110 -108
- package/dist/index.js.map +1 -1
- package/dist/models.cjs +292 -86
- package/dist/models.cjs.map +1 -1
- package/dist/models.js +3 -3
- package/dist/socketIoClient.cjs +7 -3
- package/dist/socketIoClient.cjs.map +1 -1
- package/dist/socketIoClient.d.cts +1 -1
- package/dist/socketIoClient.d.ts +1 -1
- package/dist/socketIoClient.js +9 -4
- package/dist/socketIoClient.js.map +1 -1
- package/dist/useCases.cjs +640 -0
- package/dist/useCases.cjs.map +1 -1
- package/dist/useCases.js +640 -2
- package/dist/useCases.js.map +1 -1
- package/dist/utils.cjs +340 -98
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +10 -5
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-MYWOGDCQ.js.map +0 -1
- /package/dist/{chunk-HKJ2B2AA.js.map → chunk-FU4IK6I4.js.map} +0 -0
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5I2BBUZP.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-FU4IK6I4.js";
|
|
4
7
|
|
|
5
8
|
// src/errors/authenticationError.js
|
|
6
9
|
var AuthenticationError = class _AuthenticationError extends AppError {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "AuthenticationError");
|
|
12
|
+
}
|
|
7
13
|
constructor(message = "Authentication Error", options = {}) {
|
|
8
14
|
super(message, options);
|
|
9
15
|
this.statusCode = 401;
|
|
@@ -14,6 +20,9 @@ var AuthenticationError = class _AuthenticationError extends AppError {
|
|
|
14
20
|
|
|
15
21
|
// src/errors/authorizationError.js
|
|
16
22
|
var AuthorizationError = class _AuthorizationError extends AppError {
|
|
23
|
+
static {
|
|
24
|
+
__name(this, "AuthorizationError");
|
|
25
|
+
}
|
|
17
26
|
constructor(message = "Authorization Error", options = {}) {
|
|
18
27
|
super(message, options);
|
|
19
28
|
this.statusCode = 403;
|
|
@@ -24,6 +33,9 @@ var AuthorizationError = class _AuthorizationError extends AppError {
|
|
|
24
33
|
|
|
25
34
|
// src/errors/conflictError.js
|
|
26
35
|
var ConflictError = class _ConflictError extends AppError {
|
|
36
|
+
static {
|
|
37
|
+
__name(this, "ConflictError");
|
|
38
|
+
}
|
|
27
39
|
constructor(message = "Bad Request", options = {}) {
|
|
28
40
|
super(message, options);
|
|
29
41
|
this.statusCode = 409;
|
|
@@ -34,6 +46,9 @@ var ConflictError = class _ConflictError extends AppError {
|
|
|
34
46
|
|
|
35
47
|
// src/errors/deviceCommError.js
|
|
36
48
|
var DeviceCommError = class _DeviceCommError extends AppError {
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "DeviceCommError");
|
|
51
|
+
}
|
|
37
52
|
constructor(message = "Device Communication Error", options = {}) {
|
|
38
53
|
super(message, options);
|
|
39
54
|
this.statusCode = 503;
|
|
@@ -44,6 +59,9 @@ var DeviceCommError = class _DeviceCommError extends AppError {
|
|
|
44
59
|
|
|
45
60
|
// src/errors/loginError.js
|
|
46
61
|
var LoginError = class _LoginError extends AppError {
|
|
62
|
+
static {
|
|
63
|
+
__name(this, "LoginError");
|
|
64
|
+
}
|
|
47
65
|
constructor(message = "Invalid Login information provided", options = {}) {
|
|
48
66
|
super(message, options);
|
|
49
67
|
this.statusCode = 401;
|
|
@@ -54,6 +72,9 @@ var LoginError = class _LoginError extends AppError {
|
|
|
54
72
|
|
|
55
73
|
// src/errors/notFoundError.js
|
|
56
74
|
var NotFoundError = class _NotFoundError extends AppError {
|
|
75
|
+
static {
|
|
76
|
+
__name(this, "NotFoundError");
|
|
77
|
+
}
|
|
57
78
|
constructor(message = "Resource Not Found", options = {}) {
|
|
58
79
|
super(message, options);
|
|
59
80
|
this.statusCode = 404;
|
|
@@ -64,6 +85,9 @@ var NotFoundError = class _NotFoundError extends AppError {
|
|
|
64
85
|
|
|
65
86
|
// src/errors/requestError.js
|
|
66
87
|
var RequestError = class _RequestError extends AppError {
|
|
88
|
+
static {
|
|
89
|
+
__name(this, "RequestError");
|
|
90
|
+
}
|
|
67
91
|
constructor(message = "Bad Request", options = {}) {
|
|
68
92
|
super(message, options);
|
|
69
93
|
this.statusCode = 400;
|
|
@@ -74,6 +98,9 @@ var RequestError = class _RequestError extends AppError {
|
|
|
74
98
|
|
|
75
99
|
// src/errors/systemCommError.js
|
|
76
100
|
var SystemCommError = class _SystemCommError extends AppError {
|
|
101
|
+
static {
|
|
102
|
+
__name(this, "SystemCommError");
|
|
103
|
+
}
|
|
77
104
|
constructor(message = "System Communication Error", options = {}) {
|
|
78
105
|
super(message, options);
|
|
79
106
|
this.statusCode = 503;
|
|
@@ -84,6 +111,9 @@ var SystemCommError = class _SystemCommError extends AppError {
|
|
|
84
111
|
|
|
85
112
|
// src/errors/tokenExpiredError.js
|
|
86
113
|
var TokenExpiredError = class _TokenExpiredError extends AppError {
|
|
114
|
+
static {
|
|
115
|
+
__name(this, "TokenExpiredError");
|
|
116
|
+
}
|
|
87
117
|
constructor(message = "Token Expired", options = {}) {
|
|
88
118
|
super(message, options);
|
|
89
119
|
this.statusCode = 401;
|
|
@@ -94,6 +124,9 @@ var TokenExpiredError = class _TokenExpiredError extends AppError {
|
|
|
94
124
|
|
|
95
125
|
// src/errors/unprocessableRequestError.js
|
|
96
126
|
var UnprocessableRequestError = class _UnprocessableRequestError extends AppError {
|
|
127
|
+
static {
|
|
128
|
+
__name(this, "UnprocessableRequestError");
|
|
129
|
+
}
|
|
97
130
|
constructor(message = "Unprocessable Request Error", options = {}) {
|
|
98
131
|
super(message, options);
|
|
99
132
|
this.statusCode = 422;
|
|
@@ -114,4 +147,4 @@ export {
|
|
|
114
147
|
TokenExpiredError,
|
|
115
148
|
UnprocessableRequestError
|
|
116
149
|
};
|
|
117
|
-
//# sourceMappingURL=chunk-
|
|
150
|
+
//# sourceMappingURL=chunk-SORMAXAX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/authenticationError.js","../src/errors/authorizationError.js","../src/errors/conflictError.js","../src/errors/deviceCommError.js","../src/errors/loginError.js","../src/errors/notFoundError.js","../src/errors/requestError.js","../src/errors/systemCommError.js","../src/errors/tokenExpiredError.js","../src/errors/unprocessableRequestError.js"],"sourcesContent":["import { AppError } from \"./appError\";\n\nexport class AuthenticationError extends AppError {\n constructor(message = \"Authentication Error\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class AuthorizationError extends AppError {\n constructor(message = \"Authorization Error\", options = {}) {\n super(message, options);\n this.statusCode = 403;\n this.name = \"AuthorizationError\";\n Object.setPrototypeOf(this, AuthorizationError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class ConflictError extends AppError {\n constructor(message = \"Bad Request\", options = {}) {\n super(message, options);\n this.statusCode = 409;\n this.name = \"ConflictError\";\n Object.setPrototypeOf(this, ConflictError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class DeviceCommError extends AppError {\n constructor(message = \"Device Communication Error\", options = {}) {\n super(message, options);\n this.statusCode = 503;\n this.name = \"DeviceCommError\";\n Object.setPrototypeOf(this, DeviceCommError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class LoginError extends AppError {\n constructor(message = \"Invalid Login information provided\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"LoginError\";\n Object.setPrototypeOf(this, LoginError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class NotFoundError extends AppError {\n constructor(message = \"Resource Not Found\", options = {}) {\n super(message, options);\n this.statusCode = 404;\n this.name = \"NotFoundError\";\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class RequestError extends AppError {\n constructor(message = \"Bad Request\", options = {}) {\n super(message, options);\n this.statusCode = 400;\n this.name = \"RequestError\";\n Object.setPrototypeOf(this, RequestError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class SystemCommError extends AppError {\n constructor(message = \"System Communication Error\", options = {}) {\n super(message, options);\n this.statusCode = 503;\n this.name = \"SystemCommError\";\n Object.setPrototypeOf(this, SystemCommError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class TokenExpiredError extends AppError {\n constructor(message = \"Token Expired\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"TokenExpiredError\";\n Object.setPrototypeOf(this, TokenExpiredError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class UnprocessableRequestError extends AppError {\n constructor(message = \"Unprocessable Request Error\", options = {}) {\n super(message, options);\n this.statusCode = 422;\n this.name = \"UnprocessableRequestError\";\n Object.setPrototypeOf(this, UnprocessableRequestError.prototype);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/errors/authenticationError.js","../src/errors/authorizationError.js","../src/errors/conflictError.js","../src/errors/deviceCommError.js","../src/errors/loginError.js","../src/errors/notFoundError.js","../src/errors/requestError.js","../src/errors/systemCommError.js","../src/errors/tokenExpiredError.js","../src/errors/unprocessableRequestError.js"],"sourcesContent":["import { AppError } from \"./appError\";\n\nexport class AuthenticationError extends AppError {\n constructor(message = \"Authentication Error\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class AuthorizationError extends AppError {\n constructor(message = \"Authorization Error\", options = {}) {\n super(message, options);\n this.statusCode = 403;\n this.name = \"AuthorizationError\";\n Object.setPrototypeOf(this, AuthorizationError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class ConflictError extends AppError {\n constructor(message = \"Bad Request\", options = {}) {\n super(message, options);\n this.statusCode = 409;\n this.name = \"ConflictError\";\n Object.setPrototypeOf(this, ConflictError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class DeviceCommError extends AppError {\n constructor(message = \"Device Communication Error\", options = {}) {\n super(message, options);\n this.statusCode = 503;\n this.name = \"DeviceCommError\";\n Object.setPrototypeOf(this, DeviceCommError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class LoginError extends AppError {\n constructor(message = \"Invalid Login information provided\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"LoginError\";\n Object.setPrototypeOf(this, LoginError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class NotFoundError extends AppError {\n constructor(message = \"Resource Not Found\", options = {}) {\n super(message, options);\n this.statusCode = 404;\n this.name = \"NotFoundError\";\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class RequestError extends AppError {\n constructor(message = \"Bad Request\", options = {}) {\n super(message, options);\n this.statusCode = 400;\n this.name = \"RequestError\";\n Object.setPrototypeOf(this, RequestError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class SystemCommError extends AppError {\n constructor(message = \"System Communication Error\", options = {}) {\n super(message, options);\n this.statusCode = 503;\n this.name = \"SystemCommError\";\n Object.setPrototypeOf(this, SystemCommError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class TokenExpiredError extends AppError {\n constructor(message = \"Token Expired\", options = {}) {\n super(message, options);\n this.statusCode = 401;\n this.name = \"TokenExpiredError\";\n Object.setPrototypeOf(this, TokenExpiredError.prototype);\n }\n}\n","import { AppError } from \"./appError\";\n\nexport class UnprocessableRequestError extends AppError {\n constructor(message = \"Unprocessable Request Error\", options = {}) {\n super(message, options);\n this.statusCode = 422;\n this.name = \"UnprocessableRequestError\";\n Object.setPrototypeOf(this, UnprocessableRequestError.prototype);\n }\n}\n"],"mappings":";;;;;;;;AAEO,IAAM,sBAAN,MAAM,6BAA4B,SAAS;AAAA,EAFlD,OAEkD;AAAA;AAAA;AAAA,EAChD,YAAY,UAAU,wBAAwB,UAAU,CAAC,GAAG;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,WAAO,eAAe,M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ACF;;;ACPO,IAAM,eAAN,MAAM,sBAAqB,SAAS;AAAA,EAF3C,OAE2C;AAAA;AAAA;AAAA,EACzC,YAAY,UAAU,eAAe,UAAU,CAAC,GAAG;AACjD,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,cAAa,SAAS;AAAA,EACpD;AACF;;;ACPO,IAAM,kBAAN,MAAM,yBAAwB,SAAS;AAAA,EAF9C,OAE8C;AAAA;AAAA;AAAA,EAC5C,YAAY,UAAU,8BAA8B,UAAU,CAAC,GAAG;AAChE,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,iBAAgB,SAAS;AAAA,EACvD;AACF;;;ACPO,IAAM,oBAAN,MAAM,2BAA0B,SAAS;AAAA,EAFhD,OAEgD;AAAA;AAAA;AAAA,EAC9C,YAAY,UAAU,iBAAiB,UAAU,CAAC,GAAG;AACnD,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,mBAAkB,SAAS;AAAA,EACzD;AACF;;;ACPO,IAAM,4BAAN,MAAM,mCAAkC,SAAS;AAAA,EAFxD,OAEwD;AAAA;AAAA;AAAA,EACtD,YAAY,UAAU,+BAA+B,UAAU,CAAC,GAAG;AACjE,UAAM,SAAS,OAAO;AACtB,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,2BAA0B,SAAS;AAAA,EACjE;AACF;","names":[]}
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
amqpExchanges
|
|
3
3
|
} from "./chunk-KNSZIQXT.js";
|
|
4
4
|
import {
|
|
5
|
-
__export
|
|
6
|
-
|
|
5
|
+
__export,
|
|
6
|
+
__name
|
|
7
|
+
} from "./chunk-FU4IK6I4.js";
|
|
7
8
|
|
|
8
9
|
// src/events/index.js
|
|
9
10
|
var events_exports = {};
|
|
@@ -31,17 +32,20 @@ __export(events_exports, {
|
|
|
31
32
|
SystemMotionSensorUpdated: () => SystemMotionSensorUpdated,
|
|
32
33
|
SystemOrganizationUpdated: () => SystemOrganizationUpdated,
|
|
33
34
|
SystemProductUpdated: () => SystemProductUpdated,
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
SystemPropertyUpdated: () => SystemPropertyUpdated,
|
|
36
|
+
SystemReservationUpdated: () => SystemReservationUpdated,
|
|
36
37
|
SystemSpaceUpdate: () => SystemSpaceUpdate,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
SystemSwitchUpdated: () => SystemSwitchUpdated,
|
|
39
|
+
SystemThermostatUpdated: () => SystemThermostatUpdated,
|
|
40
|
+
SystemUserUpdated: () => SystemUserUpdated,
|
|
41
|
+
SystemWindowCoveringUpdated: () => SystemWindowCoveringUpdated
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
// src/events/event.js
|
|
44
45
|
var Event = class {
|
|
46
|
+
static {
|
|
47
|
+
__name(this, "Event");
|
|
48
|
+
}
|
|
45
49
|
constructor(data, context = {}) {
|
|
46
50
|
this.data = [];
|
|
47
51
|
this.context = context;
|
|
@@ -376,7 +380,7 @@ var SystemProductUpdated = class extends Event {
|
|
|
376
380
|
};
|
|
377
381
|
|
|
378
382
|
// src/events/systemPropertyUpdated.js
|
|
379
|
-
var
|
|
383
|
+
var SystemPropertyUpdated = class extends Event {
|
|
380
384
|
constructor(property, context) {
|
|
381
385
|
super(property, context);
|
|
382
386
|
}
|
|
@@ -389,7 +393,7 @@ var SystemPropertyUpdate = class extends Event {
|
|
|
389
393
|
};
|
|
390
394
|
|
|
391
395
|
// src/events/systemReservationUpdated.js
|
|
392
|
-
var
|
|
396
|
+
var SystemReservationUpdated = class extends Event {
|
|
393
397
|
constructor(reservation, context) {
|
|
394
398
|
super(reservation, context);
|
|
395
399
|
}
|
|
@@ -415,7 +419,7 @@ var SystemSpaceUpdate = class extends Event {
|
|
|
415
419
|
};
|
|
416
420
|
|
|
417
421
|
// src/events/systemSwitchUpdated.js
|
|
418
|
-
var
|
|
422
|
+
var SystemSwitchUpdated = class extends Event {
|
|
419
423
|
constructor(_switch, context) {
|
|
420
424
|
super(_switch, context);
|
|
421
425
|
}
|
|
@@ -428,7 +432,7 @@ var SystemSwitchUpdate = class extends Event {
|
|
|
428
432
|
};
|
|
429
433
|
|
|
430
434
|
// src/events/systemThermostatUpdated.js
|
|
431
|
-
var
|
|
435
|
+
var SystemThermostatUpdated = class extends Event {
|
|
432
436
|
constructor(thermostat, context) {
|
|
433
437
|
super(thermostat, context);
|
|
434
438
|
}
|
|
@@ -441,7 +445,7 @@ var SystemThermostatUpdate = class extends Event {
|
|
|
441
445
|
};
|
|
442
446
|
|
|
443
447
|
// src/events/systemUserUpdated.js
|
|
444
|
-
var
|
|
448
|
+
var SystemUserUpdated = class extends Event {
|
|
445
449
|
constructor(user, context) {
|
|
446
450
|
super(user, context);
|
|
447
451
|
}
|
|
@@ -454,7 +458,7 @@ var SystemUserUpdate = class extends Event {
|
|
|
454
458
|
};
|
|
455
459
|
|
|
456
460
|
// src/events/systemWindowCoveringUpdated.js
|
|
457
|
-
var
|
|
461
|
+
var SystemWindowCoveringUpdated = class extends Event {
|
|
458
462
|
constructor(wc, context) {
|
|
459
463
|
super(wc, context);
|
|
460
464
|
}
|
|
@@ -490,13 +494,13 @@ export {
|
|
|
490
494
|
SystemMotionSensorUpdated,
|
|
491
495
|
SystemOrganizationUpdated,
|
|
492
496
|
SystemProductUpdated,
|
|
493
|
-
|
|
494
|
-
|
|
497
|
+
SystemPropertyUpdated,
|
|
498
|
+
SystemReservationUpdated,
|
|
495
499
|
SystemSpaceUpdate,
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
+
SystemSwitchUpdated,
|
|
501
|
+
SystemThermostatUpdated,
|
|
502
|
+
SystemUserUpdated,
|
|
503
|
+
SystemWindowCoveringUpdated,
|
|
500
504
|
events_exports
|
|
501
505
|
};
|
|
502
|
-
//# sourceMappingURL=chunk-
|
|
506
|
+
//# sourceMappingURL=chunk-TBEXLKDH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/events/index.js","../src/events/event.js","../src/events/applicationInUse.js","../src/events/applicationOutOfUse.js","../src/events/emailEvent.js","../src/events/reservationCheckedIn.js","../src/events/reservationCheckedOut.js","../src/events/reservationSpaceChanged.js","../src/events/sceneSet.js","../src/events/shortLinkCreated.js","../src/events/smsEvent.js","../src/events/systemAlarmUpdated.js","../src/events/systemCameraUpdated.js","../src/events/systemCategoryUpdated.js","../src/events/systemCourtesyUpdated.js","../src/events/systemCredentialUpdated.js","../src/events/systemDimmerUpdated.js","../src/events/systemEntityDeleted.js","../src/events/systemGatewayUpdated.js","../src/events/systemLockUpdated.js","../src/events/systemMediaSourceUpdated.js","../src/events/systemMotionSensorUpdated.js","../src/events/systemOrganizationUpdated.js","../src/events/systemProductUpdated.js","../src/events/systemPropertyUpdated.js","../src/events/systemReservationUpdated.js","../src/events/systemSpaceUpdated.js","../src/events/systemSwitchUpdated.js","../src/events/systemThermostatUpdated.js","../src/events/systemUserUpdated.js","../src/events/systemWindowCoveringUpdated.js"],"sourcesContent":["// This file is auto-generated. Do not edit this file manually.\n// Generated on: 2025-01-08T15:34:00.338Z\n\nexport { ApplicationInUse } from \"./applicationInUse\";\nexport { ApplicationOutOfUse } from \"./applicationOutOfUse\";\nexport { EmailEvent } from \"./emailEvent\";\nexport { Event } from \"./event\";\nexport { ReservationCheckedIn } from \"./reservationCheckedIn\";\nexport { ReservationCheckedOut } from \"./reservationCheckedOut\";\nexport { ReservationSpaceChanged } from \"./reservationSpaceChanged\";\nexport { SceneSet } from \"./sceneSet\";\nexport { ShortLinkCreated } from \"./shortLinkCreated\";\nexport { SMSEvent } from \"./smsEvent\";\nexport { SystemAlarmUpdated } from \"./systemAlarmUpdated\";\nexport { SystemCameraUpdated } from \"./systemCameraUpdated\";\nexport { SystemCategoryUpdated } from \"./systemCategoryUpdated\";\nexport { SystemCourtesyUpdated } from \"./systemCourtesyUpdated\";\nexport { SystemCredentialUpdated } from \"./systemCredentialUpdated\";\nexport { SystemDimmerUpdated } from \"./systemDimmerUpdated\";\nexport { SystemEntityDeleted } from \"./systemEntityDeleted\";\nexport { SystemGatewayUpdated } from \"./systemGatewayUpdated\";\nexport { SystemLockUpdated } from \"./systemLockUpdated\";\nexport { SystemMediaSourceUpdated } from \"./systemMediaSourceUpdated\";\nexport { SystemMotionSensorUpdated } from \"./systemMotionSensorUpdated\";\nexport { SystemOrganizationUpdated } from \"./systemOrganizationUpdated\";\nexport { SystemProductUpdated } from \"./systemProductUpdated\";\nexport { SystemPropertyUpdated } from \"./systemPropertyUpdated\";\nexport { SystemReservationUpdated } from \"./systemReservationUpdated\";\nexport { SystemSpaceUpdate } from \"./systemSpaceUpdated\";\nexport { SystemSwitchUpdated } from \"./systemSwitchUpdated\";\nexport { SystemThermostatUpdated } from \"./systemThermostatUpdated\";\nexport { SystemUserUpdated } from \"./systemUserUpdated\";\nexport { SystemWindowCoveringUpdated } from \"./systemWindowCoveringUpdated\";","import { amqpExchanges } from \"../defs\";\n\nexport class Event {\n constructor(data, context = {}) {\n this.data = [];\n this.context = context;\n if (!data) throw new Error(\"Event data is required\");\n if (typeof data !== \"object\" && !Array.isArray(data))\n throw new Error(\"Event data must be an object or array\");\n\n if (!Array.isArray(data)) this.data = [data];\n else this.data = data;\n }\n\n get organizationId() {\n return this.context.organizationId || \"*\";\n }\n\n get propertyId() {\n return this.context.propertyId || \"*\";\n }\n\n static get type() {\n return \"Event\";\n }\n\n static get exchange() {\n return amqpExchanges.DriverEvents.name;\n }\n\n static get entity() {\n return \"\";\n }\n\n build() {\n return { data: { ...this.data } };\n }\n\n get routingKey() {\n return `${this.organizationId}.${this.propertyId}.${this.constructor.entity}.${this.constructor.name}`;\n }\n}\n","import { amqpExchanges } from \"../defs\";\nimport { Event } from \"./event\";\n\nexport class ApplicationInUse extends Event {\n constructor(data = {}, context) {\n super(data, context);\n }\n\n static get name() {\n return \"ApplicationInUse\";\n }\n\n static get entity() {\n return \"app\";\n }\n\n static get exchange() {\n return amqpExchanges.AppEvents.name;\n }\n}\n","import { amqpExchanges } from \"../defs\";\nimport { Event } from \"./event\";\n\nexport class ApplicationOutOfUse extends Event {\n constructor(data = {}, context = {}) {\n super(data, context);\n }\n\n static get name() {\n return \"ApplicationOutOfUse\";\n }\n\n static get entity() {\n return \"app\";\n }\n\n static get exchange() {\n return amqpExchanges.AppEvents.name;\n }\n}\n","import { Event } from \"./event\";\n\nexport class EmailEvent extends Event {\n constructor(email, context) {\n super(email, context);\n }\n\n static get name() {\n return \"EmailEvent\";\n }\n\n static get entity() {\n return \"emailMessage\";\n }\n}\n","import { amqpExchanges } from \"../defs\";\nimport { Event } from \"./event\";\n\nexport class ReservationCheckedIn extends Event {\n constructor(reservation, context) {\n super(reservation, context);\n }\n\n static get name() {\n return \"ReservationCheckedIn\";\n }\n\n static get entity() {\n return \"reservation\";\n }\n\n static get exchange() {\n return amqpExchanges.AppEvents.name;\n }\n}\n","import { amqpExchanges } from \"../defs\";\nimport { Event } from \"./event\";\n\nexport class ReservationCheckedOut extends Event {\n constructor(reservation, context) {\n super(reservation, context);\n }\n\n static get name() {\n return \"ReservationCheckedOut\";\n }\n\n static get entity() {\n return \"reservation\";\n }\n\n static get exchange() {\n return amqpExchanges.AppEvents.name;\n }\n}\n","import { amqpExchanges } from \"../defs\";\nimport { Event } from \"./event\";\n\nexport class ReservationSpaceChanged extends Event {\n constructor(reservation, context) {\n super(reservation, context);\n }\n\n static get name() {\n return \"ReservationSpaceChanged\";\n }\n\n static get entity() {\n return \"reservation\";\n }\n\n static get exchange() {\n return amqpExchanges.AppEvents.name;\n }\n}\n","import { Event } from \"./event\";\n\nexport class SceneSet extends Event {\n constructor(scene, context) {\n super(scene, context);\n }\n\n static get name() {\n return \"SceneSet\";\n }\n\n static get entity() {\n return \"scene\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class ShortLinkCreated extends Event {\n constructor(shortLink, context) {\n super(shortLink, context);\n }\n\n static get name() {\n return \"ShortLinkCreated\";\n }\n\n static get entity() {\n return \"shortLink\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SMSEvent extends Event {\n constructor(sms, context) {\n super(sms, context);\n }\n\n static get name() {\n return \"SMSEvent\";\n }\n\n static get entity() {\n return \"smsMessage\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemAlarmUpdated extends Event {\n constructor(alarm, context) {\n super(alarm, context);\n }\n\n static get name() {\n return \"SystemAlarmUpdated\";\n }\n\n static get entity() {\n return \"alarm\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemCameraUpdated extends Event {\n constructor(camera, context) {\n super(camera, context);\n }\n\n static get name() {\n return \"SystemCameraUpdated\";\n }\n\n static get entity() {\n return \"camera\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemCategoryUpdated extends Event {\n constructor(category, context) {\n super(category, context);\n }\n\n static get name() {\n return \"SystemCategoryUpdated\";\n }\n\n static get entity() {\n return \"category\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemCourtesyUpdated extends Event {\n constructor(courtesy, context) {\n super(courtesy, context);\n }\n\n static get name() {\n return \"SystemCourtesyUpdated\";\n }\n\n static get entity() {\n return \"courtesy\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemCredentialUpdated extends Event {\n constructor(cred, context) {\n super(cred, context);\n }\n\n static get name() {\n return \"SystemCredentialUpdated\";\n }\n\n static get entity() {\n return \"credential\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemDimmerUpdated extends Event {\n constructor(dimmer, context) {\n super(dimmer, context);\n }\n\n static get name() {\n return \"SystemDimmerUpdated\";\n }\n\n static get entity() {\n return \"dimmer\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemEntityDeleted extends Event {\n constructor(data, context) {\n super(data, context);\n }\n\n static get name() {\n return \"SystemEntityDeleted\";\n }\n\n static get entity() {\n return \"entity\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemGatewayUpdated extends Event {\n constructor(gateway, context) {\n super(gateway, context);\n }\n\n static get name() {\n return \"SystemGatewayUpdated\";\n }\n\n static get entity() {\n return \"gateway\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemLockUpdated extends Event {\n constructor(lock, context) {\n super(lock, context);\n }\n\n static get name() {\n return \"SystemLockUpdated\";\n }\n\n static get entity() {\n return \"lock\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemMediaSourceUpdated extends Event {\n constructor(mediaSource, context) {\n super(mediaSource, context);\n }\n\n static get name() {\n return \"SystemMediaSourceUpdated\";\n }\n\n static get entity() {\n return \"mediaSource\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemMotionSensorUpdated extends Event {\n constructor(motion, context) {\n super(motion, context);\n }\n\n static get name() {\n return \"SystemMotionSensorUpdated\";\n }\n\n static get entity() {\n return \"motionSensor\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemOrganizationUpdated extends Event {\n constructor(organization, context) {\n super(organization, context);\n }\n\n static get name() {\n return \"SystemOrganizationUpdated\";\n }\n\n static get entity() {\n return \"organization\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemProductUpdated extends Event {\n constructor(product, context) {\n super(product, context);\n }\n\n static get name() {\n return \"SystemProductUpdated\";\n }\n\n static get entity() {\n return \"product\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemPropertyUpdated extends Event {\n constructor(property, context) {\n super(property, context);\n }\n\n static get name() {\n return \"SystemPropertyUpdated\";\n }\n\n static get entity() {\n return \"property\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemReservationUpdated extends Event {\n constructor(reservation, context) {\n super(reservation, context);\n }\n\n static get name() {\n return \"SystemReservationUpdated\";\n }\n\n static get entity() {\n return \"reservation\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemSpaceUpdate extends Event {\n constructor(space, context) {\n super(space, context);\n }\n\n static get name() {\n return \"SystemSpaceUpdated\";\n }\n\n static get entity() {\n return \"space\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemSwitchUpdated extends Event {\n constructor(_switch, context) {\n super(_switch, context);\n }\n\n static get name() {\n return \"SystemSwitchUpdated\";\n }\n\n static get entity() {\n return \"switch\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemThermostatUpdated extends Event {\n constructor(thermostat, context) {\n super(thermostat, context);\n }\n\n static get name() {\n return \"SystemThermostatUpdated\";\n }\n\n static get entity() {\n return \"thermostat\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemUserUpdated extends Event {\n constructor(user, context) {\n super(user, context);\n }\n\n static get name() {\n return \"SystemUserUpdated\";\n }\n\n static get entity() {\n return \"user\";\n }\n}\n","import { Event } from \"./event\";\n\nexport class SystemWindowCoveringUpdated extends Event {\n constructor(wc, context) {\n super(wc, context);\n }\n\n static get name() {\n return \"SystemWindowCoveringUpdated\";\n }\n\n static get entity() {\n return \"windowCovering\";\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,QAAN,MAAY;AAAA,EAFnB,OAEmB;AAAA;AAAA;AAAA,EACjB,YAAY,MAAM,UAAU,CAAC,GAAG;AAC9B,SAAK,OAAO,CAAC;AACb,SAAK,UAAU;AACf,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,wBAAwB;AACnD,QAAI,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI;AACjD,YAAM,IAAI,MAAM,uCAAuC;AAEzD,QAAI,CAAC,MAAM,QAAQ,IAAI,EAAG,MAAK,OAAO,C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AAN,cAAsC,MAAM;AAAA,EACjD,YAAY,YAAY,SAAS;AAC/B,UAAM,YAAY,OAAO;AAAA,EAC3B;AAAA,EAEA,WAAW,OAAO;AAChB,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,SAAS;AAClB,WAAO;AAAA,EACT;AACF;;;ACZO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,MAAM,SAAS;AACzB,UAAM,MAAM,OAAO;AAAA,EACrB;AAAA,EAEA,WAAW,OAAO;AAChB,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,SAAS;AAClB,WAAO;AAAA,EACT;AACF;;;ACZO,IAAM,8BAAN,cAA0C,MAAM;AAAA,EACrD,YAAY,IAAI,SAAS;AACvB,UAAM,IAAI,OAAO;AAAA,EACnB;AAAA,EAEA,WAAW,OAAO;AAChB,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,SAAS;AAClB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-FU4IK6I4.js";
|
|
4
|
+
|
|
1
5
|
// src/useCases/refreshToken.js
|
|
2
6
|
var RefreshTokenCommand = class _RefreshTokenCommand {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "RefreshTokenCommand");
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* @description
|
|
5
12
|
* @constructor
|
|
@@ -64,4 +71,4 @@ var RefreshTokenCommand = class _RefreshTokenCommand {
|
|
|
64
71
|
export {
|
|
65
72
|
RefreshTokenCommand
|
|
66
73
|
};
|
|
67
|
-
//# sourceMappingURL=chunk-
|
|
74
|
+
//# sourceMappingURL=chunk-UZQ2AWUY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useCases/refreshToken.js"],"sourcesContent":["/* @ts-nocheck */\n/* This file is automatically generated. Do not modify it manually. */\n\nexport class RefreshTokenCommand {\n /**\n * @description\n * @constructor\n * @typedef {object} RefreshTokenCommandConfig\n * @property {{[key: string]: any}} data - The body to include in the command\n * @property {{[key:string]: any} | null} [headers] - The headers to include in the command\n * @property {{[key:string]: any} | null} [query] - The query parameters to include in the command\n *\n * @param {RefreshTokenCommandConfig} commandConfig - The options to include in the command\n * @param {Object} options - The options to include in the command\n */\n constructor(commandConfig, options = {}) {\n // get parameters from path\n const pathParams = RefreshTokenCommand.params;\n\n let { data, query, headers } = commandConfig ?? {};\n\n if (typeof data === \"undefined\") data = null;\n if (typeof query === \"undefined\") query = null;\n if (typeof headers === \"undefined\") headers = null;\n\n // replace path parameters with values from params\n let url = RefreshTokenCommand.url;\n\n if (pathParams && data) {\n for (const param of pathParams) {\n const urlParam = \":\" + param;\n url = url.replace(urlParam, data[param]);\n }\n }\n\n // make sure all parameters have been replaced\n if (url.match(/:[a-zA-Z0-9]+/g)) {\n const missingParams = url.match(/:[a-zA-Z0-9]+/g);\n\n if (missingParams) {\n // remove the colon from the parameter name\n const missing = missingParams.map((param) => param.replace(\":\", \"\"));\n throw new Error(\"Missing parameters: \" + missing.join(\", \"));\n }\n }\n\n /**\n * The full URL for the use case\n * @type {string}\n * @public\n */\n this.url = url;\n /**\n * The data to send with the use case\n * @type {RefreshTokenCommandConfig[\"data\"]}\n * @public\n */\n this.data = data;\n /**\n * The query parameters for the use case\n * @type {RefreshTokenCommandConfig[\"query\"]}\n * @public\n */\n this.query = query;\n /**\n * The headers for the use case\n * @type {RefreshTokenCommandConfig[\"headers\"]}\n * @public\n */\n this.headers = headers;\n\n /**\n * The configuration for the use case command\n * @type {{ url: string, method: \"post\" , data: RefreshTokenCommandConfig[\"data\"] , params: RefreshTokenCommandConfig[\"query\"], headers: RefreshTokenCommandConfig[\"headers\"] }}\n * @public\n */\n this.config = {\n method: RefreshTokenCommand.method,\n url: url,\n data: data,\n params: query,\n headers: headers,\n ...options,\n };\n }\n\n /**\n * The required parameters for the use case\n * @type {string[]}\n */\n static params = [];\n\n /**\n * The URL for the use case, with path parameters\n * @type {string}\n */\n static url = \"/auth/refresh\";\n\n /**\n * The HTTP method for the use case\n * @type {\"post\"}\n */\n static method = \"post\";\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/useCases/refreshToken.js"],"sourcesContent":["/* @ts-nocheck */\n/* This file is automatically generated. Do not modify it manually. */\n\nexport class RefreshTokenCommand {\n /**\n * @description\n * @constructor\n * @typedef {object} RefreshTokenCommandConfig\n * @property {{[key: string]: any}} data - The body to include in the command\n * @property {{[key:string]: any} | null} [headers] - The headers to include in the command\n * @property {{[key:string]: any} | null} [query] - The query parameters to include in the command\n *\n * @param {RefreshTokenCommandConfig} commandConfig - The options to include in the command\n * @param {Object} options - The options to include in the command\n */\n constructor(commandConfig, options = {}) {\n // get parameters from path\n const pathParams = RefreshTokenCommand.params;\n\n let { data, query, headers } = commandConfig ?? {};\n\n if (typeof data === \"undefined\") data = null;\n if (typeof query === \"undefined\") query = null;\n if (typeof headers === \"undefined\") headers = null;\n\n // replace path parameters with values from params\n let url = RefreshTokenCommand.url;\n\n if (pathParams && data) {\n for (const param of pathParams) {\n const urlParam = \":\" + param;\n url = url.replace(urlParam, data[param]);\n }\n }\n\n // make sure all parameters have been replaced\n if (url.match(/:[a-zA-Z0-9]+/g)) {\n const missingParams = url.match(/:[a-zA-Z0-9]+/g);\n\n if (missingParams) {\n // remove the colon from the parameter name\n const missing = missingParams.map((param) => param.replace(\":\", \"\"));\n throw new Error(\"Missing parameters: \" + missing.join(\", \"));\n }\n }\n\n /**\n * The full URL for the use case\n * @type {string}\n * @public\n */\n this.url = url;\n /**\n * The data to send with the use case\n * @type {RefreshTokenCommandConfig[\"data\"]}\n * @public\n */\n this.data = data;\n /**\n * The query parameters for the use case\n * @type {RefreshTokenCommandConfig[\"query\"]}\n * @public\n */\n this.query = query;\n /**\n * The headers for the use case\n * @type {RefreshTokenCommandConfig[\"headers\"]}\n * @public\n */\n this.headers = headers;\n\n /**\n * The configuration for the use case command\n * @type {{ url: string, method: \"post\" , data: RefreshTokenCommandConfig[\"data\"] , params: RefreshTokenCommandConfig[\"query\"], headers: RefreshTokenCommandConfig[\"headers\"] }}\n * @public\n */\n this.config = {\n method: RefreshTokenCommand.method,\n url: url,\n data: data,\n params: query,\n headers: headers,\n ...options,\n };\n }\n\n /**\n * The required parameters for the use case\n * @type {string[]}\n */\n static params = [];\n\n /**\n * The URL for the use case, with path parameters\n * @type {string}\n */\n static url = \"/auth/refresh\";\n\n /**\n * The HTTP method for the use case\n * @type {\"post\"}\n */\n static method = \"post\";\n}\n"],"mappings":";;;;;AAGO,IAAM,sBAAN,MAAM,qBAAoB;AAAA,EAHjC,OAGiC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY/B,YAAY,eAAe,UAAU,CAAC,GAAG;AAEvC,UAAM,aAAa,qBAAoB;AAEvC,QAAI,EAAE,MAAM,OAAO,QAAQ,IAAI,iBAAiB,CAAC;AAEjD,QAAI,OAAO,SAAS,YAAa,QAAO;AACxC,QAAI,OAAO,UAAU,YAAa,SAAQ;AAC1C,QAAI,OAAO,YAAY,YAAa,WAAU;AAG9C,QAAI,MAAM,qBAAoB;AAE9B,QAAI,cAAc,MAAM;AACtB,iBAAW,SAAS,YAAY;AAC9B,cAAM,WAAW,MAAM;AACvB,cAAM,IAAI,QAAQ,UAAU,KAAK,KAAK,CAAC;AAAA,MACzC;AAAA,IACF;AAGA,QAAI,IAAI,MAAM,gBAAgB,GAAG;AAC/B,YAAM,gBAAgB,IAAI,MAAM,gBAAgB;AAEhD,UAAI,eAAe;AAEjB,cAAM,UAAU,cAAc,IAAI,CAAC,UAAU,MAAM,QAAQ,KAAK,EAAE,CAAC;AACnE,cAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,IAAI,CAAC;AAAA,MAC7D;AAAA,IACF;AAOA,SAAK,MAAM;AAMX,SAAK,OAAO;AAMZ,SAAK,QAAQ;AAMb,SAAK,UAAU;AAOf,SAAK,SAAS;AAAA,MACZ,QAAQ,qBAAoB;AAAA,MAC5B;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,SAAS,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAMb,OAAO,SAAS;AAClB;","names":[]}
|
package/dist/client.cjs
CHANGED
|
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
6
|
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,6 +26,9 @@ module.exports = __toCommonJS(httpClient_exports);
|
|
|
25
26
|
|
|
26
27
|
// src/useCases/refreshToken.js
|
|
27
28
|
var RefreshTokenCommand = class _RefreshTokenCommand {
|
|
29
|
+
static {
|
|
30
|
+
__name(this, "RefreshTokenCommand");
|
|
31
|
+
}
|
|
28
32
|
/**
|
|
29
33
|
* @description
|
|
30
34
|
* @constructor
|
|
@@ -88,6 +92,9 @@ var RefreshTokenCommand = class _RefreshTokenCommand {
|
|
|
88
92
|
|
|
89
93
|
// src/httpClient.js
|
|
90
94
|
var KohostHTTPClient = class _KohostHTTPClient {
|
|
95
|
+
static {
|
|
96
|
+
__name(this, "KohostHTTPClient");
|
|
97
|
+
}
|
|
91
98
|
#onSuccess;
|
|
92
99
|
#onError;
|
|
93
100
|
/**
|
|
@@ -106,8 +113,8 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
106
113
|
organizationId: "",
|
|
107
114
|
apiKey: "",
|
|
108
115
|
headers: new Headers({}),
|
|
109
|
-
onSuccess: (response) => response,
|
|
110
|
-
onError: (error) => error
|
|
116
|
+
onSuccess: /* @__PURE__ */ __name((response) => response, "onSuccess"),
|
|
117
|
+
onError: /* @__PURE__ */ __name((error) => error, "onError")
|
|
111
118
|
}) {
|
|
112
119
|
if (!options.url) throw new Error("options.url is required");
|
|
113
120
|
this.options = options;
|
|
@@ -197,7 +204,8 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
197
204
|
const commandConfig = command.config;
|
|
198
205
|
const request = this.createRequest(commandConfig);
|
|
199
206
|
const response = await fetch(request);
|
|
200
|
-
const
|
|
207
|
+
const isJsonResponse = response.headers.get("Content-Type")?.includes("application/json") || false;
|
|
208
|
+
const responseData = isJsonResponse ? await response.json() : response.body;
|
|
201
209
|
if (!response.ok) {
|
|
202
210
|
let error = responseData?.error || new Error(response.statusText);
|
|
203
211
|
const status = response.status;
|
|
@@ -237,7 +245,7 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
237
245
|
}
|
|
238
246
|
}
|
|
239
247
|
} catch (error2) {
|
|
240
|
-
console.
|
|
248
|
+
console.error(error2);
|
|
241
249
|
}
|
|
242
250
|
error = this.#onError(error);
|
|
243
251
|
return Promise.reject(error);
|
|
@@ -264,9 +272,33 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
264
272
|
}
|
|
265
273
|
const url = new URL(apiPath, this.baseUrl);
|
|
266
274
|
const method = config.method.toUpperCase() || "GET";
|
|
267
|
-
if (config.params) {
|
|
268
|
-
Object.
|
|
269
|
-
|
|
275
|
+
if (config.params && typeof config.params === "object") {
|
|
276
|
+
Object.entries(config.params).forEach(([key, value]) => {
|
|
277
|
+
if (Array.isArray(value)) {
|
|
278
|
+
value.forEach((item) => {
|
|
279
|
+
if (typeof item === "object" && item !== null) {
|
|
280
|
+
Object.entries(item).forEach(([itemKey, itemValue]) => {
|
|
281
|
+
url.searchParams.append(`${key}[][${itemKey}]`, itemValue);
|
|
282
|
+
});
|
|
283
|
+
} else {
|
|
284
|
+
url.searchParams.append(`${key}[]`, item);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
} else if (value === null || value === void 0) {
|
|
288
|
+
url.searchParams.append(key, "");
|
|
289
|
+
} else if (typeof value === "object") {
|
|
290
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
291
|
+
if (Array.isArray(nestedValue)) {
|
|
292
|
+
nestedValue.forEach((item) => {
|
|
293
|
+
url.searchParams.append(`${key}[${nestedKey}][]`, item);
|
|
294
|
+
});
|
|
295
|
+
} else {
|
|
296
|
+
url.searchParams.append(`${key}[${nestedKey}]`, nestedValue);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
} else {
|
|
300
|
+
url.searchParams.append(key, value);
|
|
301
|
+
}
|
|
270
302
|
});
|
|
271
303
|
}
|
|
272
304
|
const headers = new Headers(this.headers);
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/httpClient.js","../src/useCases/refreshToken.js"],"sourcesContent":["import { RefreshTokenCommand } from \"./useCases/refreshToken\";\n\nexport class KohostHTTPClient {\n #onSuccess;\n #onError;\n\n /** \n @param {Object} options - The options to create the client\n @param {String} options.organizationId - The organization ID\n @param {String} options.propertyId - The property ID\n @param {String | URL} options.url - The base URL for the API endpint\n @param {String} options.apiKey - The API key to use for requests\n @param {Headers} options.headers - Additional headers to send with each request\n @param {Function} options.onSuccess - A callback to handle successful responses\n @param {Function} options.onError - A callback to handle errors\n */\n constructor(\n options = {\n url: \"\",\n propertyId: \"\",\n organizationId: \"\",\n apiKey: \"\",\n headers: new Headers({}),\n onSuccess: (response) => response,\n onError: (error) => error,\n },\n ) {\n if (!options.url) throw new Error(\"options.url is required\");\n this.options = options;\n\n this.isAuthTokenRenewalActive = false;\n\n this.baseUrl = new URL(options.url);\n this.headers = new Headers({\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...options.headers,\n });\n\n if (options.apiKey) {\n this.headers.set(KohostHTTPClient.defs.apiKeyHeader, options.apiKey);\n }\n\n if (options.propertyId) {\n this.propertyId = options.propertyId;\n }\n\n if (options.organizationId) {\n this.organizationId = options.organizationId;\n }\n\n this.#onSuccess = options.onSuccess\n ? options.onSuccess\n : (response) => response;\n\n this.#onError = options.onError ? options.onError : (error) => error;\n\n this.callbacks = {};\n }\n\n /**\n *\n * @param {\"LoginRequired\" | \"PhoneVerificationRequired\"} event\n * @param {Function} callback\n */\n on(event, callback) {\n if (typeof callback !== \"function\") {\n throw new Error(\"Callback must be a function\");\n }\n if (!this.callbacks[event]) {\n this.callbacks[event] = [];\n }\n this.callbacks[event].push(callback);\n }\n\n emit(event, ...args) {\n if (this.callbacks[event]) {\n this.callbacks[event].forEach((callback) => callback(...args));\n }\n }\n\n /**\n * @param {string} orgId\n * @returns {void}\n * @memberof KohostApiClient\n * @example\n * client.organizationId = \"1234\";\n */\n set organizationId(orgId) {\n const key = KohostHTTPClient.defs.organizationHeader;\n this.headers.set(key, orgId);\n }\n\n get organizationId() {\n const key = KohostHTTPClient.defs.organizationHeader;\n return this.headers.get(key);\n }\n\n /**\n * @param {string} propertyId\n * @returns {void}\n * @memberof KohostApiClient\n * @example\n * client.propertyId = \"1234\";\n */\n\n set propertyId(propertyId) {\n const key = KohostHTTPClient.defs.propertyHeader;\n this.headers.set(key, propertyId);\n }\n\n get propertyId() {\n const key = KohostHTTPClient.defs.propertyHeader;\n return this.headers.get(key);\n }\n\n static get defs() {\n return {\n apiKeyHeader: \"X-Api-Key\",\n propertyHeader: \"X-Property-Id\",\n organizationHeader: \"X-Organization-Id\",\n };\n }\n\n /**\n * @typedef {keyof typeof import('./useCases')} CommandName\n * @typedef {import('./useCases')[CommandName]} Command\n *\n * @param {Command} command\n */\n async send(command) {\n const commandConfig = command.config;\n const request = this.createRequest(commandConfig);\n const response = await fetch(request);\n\n const responseData =\n response.headers.get(\"Content-Type\") === \"application/json\"\n ? await response.json()\n : response;\n\n if (!response.ok) {\n let error = responseData?.error || new Error(response.statusText);\n\n const status = response.status;\n const errorType = responseData.error?.type;\n const errorMessage = responseData?.error?.message;\n\n try {\n const expectedError = status >= 400 && status < 500;\n const newTokensNeeded =\n expectedError && errorType === \"TokenExpiredError\";\n\n if (\n expectedError &&\n errorMessage === \"Phone Verification is required\"\n ) {\n this.#onPhoneVerificationRequired();\n return Promise.reject(error);\n }\n\n if (expectedError && errorMessage === \"Login Required\") {\n this.#onLoginRequired();\n return Promise.reject(error);\n }\n\n if (\n expectedError &&\n errorMessage === \"No auth header or cookie provided\"\n ) {\n this.#onLoginRequired();\n return Promise.reject(error);\n }\n\n if (expectedError && newTokensNeeded) {\n while (!this.isAuthTokenRenewalActive) {\n this.isAuthTokenRenewalActive = true;\n return this.send(\n new RefreshTokenCommand({\n data: commandConfig.data,\n query: commandConfig.params,\n headers: commandConfig.headers,\n }),\n )\n .then(() => {\n // retry the original request with the new token\n this.isAuthTokenRenewalActive = false;\n return fetch(request.clone());\n })\n .catch((err) => {\n this.isAuthTokenRenewalActive = false;\n return Promise.reject(err);\n });\n }\n }\n } catch (error) {\n console.log(error);\n }\n\n error = this.#onError(error);\n\n return Promise.reject(error);\n }\n\n return this.#onSuccess(responseData);\n }\n\n #onLoginRequired() {\n this.emit(\"LoginRequired\");\n }\n\n #onPhoneVerificationRequired() {\n this.emit(\"PhoneVerificationRequired\");\n }\n\n /**\n * @param {Command} config\n * @returns {Request}\n */\n createRequest(config) {\n if (typeof config.headers !== \"object\") {\n config.headers = {};\n }\n\n let apiPath = config.url;\n\n if (apiPath.startsWith(\"/\")) {\n apiPath = `.${apiPath}`;\n }\n const url = new URL(apiPath, this.baseUrl);\n const method = config.method.toUpperCase() || \"GET\";\n\n if (config.params) {\n Object.keys(config.params).forEach((key) => {\n url.searchParams.append(key, config.params[key]);\n });\n }\n\n const headers = new Headers(this.headers);\n // Add any additional headers\n if (config.headers) {\n Object.keys(config.headers).forEach((key) => {\n headers.set(key, config.headers[key]);\n });\n }\n\n const body = [\"POST\", \"PUT\", \"PATCH\"].includes(method)\n ? headers.get(\"Content-Type\") === \"application/json\"\n ? JSON.stringify(config.data)\n : config.data\n : undefined;\n\n const request = new Request(url, {\n method: method,\n headers: headers,\n credentials: \"include\",\n body: body,\n });\n\n return request;\n }\n}\n","/* @ts-nocheck */\n/* This file is automatically generated. Do not modify it manually. */\n\nexport class RefreshTokenCommand {\n /**\n * @description\n * @constructor\n * @typedef {object} RefreshTokenCommandConfig\n * @property {{[key: string]: any}} data - The body to include in the command\n * @property {{[key:string]: any} | null} [headers] - The headers to include in the command\n * @property {{[key:string]: any} | null} [query] - The query parameters to include in the command\n *\n * @param {RefreshTokenCommandConfig} commandConfig - The options to include in the command\n * @param {Object} options - The options to include in the command\n */\n constructor(commandConfig, options = {}) {\n // get parameters from path\n const pathParams = RefreshTokenCommand.params;\n\n let { data, query, headers } = commandConfig ?? {};\n\n if (typeof data === \"undefined\") data = null;\n if (typeof query === \"undefined\") query = null;\n if (typeof headers === \"undefined\") headers = null;\n\n // replace path parameters with values from params\n let url = RefreshTokenCommand.url;\n\n if (pathParams && data) {\n for (const param of pathParams) {\n const urlParam = \":\" + param;\n url = url.replace(urlParam, data[param]);\n }\n }\n\n // make sure all parameters have been replaced\n if (url.match(/:[a-zA-Z0-9]+/g)) {\n const missingParams = url.match(/:[a-zA-Z0-9]+/g);\n\n if (missingParams) {\n // remove the colon from the parameter name\n const missing = missingParams.map((param) => param.replace(\":\", \"\"));\n throw new Error(\"Missing parameters: \" + missing.join(\", \"));\n }\n }\n\n /**\n * The full URL for the use case\n * @type {string}\n * @public\n */\n this.url = url;\n /**\n * The data to send with the use case\n * @type {RefreshTokenCommandConfig[\"data\"]}\n * @public\n */\n this.data = data;\n /**\n * The query parameters for the use case\n * @type {RefreshTokenCommandConfig[\"query\"]}\n * @public\n */\n this.query = query;\n /**\n * The headers for the use case\n * @type {RefreshTokenCommandConfig[\"headers\"]}\n * @public\n */\n this.headers = headers;\n\n /**\n * The configuration for the use case command\n * @type {{ url: string, method: \"post\" , data: RefreshTokenCommandConfig[\"data\"] , params: RefreshTokenCommandConfig[\"query\"], headers: RefreshTokenCommandConfig[\"headers\"] }}\n * @public\n */\n this.config = {\n method: RefreshTokenCommand.method,\n url: url,\n data: data,\n params: query,\n headers: headers,\n ...options,\n };\n }\n\n /**\n * The required parameters for the use case\n * @type {string[]}\n */\n static params = [];\n\n /**\n * The URL for the use case, with path parameters\n * @type {string}\n */\n static url = \"/auth/refresh\";\n\n /**\n * The HTTP method for the use case\n * @type {\"post\"}\n */\n static method = \"post\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,sBAAN,MAAM,qBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY/B,YAAY,eAAe,UAAU,CAAC,GAAG;AAEvC,UAAM,aAAa,qBAAoB;AAEvC,QAAI,EAAE,MAAM,OAAO,QAAQ,IAAI,iBAAiB,CAAC;AAEjD,QAAI,OAAO,SAAS,YAAa,QAAO;AACxC,QAAI,OAAO,UAAU,YAAa,SAAQ;AAC1C,QAAI,OAAO,YAAY,YAAa,WAAU;AAG9C,QAAI,MAAM,qBAAoB;AAE9B,QAAI,cAAc,MAAM;AACtB,iBAAW,SAAS,YAAY;AAC9B,cAAM,WAAW,MAAM;AACvB,cAAM,IAAI,QAAQ,UAAU,KAAK,KAAK,CAAC;AAAA,MACzC;AAAA,IACF;AAGA,QAAI,IAAI,MAAM,gBAAgB,GAAG;AAC/B,YAAM,gBAAgB,IAAI,MAAM,gBAAgB;AAEhD,UAAI,eAAe;AAEjB,cAAM,UAAU,cAAc,IAAI,CAAC,UAAU,MAAM,QAAQ,KAAK,EAAE,CAAC;AACnE,cAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,IAAI,CAAC;AAA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,WAAO;AAAA,EACT;AACF;","names":["error"]}
|
|
1
|
+
{"version":3,"sources":["../src/httpClient.js","../src/useCases/refreshToken.js"],"sourcesContent":["import { RefreshTokenCommand } from \"./useCases/refreshToken\";\n\nexport class KohostHTTPClient {\n #onSuccess;\n #onError;\n\n /** \n @param {Object} options - The options to create the client\n @param {String} options.organizationId - The organization ID\n @param {String} options.propertyId - The property ID\n @param {String | URL} options.url - The base URL for the API endpint\n @param {String} options.apiKey - The API key to use for requests\n @param {Headers} options.headers - Additional headers to send with each request\n @param {Function} options.onSuccess - A callback to handle successful responses\n @param {Function} options.onError - A callback to handle errors\n */\n constructor(\n options = {\n url: \"\",\n propertyId: \"\",\n organizationId: \"\",\n apiKey: \"\",\n headers: new Headers({}),\n onSuccess: (response) => response,\n onError: (error) => error,\n },\n ) {\n if (!options.url) throw new Error(\"options.url is required\");\n this.options = options;\n\n this.isAuthTokenRenewalActive = false;\n\n this.baseUrl = new URL(options.url);\n this.headers = new Headers({\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...options.headers,\n });\n\n if (options.apiKey) {\n this.headers.set(KohostHTTPClient.defs.apiKeyHeader, options.apiKey);\n }\n\n if (options.propertyId) {\n this.propertyId = options.propertyId;\n }\n\n if (options.organizationId) {\n this.organizationId = options.organizationId;\n }\n\n this.#onSuccess = options.onSuccess\n ? options.onSuccess\n : (response) => response;\n\n this.#onError = options.onError ? options.onError : (error) => error;\n\n this.callbacks = {};\n }\n\n /**\n *\n * @param {\"LoginRequired\" | \"PhoneVerificationRequired\"} event\n * @param {Function} callback\n */\n on(event, callback) {\n if (typeof callback !== \"function\") {\n throw new Error(\"Callback must be a function\");\n }\n if (!this.callbacks[event]) {\n this.callbacks[event] = [];\n }\n this.callbacks[event].push(callback);\n }\n\n emit(event, ...args) {\n if (this.callbacks[event]) {\n this.callbacks[event].forEach((callback) => callback(...args));\n }\n }\n\n /**\n * @param {string} orgId\n * @returns {void}\n * @memberof KohostApiClient\n * @example\n * client.organizationId = \"1234\";\n */\n set organizationId(orgId) {\n const key = KohostHTTPClient.defs.organizationHeader;\n this.headers.set(key, orgId);\n }\n\n get organizationId() {\n const key = KohostHTTPClient.defs.organizationHeader;\n return this.headers.get(key);\n }\n\n /**\n * @param {string} propertyId\n * @returns {void}\n * @memberof KohostApiClient\n * @example\n * client.propertyId = \"1234\";\n */\n\n set propertyId(propertyId) {\n const key = KohostHTTPClient.defs.propertyHeader;\n this.headers.set(key, propertyId);\n }\n\n get propertyId() {\n const key = KohostHTTPClient.defs.propertyHeader;\n return this.headers.get(key);\n }\n\n static get defs() {\n return {\n apiKeyHeader: \"X-Api-Key\",\n propertyHeader: \"X-Property-Id\",\n organizationHeader: \"X-Organization-Id\",\n };\n }\n\n /**\n * @typedef {keyof typeof import('./useCases')} CommandName\n * @typedef {import('./useCases')[CommandName]} Command\n *\n * @param {Command} command\n */\n async send(command) {\n const commandConfig = command.config;\n const request = this.createRequest(commandConfig);\n const response = await fetch(request);\n\n const isJsonResponse =\n response.headers.get(\"Content-Type\")?.includes(\"application/json\") ||\n false;\n\n const responseData = isJsonResponse ? await response.json() : response.body;\n\n if (!response.ok) {\n let error = responseData?.error || new Error(response.statusText);\n\n const status = response.status;\n const errorType = responseData.error?.type;\n const errorMessage = responseData?.error?.message;\n\n try {\n const expectedError = status >= 400 && status < 500;\n const newTokensNeeded =\n expectedError && errorType === \"TokenExpiredError\";\n\n if (\n expectedError &&\n errorMessage === \"Phone Verification is required\"\n ) {\n this.#onPhoneVerificationRequired();\n return Promise.reject(error);\n }\n\n if (expectedError && errorMessage === \"Login Required\") {\n this.#onLoginRequired();\n return Promise.reject(error);\n }\n\n if (\n expectedError &&\n errorMessage === \"No auth header or cookie provided\"\n ) {\n this.#onLoginRequired();\n return Promise.reject(error);\n }\n\n if (expectedError && newTokensNeeded) {\n while (!this.isAuthTokenRenewalActive) {\n this.isAuthTokenRenewalActive = true;\n return this.send(\n new RefreshTokenCommand({\n data: commandConfig.data,\n query: commandConfig.params,\n headers: commandConfig.headers,\n }),\n )\n .then(() => {\n // retry the original request with the new token\n this.isAuthTokenRenewalActive = false;\n return fetch(request.clone());\n })\n .catch((err) => {\n this.isAuthTokenRenewalActive = false;\n return Promise.reject(err);\n });\n }\n }\n } catch (error) {\n console.error(error);\n }\n\n error = this.#onError(error);\n\n return Promise.reject(error);\n }\n\n return this.#onSuccess(responseData);\n }\n\n #onLoginRequired() {\n this.emit(\"LoginRequired\");\n }\n\n #onPhoneVerificationRequired() {\n this.emit(\"PhoneVerificationRequired\");\n }\n\n /**\n * @param {Command} config\n * @returns {Request}\n */\n createRequest(config) {\n if (typeof config.headers !== \"object\") {\n config.headers = {};\n }\n\n let apiPath = config.url;\n\n if (apiPath.startsWith(\"/\")) {\n apiPath = `.${apiPath}`;\n }\n const url = new URL(apiPath, this.baseUrl);\n const method = config.method.toUpperCase() || \"GET\";\n\n // Add parameters to URL if they exist\n if (config.params && typeof config.params === \"object\") {\n Object.entries(config.params).forEach(([key, value]) => {\n // Handle array values\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (typeof item === \"object\" && item !== null) {\n Object.entries(item).forEach(([itemKey, itemValue]) => {\n url.searchParams.append(`${key}[][${itemKey}]`, itemValue);\n });\n } else {\n url.searchParams.append(`${key}[]`, item);\n }\n });\n }\n // Handle null/undefined\n else if (value === null || value === undefined) {\n url.searchParams.append(key, \"\");\n }\n // Handle nested objects\n else if (typeof value === \"object\") {\n Object.entries(value).forEach(([nestedKey, nestedValue]) => {\n if (Array.isArray(nestedValue)) {\n nestedValue.forEach((item) => {\n url.searchParams.append(`${key}[${nestedKey}][]`, item);\n });\n } else {\n url.searchParams.append(`${key}[${nestedKey}]`, nestedValue);\n }\n });\n }\n // Handle primitive values\n else {\n url.searchParams.append(key, value);\n }\n });\n }\n\n const headers = new Headers(this.headers);\n // Add any additional headers\n if (config.headers) {\n Object.keys(config.headers).forEach((key) => {\n headers.set(key, config.headers[key]);\n });\n }\n\n const body = [\"POST\", \"PUT\", \"PATCH\"].includes(method)\n ? headers.get(\"Content-Type\") === \"application/json\"\n ? JSON.stringify(config.data)\n : config.data\n : undefined;\n\n const request = new Request(url, {\n method: method,\n headers: headers,\n credentials: \"include\",\n body: body,\n });\n\n return request;\n }\n}\n","/* @ts-nocheck */\n/* This file is automatically generated. Do not modify it manually. */\n\nexport class RefreshTokenCommand {\n /**\n * @description\n * @constructor\n * @typedef {object} RefreshTokenCommandConfig\n * @property {{[key: string]: any}} data - The body to include in the command\n * @property {{[key:string]: any} | null} [headers] - The headers to include in the command\n * @property {{[key:string]: any} | null} [query] - The query parameters to include in the command\n *\n * @param {RefreshTokenCommandConfig} commandConfig - The options to include in the command\n * @param {Object} options - The options to include in the command\n */\n constructor(commandConfig, options = {}) {\n // get parameters from path\n const pathParams = RefreshTokenCommand.params;\n\n let { data, query, headers } = commandConfig ?? {};\n\n if (typeof data === \"undefined\") data = null;\n if (typeof query === \"undefined\") query = null;\n if (typeof headers === \"undefined\") headers = null;\n\n // replace path parameters with values from params\n let url = RefreshTokenCommand.url;\n\n if (pathParams && data) {\n for (const param of pathParams) {\n const urlParam = \":\" + param;\n url = url.replace(urlParam, data[param]);\n }\n }\n\n // make sure all parameters have been replaced\n if (url.match(/:[a-zA-Z0-9]+/g)) {\n const missingParams = url.match(/:[a-zA-Z0-9]+/g);\n\n if (missingParams) {\n // remove the colon from the parameter name\n const missing = missingParams.map((param) => param.replace(\":\", \"\"));\n throw new Error(\"Missing parameters: \" + missing.join(\", \"));\n }\n }\n\n /**\n * The full URL for the use case\n * @type {string}\n * @public\n */\n this.url = url;\n /**\n * The data to send with the use case\n * @type {RefreshTokenCommandConfig[\"data\"]}\n * @public\n */\n this.data = data;\n /**\n * The query parameters for the use case\n * @type {RefreshTokenCommandConfig[\"query\"]}\n * @public\n */\n this.query = query;\n /**\n * The headers for the use case\n * @type {RefreshTokenCommandConfig[\"headers\"]}\n * @public\n */\n this.headers = headers;\n\n /**\n * The configuration for the use case command\n * @type {{ url: string, method: \"post\" , data: RefreshTokenCommandConfig[\"data\"] , params: RefreshTokenCommandConfig[\"query\"], headers: RefreshTokenCommandConfig[\"headers\"] }}\n * @public\n */\n this.config = {\n method: RefreshTokenCommand.method,\n url: url,\n data: data,\n params: query,\n headers: headers,\n ...options,\n };\n }\n\n /**\n * The required parameters for the use case\n * @type {string[]}\n */\n static params = [];\n\n /**\n * The URL for the use case, with path parameters\n * @type {string}\n */\n static url = \"/auth/refresh\";\n\n /**\n * The HTTP method for the use case\n * @type {\"post\"}\n */\n static method = \"post\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,sBAAN,MAAM,qBAAoB;AAAA,EAHjC,OAGiC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY/B,YAAY,eAAe,UAAU,CAAC,GAAG;AAEvC,UAAM,aAAa,qBAAoB;AAEvC,QAAI,EAAE,MAAM,OAAO,QAAQ,IAAI,iBAAiB,CAAC;AAEjD,QAAI,OAAO,SAAS,YAAa,QAAO;AACxC,QAAI,OAAO,UAAU,YAAa,SAAQ;AAC1C,QAAI,OAAO,YAAY,YAAa,WAAU;AAG9C,QAAI,MAAM,qBAAoB;AAE9B,QAAI,cAAc,MAAM;AACtB,iBAAW,SAAS,YAAY;AAC9B,cAAM,WAAW,MAAM;AACvB,cAAM,IAAI,QAAQ,UAAU,KAAK,KAAK,CAAC;AAAA,MACzC;AAAA,IACF;AAGA,QAAI,IAAI,MAAM,gBAAgB,GAAG;AAC/B,YAAM,gBAAgB,IAAI,MAAM,gBAAgB;AAEhD,UAAI,eAAe;AAEjB,cAAM,UAAU,cAAc,IAAI,CAAC,UAAU,MAAM,QAAQ,KAAK,EAAE,CAAC;AACnE,cAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,IAAI,CAAC;AAAA,MAC7D;AAAA,IACF;AAOA,SAAK,MAAM;AAMX,SAAK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O,UAAU,UAAU;AAClC,iBAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,WAAW,WAAW,MAAM;AAC1D,gBAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,0BAAY,QAAQ,CAAC,SAAS;AAC5B,oBAAI,aAAa,OAAO,GAAG,GAAG,IAAI,SAAS,OAAO,IAAI;AAAA,cACxD,CAAC;AAAA,YACH,OAAO;AACL,kBAAI,aAAa,OAAO,GAAG,GAAG,IAAI,SAAS,KAAK,WAAW;AAAA,YAC7D;AAAA,UACF,CAAC;AAAA,QACH,OAEK;AACH,cAAI,aAAa,OAAO,KAAK,KAAK;AAAA,QACpC;AAAA,MACF,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;AAExC,QAAI,OAAO,SAAS;AAClB,aAAO,KAAK,OAAO,OAAO,EAAE,QAAQ,CAAC,QAAQ;AAC3C,gBAAQ,IAAI,KAAK,OAAO,QAAQ,GAAG,CAAC;AAAA,MACtC,CAAC;AAAA,IACH;AAEA,UAAM,OAAO,CAAC,QAAQ,OAAO,OAAO,EAAE,SAAS,MAAM,IACjD,QAAQ,IAAI,cAAc,MAAM,qBAC9B,KAAK,UAAU,OAAO,IAAI,IAC1B,OAAO,OACT;AAEJ,UAAM,UAAU,IAAI,QAAQ,KAAK;AAAA,MAC/B;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":["error"]}
|
package/dist/client.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RefreshTokenCommand
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import
|
|
3
|
+
} from "./chunk-UZQ2AWUY.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-FU4IK6I4.js";
|
|
5
7
|
|
|
6
8
|
// src/httpClient.js
|
|
7
9
|
var KohostHTTPClient = class _KohostHTTPClient {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "KohostHTTPClient");
|
|
12
|
+
}
|
|
8
13
|
#onSuccess;
|
|
9
14
|
#onError;
|
|
10
15
|
/**
|
|
@@ -23,8 +28,8 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
23
28
|
organizationId: "",
|
|
24
29
|
apiKey: "",
|
|
25
30
|
headers: new Headers({}),
|
|
26
|
-
onSuccess: (response) => response,
|
|
27
|
-
onError: (error) => error
|
|
31
|
+
onSuccess: /* @__PURE__ */ __name((response) => response, "onSuccess"),
|
|
32
|
+
onError: /* @__PURE__ */ __name((error) => error, "onError")
|
|
28
33
|
}) {
|
|
29
34
|
if (!options.url) throw new Error("options.url is required");
|
|
30
35
|
this.options = options;
|
|
@@ -114,7 +119,8 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
114
119
|
const commandConfig = command.config;
|
|
115
120
|
const request = this.createRequest(commandConfig);
|
|
116
121
|
const response = await fetch(request);
|
|
117
|
-
const
|
|
122
|
+
const isJsonResponse = response.headers.get("Content-Type")?.includes("application/json") || false;
|
|
123
|
+
const responseData = isJsonResponse ? await response.json() : response.body;
|
|
118
124
|
if (!response.ok) {
|
|
119
125
|
let error = responseData?.error || new Error(response.statusText);
|
|
120
126
|
const status = response.status;
|
|
@@ -154,7 +160,7 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
} catch (error2) {
|
|
157
|
-
console.
|
|
163
|
+
console.error(error2);
|
|
158
164
|
}
|
|
159
165
|
error = this.#onError(error);
|
|
160
166
|
return Promise.reject(error);
|
|
@@ -181,9 +187,33 @@ var KohostHTTPClient = class _KohostHTTPClient {
|
|
|
181
187
|
}
|
|
182
188
|
const url = new URL(apiPath, this.baseUrl);
|
|
183
189
|
const method = config.method.toUpperCase() || "GET";
|
|
184
|
-
if (config.params) {
|
|
185
|
-
Object.
|
|
186
|
-
|
|
190
|
+
if (config.params && typeof config.params === "object") {
|
|
191
|
+
Object.entries(config.params).forEach(([key, value]) => {
|
|
192
|
+
if (Array.isArray(value)) {
|
|
193
|
+
value.forEach((item) => {
|
|
194
|
+
if (typeof item === "object" && item !== null) {
|
|
195
|
+
Object.entries(item).forEach(([itemKey, itemValue]) => {
|
|
196
|
+
url.searchParams.append(`${key}[][${itemKey}]`, itemValue);
|
|
197
|
+
});
|
|
198
|
+
} else {
|
|
199
|
+
url.searchParams.append(`${key}[]`, item);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
} else if (value === null || value === void 0) {
|
|
203
|
+
url.searchParams.append(key, "");
|
|
204
|
+
} else if (typeof value === "object") {
|
|
205
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
206
|
+
if (Array.isArray(nestedValue)) {
|
|
207
|
+
nestedValue.forEach((item) => {
|
|
208
|
+
url.searchParams.append(`${key}[${nestedKey}][]`, item);
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
url.searchParams.append(`${key}[${nestedKey}]`, nestedValue);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
} else {
|
|
215
|
+
url.searchParams.append(key, value);
|
|
216
|
+
}
|
|
187
217
|
});
|
|
188
218
|
}
|
|
189
219
|
const headers = new Headers(this.headers);
|