@karpeleslab/klbfw 0.2.1 → 0.2.2

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 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 = () => getFWProperty('call_url_prefix', 'https://hub.atonline.com');
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.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
- if (fwWrapper.getCallUrlPrefix()) return fwWrapper.getCallUrlPrefix() + "/_rest/" + path;
55
- return "/_rest/" + path;
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 = "/_rest/" + path + "?static";
73
+ callUrl = apiPrefixPath + "?static";
64
74
  glue = '&';
65
75
  } else {
66
- callUrl = "/_rest/" + path;
76
+ callUrl = apiPrefixPath;
67
77
  }
68
78
 
69
- if (fwWrapper.getCallUrlPrefix()) {
70
- callUrl = fwWrapper.getCallUrlPrefix() + callUrl;
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]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karpeleslab/klbfw",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Frontend Framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",