@allthings/sdk 4.7.0 → 5.0.0
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 +17 -5
- package/dist/cli.js +51 -46
- package/dist/lib.cjs.js +51 -46
- package/dist/lib.esm.js +33 -28
- package/dist/lib.umd.min.js +1 -1
- package/dist/src/rest/methods/app.d.ts +2 -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/types.d.ts +3 -0
- package/dist/test/constants.d.ts +1 -0
- package/package.json +25 -40
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ const client = allthings.restClient({
|
|
|
28
28
|
|
|
29
29
|
client
|
|
30
30
|
.getCurrentUser()
|
|
31
|
-
.then(viewer => console.log(`Welcome back ${viewer.username}!`))
|
|
31
|
+
.then((viewer) => console.log(`Welcome back ${viewer.username}!`))
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
<!--
|
|
@@ -83,7 +83,7 @@ const client = allthings.restClient({
|
|
|
83
83
|
|
|
84
84
|
client
|
|
85
85
|
.getCurrentUser()
|
|
86
|
-
.then(viewer => console.log(`Welcome back ${viewer.username}!`))
|
|
86
|
+
.then((viewer) => console.log(`Welcome back ${viewer.username}!`))
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
## OAuth Authorization Code Grant Example
|
|
@@ -249,12 +249,17 @@ export interface IAllthingsRestClient {
|
|
|
249
249
|
*/
|
|
250
250
|
readonly appCreate: MethodAppCreate
|
|
251
251
|
|
|
252
|
-
//
|
|
252
|
+
// Booking
|
|
253
253
|
|
|
254
254
|
/**
|
|
255
|
-
*
|
|
255
|
+
* Get a booking by its ID
|
|
256
256
|
*/
|
|
257
|
-
readonly
|
|
257
|
+
readonly bookingGetById: MethodBookingGetById
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Update a booking by its ID
|
|
261
|
+
*/
|
|
262
|
+
readonly bookingUpdateById: MethodBookingUpdateById
|
|
258
263
|
|
|
259
264
|
// Group
|
|
260
265
|
|
|
@@ -273,6 +278,13 @@ export interface IAllthingsRestClient {
|
|
|
273
278
|
*/
|
|
274
279
|
readonly groupUpdateById: MethodGroupUpdateById
|
|
275
280
|
|
|
281
|
+
// ID Lookup
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Map one or more externalId's to API ObjectId's within the scope of a specified App
|
|
285
|
+
*/
|
|
286
|
+
readonly lookupIds: MethodLookupIds
|
|
287
|
+
|
|
276
288
|
// Notification
|
|
277
289
|
|
|
278
290
|
/**
|
package/dist/cli.js
CHANGED
|
@@ -27,7 +27,7 @@ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
|
27
27
|
var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
|
|
28
28
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
29
29
|
|
|
30
|
-
const version = "
|
|
30
|
+
const version = "5.0.0";
|
|
31
31
|
|
|
32
32
|
const REST_API_URL = 'https://api.allthings.me';
|
|
33
33
|
const OAUTH_URL = 'https://accounts.allthings.me';
|
|
@@ -70,7 +70,7 @@ const isEligibleForClientRedirect$1 = (params) => {
|
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
-
const getRedirectUrl$1 = (params) => `${params.oauthUrl}/oauth/authorize?${querystring__default[
|
|
73
|
+
const getRedirectUrl$1 = (params) => `${params.oauthUrl}/oauth/authorize?${querystring__default["default"].stringify(castToAuthorizationRequestParams$1(params))}`;
|
|
74
74
|
const castToTokenRequestParams$2 = (params) => {
|
|
75
75
|
const { authorizationCode, redirectUri, clientId, clientSecret } = params;
|
|
76
76
|
if (!clientId) {
|
|
@@ -97,14 +97,14 @@ const requestToken$3 = (tokenRequester, params) => tokenRequester(castToTokenReq
|
|
|
97
97
|
function createTokenStore(initialToken) {
|
|
98
98
|
const token = new Map(Object.entries(initialToken || {}));
|
|
99
99
|
return {
|
|
100
|
-
get: key => token.get(key),
|
|
100
|
+
get: (key) => token.get(key),
|
|
101
101
|
reset: () => token.clear(),
|
|
102
|
-
set: update => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
|
|
102
|
+
set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const SUBSCRIPTIONS = (process.env.DEBUG &&
|
|
107
|
-
process.env.DEBUG.split(',').map(item => item.trim())) ||
|
|
107
|
+
process.env.DEBUG.split(',').map((item) => item.trim())) ||
|
|
108
108
|
[];
|
|
109
109
|
function makeLogger(name) {
|
|
110
110
|
return ['log', 'info', 'warn', 'error'].reduce((logger, type) => (Object.assign(Object.assign({}, logger), { [type]: function log(...logs) {
|
|
@@ -120,8 +120,8 @@ function makeLogger(name) {
|
|
|
120
120
|
const logger = makeLogger('OAuth Token Request');
|
|
121
121
|
const makeFetchTokenRequester = (url) => async (params) => {
|
|
122
122
|
try {
|
|
123
|
-
const response = await fetch__default[
|
|
124
|
-
body: querystring__default[
|
|
123
|
+
const response = await fetch__default["default"](url, {
|
|
124
|
+
body: querystring__default["default"].stringify(params),
|
|
125
125
|
cache: 'no-cache',
|
|
126
126
|
credentials: 'omit',
|
|
127
127
|
headers: {
|
|
@@ -194,9 +194,7 @@ function fnClearInterval(intervalId) {
|
|
|
194
194
|
function pseudoRandomString(length = 16) {
|
|
195
195
|
let token = '';
|
|
196
196
|
while (token.length < length) {
|
|
197
|
-
token += Math.random()
|
|
198
|
-
.toString(36)
|
|
199
|
-
.substr(2);
|
|
197
|
+
token += Math.random().toString(36).substr(2);
|
|
200
198
|
}
|
|
201
199
|
return token.substr(0, length);
|
|
202
200
|
}
|
|
@@ -372,6 +370,13 @@ async function activeUnitsGetByAppId(client, appId) {
|
|
|
372
370
|
return client.get(`/v1/apps/${appId}/active-units`);
|
|
373
371
|
}
|
|
374
372
|
|
|
373
|
+
async function bookingGetById(client, bookingId) {
|
|
374
|
+
return client.get(`/v1/bookings/${bookingId}`);
|
|
375
|
+
}
|
|
376
|
+
async function bookingUpdateById(client, bookingId, data) {
|
|
377
|
+
return client.patch(`/v1/bookings/${bookingId}`, data);
|
|
378
|
+
}
|
|
379
|
+
|
|
375
380
|
async function bucketGet(client, bucketId) {
|
|
376
381
|
return client.get(`/v1/buckets/${bucketId}`);
|
|
377
382
|
}
|
|
@@ -416,7 +421,7 @@ async function createManyFilesSorted(files, client) {
|
|
|
416
421
|
error: result.filter((item) => item instanceof Error),
|
|
417
422
|
success: result
|
|
418
423
|
.filter((item) => !(item instanceof Error))
|
|
419
|
-
.map(item => item.id),
|
|
424
|
+
.map((item) => item.id),
|
|
420
425
|
};
|
|
421
426
|
}
|
|
422
427
|
|
|
@@ -572,10 +577,10 @@ function remapKeys(input, mapFn) {
|
|
|
572
577
|
}
|
|
573
578
|
|
|
574
579
|
function camelCaseToDash(input) {
|
|
575
|
-
return input.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`);
|
|
580
|
+
return input.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`);
|
|
576
581
|
}
|
|
577
582
|
function dashCaseToCamel(input) {
|
|
578
|
-
return input.replace(/-([a-z])/g, g => g[1].toUpperCase());
|
|
583
|
+
return input.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
579
584
|
}
|
|
580
585
|
|
|
581
586
|
var EnumNotificationSettingsValue;
|
|
@@ -857,7 +862,7 @@ async function put(request, method, body, returnRawResultObject) {
|
|
|
857
862
|
return request('put', method, { body }, returnRawResultObject);
|
|
858
863
|
}
|
|
859
864
|
|
|
860
|
-
var Stream$
|
|
865
|
+
var Stream$2 = stream__default["default"].Stream;
|
|
861
866
|
|
|
862
867
|
|
|
863
868
|
var delayed_stream = DelayedStream;
|
|
@@ -871,7 +876,7 @@ function DelayedStream() {
|
|
|
871
876
|
this._released = false;
|
|
872
877
|
this._bufferedEvents = [];
|
|
873
878
|
}
|
|
874
|
-
util__default[
|
|
879
|
+
util__default["default"].inherits(DelayedStream, Stream$2);
|
|
875
880
|
|
|
876
881
|
DelayedStream.create = function(source, options) {
|
|
877
882
|
var delayedStream = new this();
|
|
@@ -931,7 +936,7 @@ DelayedStream.prototype.release = function() {
|
|
|
931
936
|
};
|
|
932
937
|
|
|
933
938
|
DelayedStream.prototype.pipe = function() {
|
|
934
|
-
var r = Stream$
|
|
939
|
+
var r = Stream$2.prototype.pipe.apply(this, arguments);
|
|
935
940
|
this.resume();
|
|
936
941
|
return r;
|
|
937
942
|
};
|
|
@@ -965,7 +970,7 @@ DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
|
|
|
965
970
|
this.emit('error', new Error(message));
|
|
966
971
|
};
|
|
967
972
|
|
|
968
|
-
var Stream = stream__default[
|
|
973
|
+
var Stream$1 = stream__default["default"].Stream;
|
|
969
974
|
|
|
970
975
|
|
|
971
976
|
var combined_stream = CombinedStream;
|
|
@@ -982,7 +987,7 @@ function CombinedStream() {
|
|
|
982
987
|
this._insideLoop = false;
|
|
983
988
|
this._pendingNext = false;
|
|
984
989
|
}
|
|
985
|
-
util__default[
|
|
990
|
+
util__default["default"].inherits(CombinedStream, Stream$1);
|
|
986
991
|
|
|
987
992
|
CombinedStream.create = function(options) {
|
|
988
993
|
var combinedStream = new this();
|
|
@@ -1028,7 +1033,7 @@ CombinedStream.prototype.append = function(stream) {
|
|
|
1028
1033
|
};
|
|
1029
1034
|
|
|
1030
1035
|
CombinedStream.prototype.pipe = function(dest, options) {
|
|
1031
|
-
Stream.prototype.pipe.call(this, dest, options);
|
|
1036
|
+
Stream$1.prototype.pipe.call(this, dest, options);
|
|
1032
1037
|
this.resume();
|
|
1033
1038
|
return dest;
|
|
1034
1039
|
};
|
|
@@ -10864,7 +10869,7 @@ var mimeTypes = createCommonjsModule(function (module, exports) {
|
|
|
10864
10869
|
*/
|
|
10865
10870
|
|
|
10866
10871
|
|
|
10867
|
-
var extname = path__default[
|
|
10872
|
+
var extname = path__default["default"].extname;
|
|
10868
10873
|
|
|
10869
10874
|
/**
|
|
10870
10875
|
* Module variables.
|
|
@@ -11418,8 +11423,9 @@ var populate = function(dst, src) {
|
|
|
11418
11423
|
return dst;
|
|
11419
11424
|
};
|
|
11420
11425
|
|
|
11421
|
-
var parseUrl = url__default[
|
|
11426
|
+
var parseUrl = url__default["default"].parse;
|
|
11422
11427
|
|
|
11428
|
+
var Stream = stream__default["default"].Stream;
|
|
11423
11429
|
|
|
11424
11430
|
|
|
11425
11431
|
|
|
@@ -11428,7 +11434,7 @@ var parseUrl = url__default['default'].parse;
|
|
|
11428
11434
|
var form_data = FormData;
|
|
11429
11435
|
|
|
11430
11436
|
// make it a Stream
|
|
11431
|
-
util__default[
|
|
11437
|
+
util__default["default"].inherits(FormData, combined_stream);
|
|
11432
11438
|
|
|
11433
11439
|
/**
|
|
11434
11440
|
* Create readable "multipart/form-data" streams.
|
|
@@ -11475,7 +11481,7 @@ FormData.prototype.append = function(field, value, options) {
|
|
|
11475
11481
|
}
|
|
11476
11482
|
|
|
11477
11483
|
// https://github.com/felixge/node-form-data/issues/38
|
|
11478
|
-
if (util__default[
|
|
11484
|
+
if (util__default["default"].isArray(value)) {
|
|
11479
11485
|
// Please convert your array into string
|
|
11480
11486
|
// the way web server expects it
|
|
11481
11487
|
this._error(new Error('Arrays are not supported.'));
|
|
@@ -11515,8 +11521,8 @@ FormData.prototype._trackLength = function(header, value, options) {
|
|
|
11515
11521
|
Buffer.byteLength(header) +
|
|
11516
11522
|
FormData.LINE_BREAK.length;
|
|
11517
11523
|
|
|
11518
|
-
// empty or either doesn't have path or not an http response
|
|
11519
|
-
if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) )) {
|
|
11524
|
+
// empty or either doesn't have path or not an http response or not a stream
|
|
11525
|
+
if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
|
|
11520
11526
|
return;
|
|
11521
11527
|
}
|
|
11522
11528
|
|
|
@@ -11547,7 +11553,7 @@ FormData.prototype._lengthRetriever = function(value, callback) {
|
|
|
11547
11553
|
// not that fast snoopy
|
|
11548
11554
|
} else {
|
|
11549
11555
|
// still need to fetch file size from fs
|
|
11550
|
-
fs__default[
|
|
11556
|
+
fs__default["default"].stat(value.path, function(err, stat) {
|
|
11551
11557
|
|
|
11552
11558
|
var fileSize;
|
|
11553
11559
|
|
|
@@ -11637,15 +11643,15 @@ FormData.prototype._getContentDisposition = function(value, options) {
|
|
|
11637
11643
|
|
|
11638
11644
|
if (typeof options.filepath === 'string') {
|
|
11639
11645
|
// custom filepath for relative paths
|
|
11640
|
-
filename = path__default[
|
|
11646
|
+
filename = path__default["default"].normalize(options.filepath).replace(/\\/g, '/');
|
|
11641
11647
|
} else if (options.filename || value.name || value.path) {
|
|
11642
11648
|
// custom filename take precedence
|
|
11643
11649
|
// formidable and the browser add a name property
|
|
11644
11650
|
// fs- and request- streams have path property
|
|
11645
|
-
filename = path__default[
|
|
11651
|
+
filename = path__default["default"].basename(options.filename || value.name || value.path);
|
|
11646
11652
|
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
|
|
11647
11653
|
// or try http response
|
|
11648
|
-
filename = path__default[
|
|
11654
|
+
filename = path__default["default"].basename(value.client._httpMessage.path || '');
|
|
11649
11655
|
}
|
|
11650
11656
|
|
|
11651
11657
|
if (filename) {
|
|
@@ -11864,20 +11870,22 @@ FormData.prototype.submit = function(params, cb) {
|
|
|
11864
11870
|
|
|
11865
11871
|
// https if specified, fallback to http in any other case
|
|
11866
11872
|
if (options.protocol == 'https:') {
|
|
11867
|
-
request = https__default[
|
|
11873
|
+
request = https__default["default"].request(options);
|
|
11868
11874
|
} else {
|
|
11869
|
-
request = http__default[
|
|
11875
|
+
request = http__default["default"].request(options);
|
|
11870
11876
|
}
|
|
11871
11877
|
|
|
11872
11878
|
// get content length and fire away
|
|
11873
11879
|
this.getLength(function(err, length) {
|
|
11874
|
-
if (err) {
|
|
11880
|
+
if (err && err !== 'Unknown stream') {
|
|
11875
11881
|
this._error(err);
|
|
11876
11882
|
return;
|
|
11877
11883
|
}
|
|
11878
11884
|
|
|
11879
11885
|
// add content length
|
|
11880
|
-
|
|
11886
|
+
if (length) {
|
|
11887
|
+
request.setHeader('Content-Length', length);
|
|
11888
|
+
}
|
|
11881
11889
|
|
|
11882
11890
|
this.pipe(request);
|
|
11883
11891
|
if (cb) {
|
|
@@ -11949,7 +11957,7 @@ const isEligibleForClientRedirect = (params) => {
|
|
|
11949
11957
|
return false;
|
|
11950
11958
|
}
|
|
11951
11959
|
};
|
|
11952
|
-
const getRedirectUrl = (params) => `${params.oauthUrl}/oauth/authorize?${querystring__default[
|
|
11960
|
+
const getRedirectUrl = (params) => `${params.oauthUrl}/oauth/authorize?${querystring__default["default"].stringify(castToAuthorizationRequestParams(params))}`;
|
|
11953
11961
|
|
|
11954
11962
|
const GRANT_TYPE = 'password';
|
|
11955
11963
|
const castToTokenRequestParams = (params) => {
|
|
@@ -11988,7 +11996,7 @@ async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefr
|
|
|
11988
11996
|
return oauthTokenStore.set(await requestToken(tokenFetcher, options));
|
|
11989
11997
|
}
|
|
11990
11998
|
if (typeof window !== 'undefined' && options.implicit) {
|
|
11991
|
-
const parsedLocationHash = querystring__default[
|
|
11999
|
+
const parsedLocationHash = querystring__default["default"].parse(window.location.hash);
|
|
11992
12000
|
const accessToken = parsedLocationHash && parsedLocationHash.access_token;
|
|
11993
12001
|
if (accessToken) {
|
|
11994
12002
|
window.history.replaceState({}, '', window.location.href.split('#')[0]);
|
|
@@ -12013,21 +12021,16 @@ async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefr
|
|
|
12013
12021
|
}
|
|
12014
12022
|
|
|
12015
12023
|
function sleep(miliseconds) {
|
|
12016
|
-
return new Promise(resolve => setTimeout(() => resolve(true), miliseconds));
|
|
12024
|
+
return new Promise((resolve) => setTimeout(() => resolve(true), miliseconds));
|
|
12017
12025
|
}
|
|
12018
12026
|
|
|
12019
12027
|
const requestLogger = makeLogger('REST API Request');
|
|
12020
12028
|
const responseLogger = makeLogger('REST API Response');
|
|
12021
12029
|
const RETRYABLE_STATUS_CODES = [
|
|
12022
|
-
401,
|
|
12023
|
-
408,
|
|
12024
|
-
429,
|
|
12025
|
-
502,
|
|
12026
|
-
503,
|
|
12027
|
-
504,
|
|
12030
|
+
401, 408, 429, 502, 503, 504,
|
|
12028
12031
|
];
|
|
12029
12032
|
const TOKEN_REFRESH_STATUS_CODES = [401];
|
|
12030
|
-
const queue = new Bottleneck__default[
|
|
12033
|
+
const queue = new Bottleneck__default["default"]({
|
|
12031
12034
|
maxConcurrent: QUEUE_CONCURRENCY,
|
|
12032
12035
|
minTime: QUEUE_DELAY,
|
|
12033
12036
|
reservoir: QUEUE_RESERVOIR,
|
|
@@ -12041,7 +12044,7 @@ function refillReservoir() {
|
|
|
12041
12044
|
const interval = setInterval(async () => {
|
|
12042
12045
|
const reservoir = (await queue.currentReservoir());
|
|
12043
12046
|
if (queue.empty() && (await queue.running()) === 0 && reservoir > 10) {
|
|
12044
|
-
return (queue.incrementReservoir(1) &&
|
|
12047
|
+
return ((await queue.incrementReservoir(1)) &&
|
|
12045
12048
|
fnClearInterval(interval) &&
|
|
12046
12049
|
refillIntervalSet.delete(interval));
|
|
12047
12050
|
}
|
|
@@ -12096,7 +12099,7 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
|
|
|
12096
12099
|
const method = httpMethod.toUpperCase();
|
|
12097
12100
|
const payloadQuery = payload && payload.query
|
|
12098
12101
|
? (apiMethod.includes('?') ? '&' : '?') +
|
|
12099
|
-
querystring__default[
|
|
12102
|
+
querystring__default["default"].stringify(payload.query)
|
|
12100
12103
|
: '';
|
|
12101
12104
|
const url = `${options.apiUrl}/api${apiMethod}${payloadQuery}`;
|
|
12102
12105
|
const body = payload && payload.body;
|
|
@@ -12115,7 +12118,7 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
|
|
|
12115
12118
|
const requestBody = {
|
|
12116
12119
|
body: hasForm ? formData : JSON.stringify(body),
|
|
12117
12120
|
};
|
|
12118
|
-
const response = await fetch__default[
|
|
12121
|
+
const response = await fetch__default["default"](url, Object.assign({ cache: 'no-cache', credentials: 'omit', headers,
|
|
12119
12122
|
method, mode: 'cors' }, (hasForm || body ? requestBody : {})));
|
|
12120
12123
|
const result = await makeResultFromResponse(response);
|
|
12121
12124
|
responseLogger.log(method, url, result instanceof Error
|
|
@@ -12212,6 +12215,8 @@ const API_METHODS = [
|
|
|
12212
12215
|
utilisationPeriodCheckInUser,
|
|
12213
12216
|
utilisationPeriodCheckOutUser,
|
|
12214
12217
|
utilisationPeriodAddRegistrationCode,
|
|
12218
|
+
bookingUpdateById,
|
|
12219
|
+
bookingGetById,
|
|
12215
12220
|
];
|
|
12216
12221
|
function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
|
|
12217
12222
|
const options = Object.assign(Object.assign({}, DEFAULT_API_WRAPPER_OPTIONS), userOptions);
|