@karpeleslab/klbfw 0.2.0 → 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 +21 -3
- package/index.d.ts +81 -0
- package/index.js +1 -1
- package/internal.js +19 -6
- package/package.json +8 -1
- package/CLAUDE.md +0 -50
- package/coverage/clover.xml +0 -835
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/cookies.js.html +0 -334
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fw-wrapper.js.html +0 -163
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/index.js.html +0 -196
- package/coverage/lcov-report/internal.js.html +0 -604
- package/coverage/lcov-report/klbfw/cookies.js.html +0 -490
- package/coverage/lcov-report/klbfw/fw-wrapper.js.html +0 -745
- package/coverage/lcov-report/klbfw/index.html +0 -206
- package/coverage/lcov-report/klbfw/index.js.html +0 -235
- package/coverage/lcov-report/klbfw/internal.js.html +0 -811
- package/coverage/lcov-report/klbfw/rest.js.html +0 -565
- package/coverage/lcov-report/klbfw/test/index.html +0 -116
- package/coverage/lcov-report/klbfw/test/setup.js.html +0 -1105
- package/coverage/lcov-report/klbfw/upload.js.html +0 -3487
- package/coverage/lcov-report/klbfw/util.js.html +0 -388
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/rest.js.html +0 -472
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/upload.js.html +0 -1789
- package/coverage/lcov-report/util.js.html +0 -313
- package/coverage/lcov.info +0 -1617
- package/test/README.md +0 -62
- package/test/api.test.js +0 -102
- package/test/cookies.test.js +0 -65
- package/test/integration.test.js +0 -481
- package/test/rest.test.js +0 -93
- package/test/setup.js +0 -341
- package/test/upload.test.js +0 -689
- package/test/util.test.js +0 -46
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
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for @karpeleslab/klbfw
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Framework wrapper types
|
|
6
|
+
declare function GET(): Record<string, string>;
|
|
7
|
+
declare function Get(key?: string): string | Record<string, string> | undefined;
|
|
8
|
+
declare function flushGet(): void;
|
|
9
|
+
declare function getPrefix(): string;
|
|
10
|
+
declare function getSettings(): Record<string, any>;
|
|
11
|
+
declare function getRealm(): Record<string, any>;
|
|
12
|
+
declare function getContext(): Record<string, any>;
|
|
13
|
+
declare function setContext(key: string, value: any): void;
|
|
14
|
+
declare function getMode(): string;
|
|
15
|
+
declare function getHostname(): string;
|
|
16
|
+
declare function getRegistry(): Record<string, any> | undefined;
|
|
17
|
+
declare function getLocale(): string;
|
|
18
|
+
declare function getUserGroup(): string | undefined;
|
|
19
|
+
declare function getCurrency(): string;
|
|
20
|
+
declare function getToken(): string | undefined;
|
|
21
|
+
declare function getUrl(): { path: string; full: string };
|
|
22
|
+
declare function getPath(): string;
|
|
23
|
+
declare function getUuid(): string | undefined;
|
|
24
|
+
declare function getInitialState(): Record<string, any> | undefined;
|
|
25
|
+
|
|
26
|
+
// Cookie handling types
|
|
27
|
+
declare function getCookie(name: string): string | null;
|
|
28
|
+
declare function hasCookie(name: string): boolean;
|
|
29
|
+
declare function setCookie(name: string, value: string, expires?: Date | number, path?: string, domain?: string, secure?: boolean): void;
|
|
30
|
+
|
|
31
|
+
// REST API types
|
|
32
|
+
declare function rest(name: string, verb: string, params?: Record<string, any> | string, context?: Record<string, any>): Promise<any>;
|
|
33
|
+
declare function rest_get(name: string, params?: Record<string, any> | string): Promise<any>; // Backward compatibility
|
|
34
|
+
declare function restGet(name: string, params?: Record<string, any> | string): Promise<any>;
|
|
35
|
+
|
|
36
|
+
// Upload module types
|
|
37
|
+
interface UploadOptions {
|
|
38
|
+
progress?: (progress: number) => void;
|
|
39
|
+
endpoint?: string;
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
retry?: number;
|
|
42
|
+
chunk_size?: number;
|
|
43
|
+
params?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare function upload(file: File, options?: UploadOptions): Promise<any>;
|
|
47
|
+
|
|
48
|
+
// Utility types
|
|
49
|
+
declare function getI18N(key: string, args?: Record<string, any>): string;
|
|
50
|
+
declare function trimPrefix(path: string): string;
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
GET,
|
|
54
|
+
Get,
|
|
55
|
+
flushGet,
|
|
56
|
+
getPrefix,
|
|
57
|
+
getSettings,
|
|
58
|
+
getRealm,
|
|
59
|
+
getContext,
|
|
60
|
+
setContext,
|
|
61
|
+
getMode,
|
|
62
|
+
getHostname,
|
|
63
|
+
getRegistry,
|
|
64
|
+
getLocale,
|
|
65
|
+
getUserGroup,
|
|
66
|
+
getCurrency,
|
|
67
|
+
getToken,
|
|
68
|
+
getUrl,
|
|
69
|
+
getPath,
|
|
70
|
+
getUuid,
|
|
71
|
+
getInitialState,
|
|
72
|
+
getCookie,
|
|
73
|
+
hasCookie,
|
|
74
|
+
setCookie,
|
|
75
|
+
rest,
|
|
76
|
+
rest_get,
|
|
77
|
+
restGet,
|
|
78
|
+
upload,
|
|
79
|
+
getI18N,
|
|
80
|
+
trimPrefix
|
|
81
|
+
};
|
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]);
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karpeleslab/klbfw",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Frontend Framework",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"*.js",
|
|
9
|
+
"*.d.ts",
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
6
13
|
"scripts": {
|
|
7
14
|
"test": "jest",
|
|
8
15
|
"test:watch": "jest --watch",
|
package/CLAUDE.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# KarpelesLab Frontend Framework (klbfw) Guidelines
|
|
2
|
-
|
|
3
|
-
## Commands
|
|
4
|
-
```
|
|
5
|
-
# Install dependencies
|
|
6
|
-
npm install
|
|
7
|
-
|
|
8
|
-
# Run tests
|
|
9
|
-
npm test
|
|
10
|
-
|
|
11
|
-
# Run tests in watch mode
|
|
12
|
-
npm run test:watch
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Code Style Guidelines
|
|
16
|
-
|
|
17
|
-
### Formatting
|
|
18
|
-
- Use 'use strict' directive at top of files
|
|
19
|
-
- 4-space indentation (configured in vim: et:ts=4:sw=4)
|
|
20
|
-
- Use semicolons consistently
|
|
21
|
-
- Use single quotes for strings
|
|
22
|
-
|
|
23
|
-
### Imports/Exports
|
|
24
|
-
- Use CommonJS module system (require/module.exports)
|
|
25
|
-
- Export using module.exports.<func> = <func>
|
|
26
|
-
|
|
27
|
-
### Variables & Functions
|
|
28
|
-
- Use camelCase for variables and functions
|
|
29
|
-
- Use snake_case for some function names (rest_get, get_timezone_data)
|
|
30
|
-
- Function declarations: mix of standard functions and arrow functions
|
|
31
|
-
|
|
32
|
-
### Error Handling
|
|
33
|
-
- Use Promise-based error handling with reject/resolve pattern
|
|
34
|
-
- Include descriptive error objects with properties (message, body, headers)
|
|
35
|
-
- Check input parameters and provide defaults (params = params || {})
|
|
36
|
-
|
|
37
|
-
### Browser Compatibility
|
|
38
|
-
- Check for feature availability before using (typeof window, Intl.DateTimeFormat)
|
|
39
|
-
- Handle both browser and non-browser environments
|
|
40
|
-
|
|
41
|
-
### Documentation
|
|
42
|
-
- Include comments for complex functions
|
|
43
|
-
- Add function descriptions where appropriate
|
|
44
|
-
|
|
45
|
-
### Testing
|
|
46
|
-
- Tests are written using Jest
|
|
47
|
-
- Test modules are in the test/ directory
|
|
48
|
-
- Each module has a separate test file
|
|
49
|
-
- Tests should cover both SSR and client modes
|
|
50
|
-
- Use setup.js for test utilities and mocks
|