@karpeleslab/klbfw 0.2.1 → 0.2.3
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/fw-wrapper.js +21 -3
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/internal.js +19 -6
- package/package.json +1 -1
package/fw-wrapper.js
CHANGED
|
@@ -138,11 +138,29 @@ const getUrl = () => {
|
|
|
138
138
|
*/
|
|
139
139
|
const getSiteStatic = () => getFWProperty('site_static', true);
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Gets the API prefix
|
|
143
|
+
* @returns {string|undefined} API prefix
|
|
144
|
+
*/
|
|
145
|
+
const getApiPrefix = () => {
|
|
146
|
+
if (typeof FW !== "undefined") {
|
|
147
|
+
return FW.api_prefix; // Return undefined if property doesn't exist
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
|
|
141
152
|
/**
|
|
142
153
|
* Gets the API call URL prefix
|
|
143
|
-
* @returns {string} API call URL prefix
|
|
154
|
+
* @returns {string|undefined} API call URL prefix
|
|
144
155
|
*/
|
|
145
|
-
const getCallUrlPrefix = () =>
|
|
156
|
+
const getCallUrlPrefix = () => {
|
|
157
|
+
// In original code, if FW existed but call_url_prefix wasn't set, it would return undefined
|
|
158
|
+
if (typeof FW !== "undefined") {
|
|
159
|
+
return FW.call_url_prefix; // Return undefined if property doesn't exist
|
|
160
|
+
}
|
|
161
|
+
// Only use fallback in non-browser environments
|
|
162
|
+
return typeof window === "undefined" ? 'https://hub.atonline.com' : undefined;
|
|
163
|
+
};
|
|
146
164
|
|
|
147
165
|
/**
|
|
148
166
|
* Gets the site UUID
|
|
@@ -215,7 +233,7 @@ module.exports.getCallUrlPrefix = getCallUrlPrefix;
|
|
|
215
233
|
module.exports.getUuid = getUuid;
|
|
216
234
|
module.exports.getInitialState = getInitialState;
|
|
217
235
|
module.exports.supported = supported;
|
|
218
|
-
module.exports.GET = getGET
|
|
236
|
+
module.exports.GET = getGET;
|
|
219
237
|
module.exports.Get = getParam;
|
|
220
238
|
module.exports.flushGet = flushGet;
|
|
221
239
|
module.exports.getMode = getMode;
|
package/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare function getLocale(): string;
|
|
|
18
18
|
declare function getUserGroup(): string | undefined;
|
|
19
19
|
declare function getCurrency(): string;
|
|
20
20
|
declare function getToken(): string | undefined;
|
|
21
|
-
declare function getUrl(): { path: string; full: string };
|
|
21
|
+
declare function getUrl(): { path: string; full: string; host: string; query: string; scheme: string };
|
|
22
22
|
declare function getPath(): string;
|
|
23
23
|
declare function getUuid(): string | undefined;
|
|
24
24
|
declare function getInitialState(): Record<string, any> | undefined;
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const util = require('./util');
|
|
|
13
13
|
const cookies = require('./cookies');
|
|
14
14
|
|
|
15
15
|
// Framework wrapper exports
|
|
16
|
-
module.exports.GET = internalFW.GET;
|
|
16
|
+
module.exports.GET = internalFW.GET; // Use the function directly
|
|
17
17
|
module.exports.Get = internalFW.Get;
|
|
18
18
|
module.exports.flushGet = internalFW.flushGet;
|
|
19
19
|
module.exports.getPrefix = internalFW.getPrefix;
|
package/internal.js
CHANGED
|
@@ -50,24 +50,36 @@ const getTimezoneData = () => {
|
|
|
50
50
|
* @returns {string} Constructed URL
|
|
51
51
|
*/
|
|
52
52
|
const buildRestUrl = (path, withToken, context) => {
|
|
53
|
+
// Check for api_prefix
|
|
54
|
+
const apiPrefixPath = typeof FW !== "undefined" && FW.api_prefix ?
|
|
55
|
+
FW.api_prefix + "/_rest/" + path :
|
|
56
|
+
"/_rest/" + path;
|
|
57
|
+
|
|
58
|
+
// For non-authenticated requests
|
|
53
59
|
if (!withToken) {
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
const prefix = fwWrapper.getCallUrlPrefix();
|
|
61
|
+
if (prefix) {
|
|
62
|
+
return prefix + apiPrefixPath;
|
|
63
|
+
}
|
|
64
|
+
return apiPrefixPath;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
context = context || {};
|
|
59
68
|
let glue = '?';
|
|
60
69
|
|
|
70
|
+
// Start building the URL
|
|
61
71
|
let callUrl;
|
|
62
72
|
if (fwWrapper.getSiteStatic()) {
|
|
63
|
-
callUrl =
|
|
73
|
+
callUrl = apiPrefixPath + "?static";
|
|
64
74
|
glue = '&';
|
|
65
75
|
} else {
|
|
66
|
-
callUrl =
|
|
76
|
+
callUrl = apiPrefixPath;
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
if
|
|
70
|
-
|
|
79
|
+
// Add call_url_prefix if it exists
|
|
80
|
+
const prefix = fwWrapper.getCallUrlPrefix();
|
|
81
|
+
if (prefix) {
|
|
82
|
+
callUrl = prefix + callUrl;
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
// Copy context, proceed with overload then add to url
|
|
@@ -76,6 +88,7 @@ const buildRestUrl = (path, withToken, context) => {
|
|
|
76
88
|
ctxFinal[key] = context[key];
|
|
77
89
|
}
|
|
78
90
|
|
|
91
|
+
// Add context parameters to URL
|
|
79
92
|
for (const key in ctxFinal) {
|
|
80
93
|
if (key === "_") continue;
|
|
81
94
|
callUrl = callUrl + glue + "_ctx[" + key + "]=" + encodeURIComponent(ctxFinal[key]);
|