@allthings/sdk 4.5.0 → 4.8.1
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/README.md +29 -7
- package/dist/cli.js +134 -106
- package/dist/lib.cjs.js +149 -106
- package/dist/lib.esm.js +94 -77
- package/dist/lib.umd.min.js +1 -1
- package/dist/src/rest/methods/app.d.ts +6 -0
- package/dist/src/rest/methods/booking.d.ts +15 -0
- package/dist/src/rest/methods/booking.test.d.ts +1 -0
- package/dist/src/rest/methods/ticket.d.ts +8 -0
- package/dist/src/rest/types.d.ts +5 -1
- package/dist/test/constants.d.ts +1 -0
- package/package.json +20 -30
package/dist/lib.esm.js
CHANGED
|
@@ -9,7 +9,7 @@ import https from 'https';
|
|
|
9
9
|
import url from 'url';
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
|
|
12
|
-
const version = "4.
|
|
12
|
+
const version = "4.8.1";
|
|
13
13
|
|
|
14
14
|
const REST_API_URL = 'https://api.allthings.me';
|
|
15
15
|
const OAUTH_URL = 'https://accounts.allthings.me';
|
|
@@ -32,9 +32,9 @@ const DEFAULT_API_WRAPPER_OPTIONS = {
|
|
|
32
32
|
};
|
|
33
33
|
const USER_AGENT = `Allthings Node SDK REST Client/${version}`;
|
|
34
34
|
|
|
35
|
-
const RESPONSE_TYPE = 'code';
|
|
36
|
-
const GRANT_TYPE = 'authorization_code';
|
|
37
|
-
const castToAuthorizationRequestParams = (params) => {
|
|
35
|
+
const RESPONSE_TYPE$1 = 'code';
|
|
36
|
+
const GRANT_TYPE$3 = 'authorization_code';
|
|
37
|
+
const castToAuthorizationRequestParams$1 = (params) => {
|
|
38
38
|
const { redirectUri, clientId, scope, state } = params;
|
|
39
39
|
if (!clientId) {
|
|
40
40
|
throw new Error('Missing required "clientId" parameter to perform authorization code grant redirect');
|
|
@@ -42,18 +42,18 @@ const castToAuthorizationRequestParams = (params) => {
|
|
|
42
42
|
if (!redirectUri) {
|
|
43
43
|
throw new Error('Missing required "redirectUri" parameter to perform authorization code grant redirect');
|
|
44
44
|
}
|
|
45
|
-
return Object.assign(Object.assign({ client_id: clientId, redirect_uri: redirectUri, response_type: RESPONSE_TYPE }, (scope ? { scope } : {})), (state ? { state } : {}));
|
|
45
|
+
return Object.assign(Object.assign({ client_id: clientId, redirect_uri: redirectUri, response_type: RESPONSE_TYPE$1 }, (scope ? { scope } : {})), (state ? { state } : {}));
|
|
46
46
|
};
|
|
47
|
-
const isEligibleForClientRedirect = (params) => {
|
|
47
|
+
const isEligibleForClientRedirect$1 = (params) => {
|
|
48
48
|
try {
|
|
49
|
-
return !!castToAuthorizationRequestParams(params);
|
|
49
|
+
return !!castToAuthorizationRequestParams$1(params);
|
|
50
50
|
}
|
|
51
51
|
catch (_a) {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
const getRedirectUrl = (params) => `${params.oauthUrl}/oauth/authorize?${querystring.stringify(castToAuthorizationRequestParams(params))}`;
|
|
56
|
-
const castToTokenRequestParams = (params) => {
|
|
55
|
+
const getRedirectUrl$1 = (params) => `${params.oauthUrl}/oauth/authorize?${querystring.stringify(castToAuthorizationRequestParams$1(params))}`;
|
|
56
|
+
const castToTokenRequestParams$2 = (params) => {
|
|
57
57
|
const { authorizationCode, redirectUri, clientId, clientSecret } = params;
|
|
58
58
|
if (!clientId) {
|
|
59
59
|
throw new Error('Missing required "clientId" parameter to perform authorization code grant');
|
|
@@ -64,17 +64,17 @@ const castToTokenRequestParams = (params) => {
|
|
|
64
64
|
if (!authorizationCode) {
|
|
65
65
|
throw new Error('Missing required "authorizationCode" parameter to perform authorization code grant');
|
|
66
66
|
}
|
|
67
|
-
return Object.assign({ client_id: clientId, code: authorizationCode, grant_type: GRANT_TYPE, redirect_uri: redirectUri }, (clientSecret ? { client_secret: clientSecret } : {}));
|
|
67
|
+
return Object.assign({ client_id: clientId, code: authorizationCode, grant_type: GRANT_TYPE$3, redirect_uri: redirectUri }, (clientSecret ? { client_secret: clientSecret } : {}));
|
|
68
68
|
};
|
|
69
|
-
const isEligible = (params) => {
|
|
69
|
+
const isEligible$3 = (params) => {
|
|
70
70
|
try {
|
|
71
|
-
return !!castToTokenRequestParams(params);
|
|
71
|
+
return !!castToTokenRequestParams$2(params);
|
|
72
72
|
}
|
|
73
73
|
catch (_a) {
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
const requestToken = (tokenRequester, params) => tokenRequester(castToTokenRequestParams(params));
|
|
77
|
+
const requestToken$3 = (tokenRequester, params) => tokenRequester(castToTokenRequestParams$2(params));
|
|
78
78
|
|
|
79
79
|
function createTokenStore(initialToken) {
|
|
80
80
|
const token = new Map(Object.entries(initialToken || {}));
|
|
@@ -134,7 +134,7 @@ const makeFetchTokenRequester = (url) => async (params) => {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
-
const GRANT_TYPE$
|
|
137
|
+
const GRANT_TYPE$2 = 'refresh_token';
|
|
138
138
|
const castToTokenRequestParams$1 = (params) => {
|
|
139
139
|
const { clientId, clientSecret, refreshToken, scope } = params;
|
|
140
140
|
if (!clientId) {
|
|
@@ -143,9 +143,9 @@ const castToTokenRequestParams$1 = (params) => {
|
|
|
143
143
|
if (!refreshToken) {
|
|
144
144
|
throw new Error('Missing required "refreshToken" parameter to perform refresh token grant');
|
|
145
145
|
}
|
|
146
|
-
return Object.assign(Object.assign({ client_id: clientId, grant_type: GRANT_TYPE$
|
|
146
|
+
return Object.assign(Object.assign({ client_id: clientId, grant_type: GRANT_TYPE$2, refresh_token: refreshToken }, (clientSecret ? { client_secret: clientSecret } : {})), (scope ? { scope } : {}));
|
|
147
147
|
};
|
|
148
|
-
const isEligible$
|
|
148
|
+
const isEligible$2 = (params) => {
|
|
149
149
|
try {
|
|
150
150
|
return !!castToTokenRequestParams$1(params);
|
|
151
151
|
}
|
|
@@ -153,7 +153,7 @@ const isEligible$1 = (params) => {
|
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
|
-
const requestToken$
|
|
156
|
+
const requestToken$2 = (tokenRequester, params) => tokenRequester(castToTokenRequestParams$1(params));
|
|
157
157
|
|
|
158
158
|
async function requestAndSaveToStore(requester, tokenStore) {
|
|
159
159
|
const response = await requester();
|
|
@@ -191,7 +191,7 @@ async function get(request, method, query, returnRawResultObject) {
|
|
|
191
191
|
return request('get', method, { query }, returnRawResultObject);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
194
|
+
var __rest$4 = (undefined && undefined.__rest) || function (s, e) {
|
|
195
195
|
var t = {};
|
|
196
196
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
197
197
|
t[p] = s[p];
|
|
@@ -253,7 +253,7 @@ var EnumUserPermissionObjectType;
|
|
|
253
253
|
EnumUserPermissionObjectType["unit"] = "Unit";
|
|
254
254
|
})(EnumUserPermissionObjectType || (EnumUserPermissionObjectType = {}));
|
|
255
255
|
const remapUserResult = (user) => {
|
|
256
|
-
const { tenantIDs: tenantIds } = user, result = __rest(user, ["tenantIDs"]);
|
|
256
|
+
const { tenantIDs: tenantIds } = user, result = __rest$4(user, ["tenantIDs"]);
|
|
257
257
|
return Object.assign(Object.assign({}, result), { tenantIds });
|
|
258
258
|
};
|
|
259
259
|
const remapEmbeddedUser = (embedded) => embedded.users ? embedded.users.map(remapUserResult) : [];
|
|
@@ -275,12 +275,12 @@ async function userGetById(client, userId) {
|
|
|
275
275
|
return remapUserResult(await client.get(`/v1/users/${userId}`));
|
|
276
276
|
}
|
|
277
277
|
async function userUpdateById(client, userId, data) {
|
|
278
|
-
const { tenantIds: tenantIDs } = data, rest = __rest(data, ["tenantIds"]);
|
|
278
|
+
const { tenantIds: tenantIDs } = data, rest = __rest$4(data, ["tenantIds"]);
|
|
279
279
|
return remapUserResult(await client.patch(`/v1/users/${userId}`, Object.assign(Object.assign({}, rest), { tenantIDs })));
|
|
280
280
|
}
|
|
281
281
|
async function userCreatePermission(client, userId, data) {
|
|
282
|
-
const { objectId: objectID } = data, rest = __rest(data, ["objectId"]);
|
|
283
|
-
const _a = await client.post(`/v1/users/${userId}/permissions`, Object.assign(Object.assign({}, rest), { objectID })), { objectID: resultObjectId } = _a, result = __rest(_a, ["objectID"]);
|
|
282
|
+
const { objectId: objectID } = data, rest = __rest$4(data, ["objectId"]);
|
|
283
|
+
const _a = await client.post(`/v1/users/${userId}/permissions`, Object.assign(Object.assign({}, rest), { objectID })), { objectID: resultObjectId } = _a, result = __rest$4(_a, ["objectID"]);
|
|
284
284
|
return Object.assign(Object.assign({}, result), { objectId: resultObjectId });
|
|
285
285
|
}
|
|
286
286
|
async function userCreatePermissionBatch(client, userId, permissions) {
|
|
@@ -300,7 +300,7 @@ async function userCreatePermissionBatch(client, userId, permissions) {
|
|
|
300
300
|
async function userGetPermissions(client, userId) {
|
|
301
301
|
const { _embedded: { items: permissions }, } = await client.get(`/v1/users/${userId}/roles?limit=-1`);
|
|
302
302
|
return permissions.map((_a) => {
|
|
303
|
-
var { objectID: objectId } = _a, result = __rest(_a, ["objectID"]);
|
|
303
|
+
var { objectID: objectId } = _a, result = __rest$4(_a, ["objectID"]);
|
|
304
304
|
return (Object.assign(Object.assign({}, result), { objectId }));
|
|
305
305
|
});
|
|
306
306
|
}
|
|
@@ -350,6 +350,16 @@ async function appCreate(client, userId, data) {
|
|
|
350
350
|
async function appGetById(client, appId) {
|
|
351
351
|
return client.get(`/v1/apps/${appId}`);
|
|
352
352
|
}
|
|
353
|
+
async function activeUnitsGetByAppId(client, appId) {
|
|
354
|
+
return client.get(`/v1/apps/${appId}/active-units`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
async function bookingGetById(client, bookingId) {
|
|
358
|
+
return client.get(`/v1/bookings/${bookingId}`);
|
|
359
|
+
}
|
|
360
|
+
async function bookingUpdateById(client, bookingId, data) {
|
|
361
|
+
return client.patch(`/v1/bookings/${bookingId}`, data);
|
|
362
|
+
}
|
|
353
363
|
|
|
354
364
|
async function bucketGet(client, bucketId) {
|
|
355
365
|
return client.get(`/v1/buckets/${bucketId}`);
|
|
@@ -438,7 +448,7 @@ async function fileDelete(client, fileId) {
|
|
|
438
448
|
return (await client.delete(`/v1/files/${fileId}`)) === '';
|
|
439
449
|
}
|
|
440
450
|
|
|
441
|
-
var __rest$
|
|
451
|
+
var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
|
|
442
452
|
var t = {};
|
|
443
453
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
444
454
|
t[p] = s[p];
|
|
@@ -450,11 +460,11 @@ var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
|
|
|
450
460
|
return t;
|
|
451
461
|
};
|
|
452
462
|
async function groupCreate(client, propertyId, data) {
|
|
453
|
-
const { propertyManagerId } = data, rest = __rest$
|
|
463
|
+
const { propertyManagerId } = data, rest = __rest$3(data, ["propertyManagerId"]);
|
|
454
464
|
return client.post(`/v1/properties/${propertyId}/groups`, Object.assign(Object.assign({}, rest), { propertyManagerID: propertyManagerId }));
|
|
455
465
|
}
|
|
456
466
|
async function groupGetById(client, groupId) {
|
|
457
|
-
const _a = await client.get(`/v1/groups/${groupId}`), { propertyManagerID: propertyManagerId } = _a, result = __rest$
|
|
467
|
+
const _a = await client.get(`/v1/groups/${groupId}`), { propertyManagerID: propertyManagerId } = _a, result = __rest$3(_a, ["propertyManagerID"]);
|
|
458
468
|
return Object.assign(Object.assign({}, result), { propertyManagerId });
|
|
459
469
|
}
|
|
460
470
|
async function groupUpdateById(client, groupId, data) {
|
|
@@ -593,7 +603,7 @@ async function getProperties(client, page = 1, limit = -1, filter = {}) {
|
|
|
593
603
|
return { _embedded: { items: properties }, total };
|
|
594
604
|
}
|
|
595
605
|
|
|
596
|
-
var __rest$
|
|
606
|
+
var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
|
|
597
607
|
var t = {};
|
|
598
608
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
599
609
|
t[p] = s[p];
|
|
@@ -605,11 +615,11 @@ var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
|
|
|
605
615
|
return t;
|
|
606
616
|
};
|
|
607
617
|
const remapRegistationCodeResult = (registrationCode) => {
|
|
608
|
-
const { tenantID: externalId } = registrationCode, result = __rest$
|
|
618
|
+
const { tenantID: externalId } = registrationCode, result = __rest$1(registrationCode, ["tenantID"]);
|
|
609
619
|
return Object.assign(Object.assign({}, result), { externalId });
|
|
610
620
|
};
|
|
611
621
|
async function registrationCodeCreate(client, code, utilisationPeriods, options = { permanent: false }) {
|
|
612
|
-
const { externalId } = options, moreOptions = __rest$
|
|
622
|
+
const { externalId } = options, moreOptions = __rest$1(options, ["externalId"]);
|
|
613
623
|
return remapRegistationCodeResult(await client.post('/v1/registration-codes', Object.assign(Object.assign({ code, utilisationPeriods: typeof utilisationPeriods === 'string'
|
|
614
624
|
? [utilisationPeriods]
|
|
615
625
|
: utilisationPeriods }, (externalId ? { tenantID: externalId } : {})), moreOptions)));
|
|
@@ -780,7 +790,7 @@ async function userRelationsGetByUser(client, userId) {
|
|
|
780
790
|
return client.get(`/v1/users/${userId}/user-relations`);
|
|
781
791
|
}
|
|
782
792
|
|
|
783
|
-
var __rest
|
|
793
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
784
794
|
var t = {};
|
|
785
795
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
786
796
|
t[p] = s[p];
|
|
@@ -798,15 +808,15 @@ var EnumUtilisationPeriodType;
|
|
|
798
808
|
EnumUtilisationPeriodType["vacant"] = "vacant";
|
|
799
809
|
})(EnumUtilisationPeriodType || (EnumUtilisationPeriodType = {}));
|
|
800
810
|
async function utilisationPeriodCreate(client, unitId, data) {
|
|
801
|
-
const _a = await client.post(`/v1/units/${unitId}/utilisation-periods`, data), { tenantIDs: tenantIds, _embedded } = _a, result = __rest
|
|
811
|
+
const _a = await client.post(`/v1/units/${unitId}/utilisation-periods`, data), { tenantIDs: tenantIds, _embedded } = _a, result = __rest(_a, ["tenantIDs", "_embedded"]);
|
|
802
812
|
return Object.assign(Object.assign({}, result), { invitations: _embedded.invitations.map(remapRegistationCodeResult), tenantIds, users: remapEmbeddedUser(_embedded) });
|
|
803
813
|
}
|
|
804
814
|
async function utilisationPeriodGetById(client, utilisationPeriodId) {
|
|
805
|
-
const _a = await client.get(`/v1/utilisation-periods/${utilisationPeriodId}`), { tenantIDs: tenantIds, _embedded } = _a, result = __rest
|
|
815
|
+
const _a = await client.get(`/v1/utilisation-periods/${utilisationPeriodId}`), { tenantIDs: tenantIds, _embedded } = _a, result = __rest(_a, ["tenantIDs", "_embedded"]);
|
|
806
816
|
return Object.assign(Object.assign({}, result), { invitations: _embedded.invitations.map(remapRegistationCodeResult), tenantIds, users: remapEmbeddedUser(_embedded) });
|
|
807
817
|
}
|
|
808
818
|
async function utilisationPeriodUpdateById(client, utilisationPeriodId, data) {
|
|
809
|
-
const _a = await client.patch(`/v1/utilisation-periods/${utilisationPeriodId}`, data), { tenantIDs: tenantIds, _embedded } = _a, result = __rest
|
|
819
|
+
const _a = await client.patch(`/v1/utilisation-periods/${utilisationPeriodId}`, data), { tenantIDs: tenantIds, _embedded } = _a, result = __rest(_a, ["tenantIDs", "_embedded"]);
|
|
810
820
|
return Object.assign(Object.assign({}, result), { invitations: _embedded.invitations.map(remapRegistationCodeResult), tenantIds, users: remapEmbeddedUser(_embedded) });
|
|
811
821
|
}
|
|
812
822
|
async function utilisationPeriodDelete(client, utilisationPeriodId) {
|
|
@@ -836,7 +846,7 @@ async function put(request, method, body, returnRawResultObject) {
|
|
|
836
846
|
return request('put', method, { body }, returnRawResultObject);
|
|
837
847
|
}
|
|
838
848
|
|
|
839
|
-
var Stream = stream.Stream;
|
|
849
|
+
var Stream$1 = stream.Stream;
|
|
840
850
|
|
|
841
851
|
|
|
842
852
|
var delayed_stream = DelayedStream;
|
|
@@ -850,7 +860,7 @@ function DelayedStream() {
|
|
|
850
860
|
this._released = false;
|
|
851
861
|
this._bufferedEvents = [];
|
|
852
862
|
}
|
|
853
|
-
util.inherits(DelayedStream, Stream);
|
|
863
|
+
util.inherits(DelayedStream, Stream$1);
|
|
854
864
|
|
|
855
865
|
DelayedStream.create = function(source, options) {
|
|
856
866
|
var delayedStream = new this();
|
|
@@ -910,7 +920,7 @@ DelayedStream.prototype.release = function() {
|
|
|
910
920
|
};
|
|
911
921
|
|
|
912
922
|
DelayedStream.prototype.pipe = function() {
|
|
913
|
-
var r = Stream.prototype.pipe.apply(this, arguments);
|
|
923
|
+
var r = Stream$1.prototype.pipe.apply(this, arguments);
|
|
914
924
|
this.resume();
|
|
915
925
|
return r;
|
|
916
926
|
};
|
|
@@ -944,7 +954,7 @@ DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
|
|
|
944
954
|
this.emit('error', new Error(message));
|
|
945
955
|
};
|
|
946
956
|
|
|
947
|
-
var Stream
|
|
957
|
+
var Stream = stream.Stream;
|
|
948
958
|
|
|
949
959
|
|
|
950
960
|
var combined_stream = CombinedStream;
|
|
@@ -961,7 +971,7 @@ function CombinedStream() {
|
|
|
961
971
|
this._insideLoop = false;
|
|
962
972
|
this._pendingNext = false;
|
|
963
973
|
}
|
|
964
|
-
util.inherits(CombinedStream, Stream
|
|
974
|
+
util.inherits(CombinedStream, Stream);
|
|
965
975
|
|
|
966
976
|
CombinedStream.create = function(options) {
|
|
967
977
|
var combinedStream = new this();
|
|
@@ -1007,7 +1017,7 @@ CombinedStream.prototype.append = function(stream) {
|
|
|
1007
1017
|
};
|
|
1008
1018
|
|
|
1009
1019
|
CombinedStream.prototype.pipe = function(dest, options) {
|
|
1010
|
-
Stream
|
|
1020
|
+
Stream.prototype.pipe.call(this, dest, options);
|
|
1011
1021
|
this.resume();
|
|
1012
1022
|
return dest;
|
|
1013
1023
|
};
|
|
@@ -11017,13 +11027,13 @@ function populateMaps (extensions, types) {
|
|
|
11017
11027
|
});
|
|
11018
11028
|
}
|
|
11019
11029
|
});
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11030
|
+
mimeTypes.charset;
|
|
11031
|
+
mimeTypes.charsets;
|
|
11032
|
+
mimeTypes.contentType;
|
|
11033
|
+
mimeTypes.extension;
|
|
11034
|
+
mimeTypes.extensions;
|
|
11035
|
+
mimeTypes.lookup;
|
|
11036
|
+
mimeTypes.types;
|
|
11027
11037
|
|
|
11028
11038
|
var defer_1 = defer;
|
|
11029
11039
|
|
|
@@ -11699,6 +11709,10 @@ FormData.prototype.getHeaders = function(userHeaders) {
|
|
|
11699
11709
|
return formHeaders;
|
|
11700
11710
|
};
|
|
11701
11711
|
|
|
11712
|
+
FormData.prototype.setBoundary = function(boundary) {
|
|
11713
|
+
this._boundary = boundary;
|
|
11714
|
+
};
|
|
11715
|
+
|
|
11702
11716
|
FormData.prototype.getBoundary = function() {
|
|
11703
11717
|
if (!this._boundary) {
|
|
11704
11718
|
this._generateBoundary();
|
|
@@ -11887,7 +11901,7 @@ FormData.prototype.toString = function () {
|
|
|
11887
11901
|
return '[object FormData]';
|
|
11888
11902
|
};
|
|
11889
11903
|
|
|
11890
|
-
const GRANT_TYPE$
|
|
11904
|
+
const GRANT_TYPE$1 = 'client_credentials';
|
|
11891
11905
|
const castClientOptionsToRequestParams = (clientOptions) => {
|
|
11892
11906
|
const { scope, clientId, clientSecret } = clientOptions;
|
|
11893
11907
|
if (!clientId) {
|
|
@@ -11896,9 +11910,9 @@ const castClientOptionsToRequestParams = (clientOptions) => {
|
|
|
11896
11910
|
if (!clientSecret) {
|
|
11897
11911
|
throw new Error('Missing required "clientSecret" parameter to perform client credentials grant');
|
|
11898
11912
|
}
|
|
11899
|
-
return Object.assign({ client_id: clientId, client_secret: clientSecret, grant_type: GRANT_TYPE$
|
|
11913
|
+
return Object.assign({ client_id: clientId, client_secret: clientSecret, grant_type: GRANT_TYPE$1 }, (scope ? { scope } : {}));
|
|
11900
11914
|
};
|
|
11901
|
-
const isEligible$
|
|
11915
|
+
const isEligible$1 = (clientOptions) => {
|
|
11902
11916
|
try {
|
|
11903
11917
|
return !!castClientOptionsToRequestParams(clientOptions);
|
|
11904
11918
|
}
|
|
@@ -11906,28 +11920,28 @@ const isEligible$2 = (clientOptions) => {
|
|
|
11906
11920
|
return false;
|
|
11907
11921
|
}
|
|
11908
11922
|
};
|
|
11909
|
-
const requestToken$
|
|
11923
|
+
const requestToken$1 = (oauthTokenRequest, clientOptions) => oauthTokenRequest(castClientOptionsToRequestParams(clientOptions));
|
|
11910
11924
|
|
|
11911
|
-
const RESPONSE_TYPE
|
|
11912
|
-
const castToAuthorizationRequestParams
|
|
11925
|
+
const RESPONSE_TYPE = 'token';
|
|
11926
|
+
const castToAuthorizationRequestParams = (params) => {
|
|
11913
11927
|
const { clientId, scope, state, redirectUri } = params;
|
|
11914
11928
|
if (!clientId) {
|
|
11915
11929
|
throw new Error('Missing required "clientId" parameter to perform implicit grant');
|
|
11916
11930
|
}
|
|
11917
|
-
return Object.assign(Object.assign({ client_id: clientId, redirect_uri: redirectUri || window.location.href, response_type: RESPONSE_TYPE
|
|
11931
|
+
return Object.assign(Object.assign({ client_id: clientId, redirect_uri: redirectUri || window.location.href, response_type: RESPONSE_TYPE }, (scope ? { scope } : {})), (state ? { state } : {}));
|
|
11918
11932
|
};
|
|
11919
|
-
const isEligibleForClientRedirect
|
|
11933
|
+
const isEligibleForClientRedirect = (params) => {
|
|
11920
11934
|
try {
|
|
11921
|
-
return !!castToAuthorizationRequestParams
|
|
11935
|
+
return !!castToAuthorizationRequestParams(params);
|
|
11922
11936
|
}
|
|
11923
11937
|
catch (_a) {
|
|
11924
11938
|
return false;
|
|
11925
11939
|
}
|
|
11926
11940
|
};
|
|
11927
|
-
const getRedirectUrl
|
|
11941
|
+
const getRedirectUrl = (params) => `${params.oauthUrl}/oauth/authorize?${querystring.stringify(castToAuthorizationRequestParams(params))}`;
|
|
11928
11942
|
|
|
11929
|
-
const GRANT_TYPE
|
|
11930
|
-
const castToTokenRequestParams
|
|
11943
|
+
const GRANT_TYPE = 'password';
|
|
11944
|
+
const castToTokenRequestParams = (params) => {
|
|
11931
11945
|
const { username, password, scope, clientId, clientSecret } = params;
|
|
11932
11946
|
if (!clientId) {
|
|
11933
11947
|
throw new Error('Missing required "clientId" parameter to perform password grant');
|
|
@@ -11938,29 +11952,29 @@ const castToTokenRequestParams$2 = (params) => {
|
|
|
11938
11952
|
if (!password) {
|
|
11939
11953
|
throw new Error('Missing required "password" parameter to perform password grant');
|
|
11940
11954
|
}
|
|
11941
|
-
return Object.assign(Object.assign({ client_id: clientId, grant_type: GRANT_TYPE
|
|
11955
|
+
return Object.assign(Object.assign({ client_id: clientId, grant_type: GRANT_TYPE, password,
|
|
11942
11956
|
username }, (scope ? { scope } : {})), (clientSecret ? { client_secret: clientSecret } : {}));
|
|
11943
11957
|
};
|
|
11944
|
-
const isEligible
|
|
11958
|
+
const isEligible = (params) => {
|
|
11945
11959
|
try {
|
|
11946
|
-
return !!castToTokenRequestParams
|
|
11960
|
+
return !!castToTokenRequestParams(params);
|
|
11947
11961
|
}
|
|
11948
11962
|
catch (_a) {
|
|
11949
11963
|
return false;
|
|
11950
11964
|
}
|
|
11951
11965
|
};
|
|
11952
|
-
const requestToken
|
|
11966
|
+
const requestToken = (tokenRequester, params) => tokenRequester(castToTokenRequestParams(params));
|
|
11953
11967
|
|
|
11954
11968
|
async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefresh = false) {
|
|
11955
11969
|
if (!mustRefresh && oauthTokenStore.get('accessToken')) {
|
|
11956
11970
|
return;
|
|
11957
11971
|
}
|
|
11958
11972
|
const refreshOptions = Object.assign(Object.assign({}, options), { refreshToken: oauthTokenStore.get('refreshToken') });
|
|
11959
|
-
if (isEligible$
|
|
11960
|
-
return oauthTokenStore.set(await requestToken$
|
|
11973
|
+
if (isEligible$2(refreshOptions)) {
|
|
11974
|
+
return oauthTokenStore.set(await requestToken$2(tokenFetcher, refreshOptions));
|
|
11961
11975
|
}
|
|
11962
|
-
if (isEligible
|
|
11963
|
-
return oauthTokenStore.set(await requestToken
|
|
11976
|
+
if (isEligible(options)) {
|
|
11977
|
+
return oauthTokenStore.set(await requestToken(tokenFetcher, options));
|
|
11964
11978
|
}
|
|
11965
11979
|
if (typeof window !== 'undefined' && options.implicit) {
|
|
11966
11980
|
const parsedLocationHash = querystring.parse(window.location.hash);
|
|
@@ -11969,20 +11983,20 @@ async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefr
|
|
|
11969
11983
|
window.history.replaceState({}, '', window.location.href.split('#')[0]);
|
|
11970
11984
|
return oauthTokenStore.set({ accessToken });
|
|
11971
11985
|
}
|
|
11972
|
-
if (isEligibleForClientRedirect
|
|
11973
|
-
window.location.href = getRedirectUrl
|
|
11986
|
+
if (isEligibleForClientRedirect(options)) {
|
|
11987
|
+
window.location.href = getRedirectUrl(options);
|
|
11974
11988
|
return;
|
|
11975
11989
|
}
|
|
11976
11990
|
}
|
|
11977
|
-
if (!mustRefresh && isEligible(options)) {
|
|
11978
|
-
return oauthTokenStore.set(await requestToken(tokenFetcher, options));
|
|
11991
|
+
if (!mustRefresh && isEligible$3(options)) {
|
|
11992
|
+
return oauthTokenStore.set(await requestToken$3(tokenFetcher, options));
|
|
11979
11993
|
}
|
|
11980
11994
|
if (options.authorizationRedirect &&
|
|
11981
|
-
isEligibleForClientRedirect(options)) {
|
|
11982
|
-
return options.authorizationRedirect(getRedirectUrl(options));
|
|
11995
|
+
isEligibleForClientRedirect$1(options)) {
|
|
11996
|
+
return options.authorizationRedirect(getRedirectUrl$1(options));
|
|
11983
11997
|
}
|
|
11984
|
-
if (isEligible$
|
|
11985
|
-
return oauthTokenStore.set(await requestToken$
|
|
11998
|
+
if (isEligible$1(options)) {
|
|
11999
|
+
return oauthTokenStore.set(await requestToken$1(tokenFetcher, options));
|
|
11986
12000
|
}
|
|
11987
12001
|
return;
|
|
11988
12002
|
}
|
|
@@ -12124,6 +12138,7 @@ async function request(oauthTokenStore, oauthTokenRequester, options, httpMethod
|
|
|
12124
12138
|
const API_METHODS = [
|
|
12125
12139
|
agentCreate,
|
|
12126
12140
|
agentCreatePermissions,
|
|
12141
|
+
activeUnitsGetByAppId,
|
|
12127
12142
|
appCreate,
|
|
12128
12143
|
appGetById,
|
|
12129
12144
|
bucketCreate,
|
|
@@ -12186,6 +12201,8 @@ const API_METHODS = [
|
|
|
12186
12201
|
utilisationPeriodCheckInUser,
|
|
12187
12202
|
utilisationPeriodCheckOutUser,
|
|
12188
12203
|
utilisationPeriodAddRegistrationCode,
|
|
12204
|
+
bookingUpdateById,
|
|
12205
|
+
bookingGetById,
|
|
12189
12206
|
];
|
|
12190
12207
|
function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
|
|
12191
12208
|
const options = Object.assign(Object.assign({}, DEFAULT_API_WRAPPER_OPTIONS), userOptions);
|
|
@@ -12214,11 +12231,11 @@ function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
|
|
|
12214
12231
|
const put$1 = partial(put, request$1);
|
|
12215
12232
|
const oauth = {
|
|
12216
12233
|
authorizationCode: {
|
|
12217
|
-
getUri: (state = options.state || pseudoRandomString()) => partial(getRedirectUrl, Object.assign(Object.assign({}, options), { state }))(),
|
|
12218
|
-
requestToken: (authorizationCode) => requestAndSaveToStore(partial(requestToken, tokenRequester, Object.assign(Object.assign({}, options), { authorizationCode: authorizationCode || options.authorizationCode })), tokenStore),
|
|
12234
|
+
getUri: (state = options.state || pseudoRandomString()) => partial(getRedirectUrl$1, Object.assign(Object.assign({}, options), { state }))(),
|
|
12235
|
+
requestToken: (authorizationCode) => requestAndSaveToStore(partial(requestToken$3, tokenRequester, Object.assign(Object.assign({}, options), { authorizationCode: authorizationCode || options.authorizationCode })), tokenStore),
|
|
12219
12236
|
},
|
|
12220
12237
|
generateState: pseudoRandomString,
|
|
12221
|
-
refreshToken: (refreshToken) => requestAndSaveToStore(partial(requestToken$
|
|
12238
|
+
refreshToken: (refreshToken) => requestAndSaveToStore(partial(requestToken$2, tokenRequester, Object.assign(Object.assign({}, options), { refreshToken: refreshToken || tokenStore.get('refreshToken') })), tokenStore),
|
|
12222
12239
|
};
|
|
12223
12240
|
const client = API_METHODS.reduce((methods, method) => (Object.assign(Object.assign({}, methods), { [method.name]: (...args) => method(client, ...args) })), {
|
|
12224
12241
|
delete: del$1,
|