@hubs101/js-api-skd-client 1.0.10248 → 1.0.10249
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/lib/api/event/index.js +1 -1
- package/lib/utils/api.d.ts +1 -0
- package/lib/utils/api.js +38 -1
- package/package.json +1 -1
package/lib/api/event/index.js
CHANGED
|
@@ -288,7 +288,7 @@ const _fetchEventGroups = (basePath, token, eventId) => __awaiter(void 0, void 0
|
|
|
288
288
|
exports._fetchEventGroups = _fetchEventGroups;
|
|
289
289
|
const _fetchMyBookings = (basePath, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
290
|
const base = (0, base_1.getBasePath)(basePath);
|
|
291
|
-
const { data: groups } = yield (0, api_1.
|
|
291
|
+
const { data: groups } = yield (0, api_1.getRequestWE)(`${base.USERS}/bookings?limit=2000`, token);
|
|
292
292
|
return groups;
|
|
293
293
|
});
|
|
294
294
|
exports._fetchMyBookings = _fetchMyBookings;
|
package/lib/utils/api.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare const postRequestWithRetry: (url: string, body?: any, token?: str
|
|
|
19
19
|
export declare const postRequestWE: (url: string, body?: any, token?: string, headers?: any) => Promise<any>;
|
|
20
20
|
export declare const deleteRequestWE: (url: string, token: string) => Promise<any>;
|
|
21
21
|
export declare const postFileRequestWE: (url: string, file: File, param: string, token: string) => Promise<any>;
|
|
22
|
+
export declare const getRequestWE: (url: string, token?: string, headers?: any) => Promise<any>;
|
package/lib/utils/api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable prettier/prettier */
|
|
2
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
10
|
});
|
|
10
11
|
};
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.postFileRequestWE = exports.deleteRequestWE = exports.postRequestWE = exports.postRequestWithRetry = exports.postFilesAndDataRequest = exports.validateConfig = exports.getFormRequest = exports.getRequest = exports.patchRequest = exports.putRequest = exports.postFileRequest = exports.deleteRequest = exports.getRequestSimple = exports.postRequestSimple = exports.postRequest = exports.trimUndefined = exports.error400 = void 0;
|
|
13
|
+
exports.getRequestWE = exports.postFileRequestWE = exports.deleteRequestWE = exports.postRequestWE = exports.postRequestWithRetry = exports.postFilesAndDataRequest = exports.validateConfig = exports.getFormRequest = exports.getRequest = exports.patchRequest = exports.putRequest = exports.postFileRequest = exports.deleteRequest = exports.getRequestSimple = exports.postRequestSimple = exports.postRequest = exports.trimUndefined = exports.error400 = void 0;
|
|
13
14
|
exports.error400 = '"status":400';
|
|
14
15
|
const trimUndefined = (obj) => Object.keys(obj).reduce((result, key) => obj[key] === undefined ? result : ((result[key] = obj[key]), result), {});
|
|
15
16
|
exports.trimUndefined = trimUndefined;
|
|
@@ -422,3 +423,39 @@ const postFileRequestWE = (url, file, param, token) => __awaiter(void 0, void 0,
|
|
|
422
423
|
return data === null || data === void 0 ? void 0 : data.result;
|
|
423
424
|
});
|
|
424
425
|
exports.postFileRequestWE = postFileRequestWE;
|
|
426
|
+
const getRequestWE = (url, token, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
+
const response = yield fetch(url, {
|
|
428
|
+
method: "GET",
|
|
429
|
+
headers: Object.assign({ accept: "application/json", Authorization: `Bearer ${token}` }, headers),
|
|
430
|
+
});
|
|
431
|
+
const data = yield response.json();
|
|
432
|
+
if ((data === null || data === void 0 ? void 0 : data.message_code) === 40100001) {
|
|
433
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
434
|
+
console.log(`Error:${data.status} for url:${url}`);
|
|
435
|
+
throw new Error(String(data === null || data === void 0 ? void 0 : data.message_code));
|
|
436
|
+
}
|
|
437
|
+
if (String(data === null || data === void 0 ? void 0 : data.status).startsWith("4")) {
|
|
438
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
439
|
+
console.log(`Error:${data.status} for url:${url}`);
|
|
440
|
+
throw new Error(data.message);
|
|
441
|
+
}
|
|
442
|
+
if ((data === null || data === void 0 ? void 0 : data.error) && (data === null || data === void 0 ? void 0 : data.message)) {
|
|
443
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
444
|
+
console.log(`Error:${data.status} for url:${url}`);
|
|
445
|
+
throw new Error(data.message);
|
|
446
|
+
}
|
|
447
|
+
if ((data === null || data === void 0 ? void 0 : data.code) === 429) {
|
|
448
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
449
|
+
console.log(`Error to may requests for for url:${url}`);
|
|
450
|
+
throw new Error("Error:" + String(data.msg || data.message) + " Try again in 30-60 sec.");
|
|
451
|
+
}
|
|
452
|
+
// handling inconsistency in API response format
|
|
453
|
+
if (Array.isArray(data === null || data === void 0 ? void 0 : data.members)) {
|
|
454
|
+
return data.members;
|
|
455
|
+
}
|
|
456
|
+
if ((data === null || data === void 0 ? void 0 : data.result) && typeof (data === null || data === void 0 ? void 0 : data.result) !== "string") {
|
|
457
|
+
return data.result;
|
|
458
|
+
}
|
|
459
|
+
return data;
|
|
460
|
+
});
|
|
461
|
+
exports.getRequestWE = getRequestWE;
|