@karpeleslab/klbfw 0.2.8 → 0.2.10

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/README.md CHANGED
@@ -22,7 +22,7 @@ npm install @karpeleslab/klbfw
22
22
  For Node.js environments with file upload support, install optional dependencies:
23
23
 
24
24
  ```bash
25
- npm install @karpeleslab/klbfw node-fetch xmldom
25
+ npm install @karpeleslab/klbfw node-fetch @xmldom/xmldom
26
26
  ```
27
27
 
28
28
  ## Development
@@ -72,30 +72,35 @@ The upload module provides cross-platform file upload capabilities, supporting b
72
72
 
73
73
  ```javascript
74
74
  // Open file picker and upload selected files
75
- upload.upload.init('Misc/Debug:testUpload')()
75
+ upload.init('Misc/Debug:testUpload')()
76
76
  .then(result => console.log('Upload complete', result));
77
77
 
78
+ // Open file picker with custom parameters and notification callback
79
+ upload.init('Support/Ticket:upload', {image_variation: 'alias=mini&strip&scale_crop=300x200'}, (result) => {
80
+ if (result.status == 'complete') console.log(result.final);
81
+ });
82
+
78
83
  // Upload a specific File object
79
- upload.upload.append('Misc/Debug:testUpload', fileObject)
84
+ upload.append('Misc/Debug:testUpload', fileObject)
80
85
  .then(result => console.log('Upload complete', result));
81
86
 
82
87
  // Track progress
83
- upload.upload.onprogress = (status) => {
88
+ upload.onprogress = (status) => {
84
89
  console.log('Progress:', status.running.map(i => i.status));
85
90
  };
86
91
 
87
92
  // Cancel an upload
88
- upload.upload.cancelItem(uploadId);
93
+ upload.cancelItem(uploadId);
89
94
  ```
90
95
 
91
96
  #### Node.js Usage
92
97
 
93
98
  ```javascript
94
99
  // For Node.js environments, first install dependencies:
95
- // npm install node-fetch xmldom
100
+ // npm install node-fetch @xmldom/xmldom
96
101
 
97
102
  // Initialize upload with specific file paths
98
- upload.upload.init('Misc/Debug:testUpload')(['./file1.txt', './file2.jpg'])
103
+ upload.init('Misc/Debug:testUpload')(['./file1.txt', './file2.jpg'])
99
104
  .then(result => console.log('Upload complete', result));
100
105
 
101
106
  // Or create a custom file object with path
@@ -105,7 +110,7 @@ const file = {
105
110
  type: 'text/plain',
106
111
  path: '/path/to/file.txt'
107
112
  };
108
- upload.upload.append('Misc/Debug:testUpload', file)
113
+ upload.append('Misc/Debug:testUpload', file)
109
114
  .then(result => console.log('Upload complete', result));
110
115
  ```
111
116
 
@@ -255,5 +260,5 @@ Several utilities have been designed to work across environments:
255
260
  To use klbfw with full functionality in Node.js, install the optional dependencies:
256
261
 
257
262
  ```bash
258
- npm install node-fetch xmldom
263
+ npm install node-fetch @xmldom/xmldom
259
264
  ```
