@hubs101/js-api-skd-client 1.0.10299 → 1.0.10300
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/authentication/index.js +0 -2
- package/lib/api/event/index.js +2 -2
- package/lib/utils/api.d.ts +1 -0
- package/lib/utils/api.js +44 -7
- package/package.json +1 -1
|
@@ -95,8 +95,6 @@ const _confirmManager = (basePath, accountId, data) => __awaiter(void 0, void 0,
|
|
|
95
95
|
exports._confirmManager = _confirmManager;
|
|
96
96
|
const _inviteFinanceManager = (basePath, token, accountId, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
97
|
const base = (0, base_1.getBasePath)(basePath);
|
|
98
|
-
console.log({ data });
|
|
99
|
-
console.log({ token });
|
|
100
98
|
const response = yield (0, api_1.postRequestWE)(`${base.ACCOUNTS}/${accountId}/managers/finances`, data, token);
|
|
101
99
|
return response;
|
|
102
100
|
});
|
package/lib/api/event/index.js
CHANGED
|
@@ -294,13 +294,13 @@ const _fetchEventGroups = (basePath, token, eventId) => __awaiter(void 0, void 0
|
|
|
294
294
|
exports._fetchEventGroups = _fetchEventGroups;
|
|
295
295
|
const _checkBooking = (basePath, body, lang) => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
296
|
const base = (0, base_1.getBasePath)(basePath);
|
|
297
|
-
const response = yield (0, api_1.
|
|
297
|
+
const response = yield (0, api_1.postRequestJSON)(`${base.PUBLIC_BOOKINGS}/check?lang=${lang}`, body, null, { "Content-Type": "application/json" });
|
|
298
298
|
return response;
|
|
299
299
|
});
|
|
300
300
|
exports._checkBooking = _checkBooking;
|
|
301
301
|
const _createBooking = (basePath, body, lang) => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
302
|
const base = (0, base_1.getBasePath)(basePath);
|
|
303
|
-
const response = yield (0, api_1.
|
|
303
|
+
const response = yield (0, api_1.postRequestJSON)(`${base.PUBLIC_BOOKINGS}?lang=${lang}`, body, null, { "Content-Type": "application/json" });
|
|
304
304
|
return response;
|
|
305
305
|
});
|
|
306
306
|
exports._createBooking = _createBooking;
|
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 postRequestJSON: (url: string, body?: any, token?: string, headers?: any) => Promise<any>;
|
package/lib/utils/api.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
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;
|
|
12
|
+
exports.postRequestJSON = 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
13
|
exports.error400 = '"status":400';
|
|
14
14
|
const trimUndefined = (obj) => Object.keys(obj).reduce((result, key) => obj[key] === undefined ? result : ((result[key] = obj[key]), result), {});
|
|
15
15
|
exports.trimUndefined = trimUndefined;
|
|
@@ -353,9 +353,8 @@ const postRequestWE = (url, body, token, headers) => __awaiter(void 0, void 0, v
|
|
|
353
353
|
var _e;
|
|
354
354
|
let form;
|
|
355
355
|
if (body) {
|
|
356
|
-
if (
|
|
357
|
-
headers["Content-Type"] === "application/x-www-form-urlencoded")
|
|
358
|
-
headers["Content-Type"] === "application/json") {
|
|
356
|
+
if (headers &&
|
|
357
|
+
headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
359
358
|
form = new URLSearchParams();
|
|
360
359
|
}
|
|
361
360
|
else {
|
|
@@ -369,9 +368,7 @@ const postRequestWE = (url, body, token, headers) => __awaiter(void 0, void 0, v
|
|
|
369
368
|
method: "POST",
|
|
370
369
|
headers: token
|
|
371
370
|
? Object.assign({ Authorization: `Bearer ${token}` }, headers) : Object.assign({}, headers),
|
|
372
|
-
body:
|
|
373
|
-
? JSON.stringify(body)
|
|
374
|
-
: form,
|
|
371
|
+
body: form,
|
|
375
372
|
});
|
|
376
373
|
if (String(response.status).startsWith("5")) {
|
|
377
374
|
throw new Error(response.statusText);
|
|
@@ -425,3 +422,43 @@ const postFileRequestWE = (url, file, param, token) => __awaiter(void 0, void 0,
|
|
|
425
422
|
return data === null || data === void 0 ? void 0 : data.result;
|
|
426
423
|
});
|
|
427
424
|
exports.postFileRequestWE = postFileRequestWE;
|
|
425
|
+
const postRequestJSON = (url, body, token, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
426
|
+
var _f;
|
|
427
|
+
let form;
|
|
428
|
+
if (body) {
|
|
429
|
+
if ((headers &&
|
|
430
|
+
headers["Content-Type"] === "application/x-www-form-urlencoded") ||
|
|
431
|
+
headers["Content-Type"] === "application/json") {
|
|
432
|
+
form = new URLSearchParams();
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
form = new FormData();
|
|
436
|
+
}
|
|
437
|
+
Object.keys((0, exports.trimUndefined)(body)).forEach((key) => Array.isArray(body[key])
|
|
438
|
+
? form.append(key, JSON.stringify(body[key]))
|
|
439
|
+
: form.append(key, body[key]));
|
|
440
|
+
}
|
|
441
|
+
const response = yield fetch(url, {
|
|
442
|
+
method: "POST",
|
|
443
|
+
headers: token
|
|
444
|
+
? Object.assign({ Authorization: `Bearer ${token}` }, headers) : Object.assign({}, headers),
|
|
445
|
+
body: headers["Content-Type"] === "application/json"
|
|
446
|
+
? JSON.stringify(body)
|
|
447
|
+
: form,
|
|
448
|
+
});
|
|
449
|
+
if (String(response.status).startsWith("5")) {
|
|
450
|
+
throw new Error(response.statusText);
|
|
451
|
+
}
|
|
452
|
+
const data = yield response.json();
|
|
453
|
+
if ((data === null || data === void 0 ? void 0 : data.message_code) === 40900000) {
|
|
454
|
+
throw new Error("errors.api-40900000");
|
|
455
|
+
}
|
|
456
|
+
if (data.status === 400 && data.invalid_fields) {
|
|
457
|
+
throw new Error((_f = Object.values(data === null || data === void 0 ? void 0 : data.invalid_fields)) === null || _f === void 0 ? void 0 : _f.toString());
|
|
458
|
+
}
|
|
459
|
+
if (String(data.status).startsWith("4")) {
|
|
460
|
+
throw new Error(data.message);
|
|
461
|
+
}
|
|
462
|
+
return data;
|
|
463
|
+
});
|
|
464
|
+
exports.postRequestJSON = postRequestJSON;
|