@djust-b2b/djust-front-sdk 1.7.3 → 1.7.5
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.
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.enhancedFetch = exports.updateConfiguration = exports.initialize = void 0;
|
|
27
27
|
const qs = __importStar(require("query-string"));
|
|
28
|
-
const utils_1 = require("../helpers/utils");
|
|
29
28
|
require("isomorphic-fetch");
|
|
30
29
|
let clientConfig = { baseUrl: "", clientId: "", apiKey: "" };
|
|
31
30
|
const initialize = (initConfig) => {
|
|
@@ -52,7 +51,7 @@ const serializeParams = (params, useRepeat) => {
|
|
|
52
51
|
return qs.stringify(params, { arrayFormat: "bracket", skipNull: true });
|
|
53
52
|
};
|
|
54
53
|
const enhancedFetch = async ({ path, method, params, body, }) => {
|
|
55
|
-
var _a;
|
|
54
|
+
var _a, _b, _c;
|
|
56
55
|
if (!isClientInitialized(clientConfig)) {
|
|
57
56
|
throw new Error('[Djust SDK] SDK not initialized. Provide both client ID and API key via the "initialize" method.');
|
|
58
57
|
}
|
|
@@ -62,12 +61,12 @@ const enhancedFetch = async ({ path, method, params, body, }) => {
|
|
|
62
61
|
"dj-api-key": apiKey,
|
|
63
62
|
"Content-Type": "application/json",
|
|
64
63
|
});
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
64
|
+
// if (isBrowser()) {
|
|
65
|
+
// const token = getCookie("token");
|
|
66
|
+
// if (token) {
|
|
67
|
+
// requestHeaders.append("Authorization", `Bearer ${token}`);
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
71
70
|
if (accessToken)
|
|
72
71
|
requestHeaders.append("Authorization", `Bearer ${accessToken}`);
|
|
73
72
|
if (locale)
|
|
@@ -103,6 +102,12 @@ const enhancedFetch = async ({ path, method, params, body, }) => {
|
|
|
103
102
|
const data = isJsonResponse && responseText
|
|
104
103
|
? JSON.parse(responseText)
|
|
105
104
|
: {};
|
|
105
|
+
// Check if response data contains new accessToken and update configuration
|
|
106
|
+
if (data && ((_b = data === null || data === void 0 ? void 0 : data.token) === null || _b === void 0 ? void 0 : _b.accessToken)) {
|
|
107
|
+
(0, exports.updateConfiguration)({
|
|
108
|
+
accessToken: (_c = data === null || data === void 0 ? void 0 : data.token) === null || _c === void 0 ? void 0 : _c.accessToken,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
106
111
|
return { data, headers, status };
|
|
107
112
|
}
|
|
108
113
|
catch (error) {
|