package/internal.js CHANGED
@@ -201,6 +201,30 @@ const internalRest = (name, verb, params, context) => {
201
201
  const responseParse = (response, resolve, reject) => {
202
202
  // Check if response is ok (status 200-299)
203
203
  if (!response.ok) {
204
+ // Check if the error response is JSON
205
+ const contentType = response.headers.get("content-type");
206
+ if (contentType && contentType.indexOf("application/json") !== -1) {
207
+ // Parse JSON error response
208
+ response.json()
209
+ .then(json => {
210
+ // Add headers and status to the parsed JSON
211
+ json.headers = response.headers;
212
+ json.status = response.status;
213
+ reject(json);
214
+ })
215
+ .catch(error => {
216
+ // If JSON parsing fails, reject with basic error info
217
+ reject({
218
+ message: `HTTP Error: ${response.status} ${response.statusText}`,
219
+ status: response.status,
220
+ headers: response.headers,
221
+ parseError: error
222
+ });
223
+ });
224
+ return;
225
+ }
226
+
227
+ // Non-JSON error response
204
228
  reject({
205
229
  message: `HTTP Error: ${response.status} ${response.statusText}`,
206
230
  status: response.status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karpeleslab/klbfw",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Frontend Framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -31,13 +31,13 @@
31
31
  },
32
32
  "optionalDependencies": {
33
33
  "node-fetch": "^2.7.0",
34
- "xmldom": "^0.6.0"
34
+ "@xmldom/xmldom": "~0.8.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "jest": "^29.7.0",
38
38
  "jest-environment-jsdom": "^29.7.0",
39
39
  "node-fetch": "^2.7.0",
40
- "xmldom": "^0.6.0"
40
+ "@xmldom/xmldom": "~0.8.4"
41
41
  },
42
42
  "jest": {
43
43
  "testEnvironment": "jsdom",
package/upload.js CHANGED
@@ -14,26 +14,31 @@
14
14
  * Browser usage:
15
15
  * ```js
16
16
  * // Open file picker and upload selected files
17
- * upload.upload.init('Misc/Debug:testUpload')()
17
+ * upload.init('Misc/Debug:testUpload')()
18
18
  * .then(result => console.log('Upload complete', result));
19
+ *
20
+ * // Open file picker with custom parameters and notification callback
21
+ * upload.init('Support/Ticket:upload', {image_variation: 'alias=mini&strip&scale_crop=300x200'}, (result) => {
22
+ * if (result.status == 'complete') console.log(result.final);
23
+ * });
19
24
  *
20
25
  * // Upload a specific File object
21
- * upload.upload.append('Misc/Debug:testUpload', fileObject)
26
+ * upload.append('Misc/Debug:testUpload', fileObject)
22
27
  * .then(result => console.log('Upload complete', result));
23
28
  *
24
29
  * // Track progress
25
- * upload.upload.onprogress = (status) => {
30
+ * upload.onprogress = (status) => {
26
31
  * console.log('Progress:', status.running.map(i => i.status));
27
32
  * };
28
33
  *
29
34
  * // Cancel an upload
30
- * upload.upload.cancelItem(uploadId);
35
+ * upload.cancelItem(uploadId);
31
36
  * ```
32
37
  *
33
38
  * Node.js usage:
34
39
  * ```js
35
40
  * // For Node.js environments, first install dependencies:
36
- * // npm install node-fetch xmldom
41
+ * // npm install node-fetch @xmldom/xmldom
37
42
  *
38
43
  * // Create a buffer-based file object for upload
39
44
  * const file = {
@@ -49,7 +54,7 @@
49
54
  * }
50
55
  * };
51
56
  *
52
- * upload.upload.append('Misc/Debug:testUpload', file)
57
+ * upload.append('Misc/Debug:testUpload', file)
53
58
  * .then(result => console.log('Upload complete', result));
54
59
  * ```
55
60
  *
@@ -93,12 +98,12 @@ const env = {
93
98
  if (env.isNode && !env.isBrowser) {
94
99
  try {
95
100
  env.node.fetch = require('node-fetch');
96
- env.node.xmlParser = require('xmldom');
101
+ env.node.xmlParser = require('@xmldom/xmldom');
97
102
  env.node.EventEmitter = require('events');
98
103
  env.node.eventEmitter = new (env.node.EventEmitter)();
99
104
  } catch (e) {
100
105
  console.warn('Node.js dependencies not available. Some functionality may be limited:', e.message);
101
- console.warn('To use in Node.js, install: npm install node-fetch xmldom');
106
+ console.warn('To use in Node.js, install: npm install node-fetch @xmldom/xmldom');
102
107
  }
103
108
  }
104
109
 
@@ -689,7 +694,7 @@ module.exports.upload = (function () {
689
694
  up.done = completedParts;
690
695
 
691
696
  // Check if all parts are complete
692
- if (pendingParts === 0) {
697
+ if (pendingParts === 0 && completedParts === up.blocks) {
693
698
  // All parts complete, finalize the upload
694
699
  up.status = "validating";
695
700