@luutuankiet/gsd-reader 0.2.19 → 0.2.20

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.
Files changed (2) hide show
  1. package/cli.cjs +28 -32
  2. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -242,39 +242,35 @@ function promptPassword(prompt) {
242
242
  });
243
243
  }
244
244
 
245
- function httpRequest(url, options, data) {
246
- return new Promise((resolve, reject) => {
247
- const protocol = url.protocol === 'https:' ? https : http;
248
-
249
- const req = protocol.request(url, options, (res) => {
250
- let body = '';
251
- res.on('data', (chunk) => body += chunk);
252
- res.on('end', () => {
253
- if (res.statusCode >= 200 && res.statusCode < 300) {
254
- resolve(body.trim() || `HTTP ${res.statusCode}`);
255
- } else if (res.statusCode === 401) {
256
- reject(new Error('Authentication failed (401). Check username/password.'));
257
- } else {
258
- reject(new Error(`HTTP ${res.statusCode}: ${body}`));
259
- }
260
- });
261
- });
262
-
263
- // 30s timeout — prevents hanging on network issues
264
- req.setTimeout(30000, () => {
265
- req.destroy(new Error('Request timed out after 30s. Check server/proxy status.'));
266
- });
267
-
268
- req.on('error', (err) => {
269
- if (err.code === 'ECONNRESET') {
270
- reject(new Error('Connection reset by server. Causes: (1) Reverse proxy body size limit, (2) Server rejected upload, (3) Network interruption. Original: ' + err.message));
271
- } else {
272
- reject(err);
273
- }
245
+ async function httpRequest(url, options, data) {
246
+ const controller = new AbortController();
247
+ const timeout = setTimeout(() => controller.abort(), 30000);
248
+
249
+ try {
250
+ const res = await fetch(url, {
251
+ method: options.method || 'POST',
252
+ headers: options.headers,
253
+ body: data,
254
+ signal: controller.signal,
274
255
  });
275
- req.write(data);
276
- req.end();
277
- });
256
+
257
+ const body = await res.text();
258
+
259
+ if (res.ok) {
260
+ return body.trim() || `HTTP ${res.status}`;
261
+ } else if (res.status === 401) {
262
+ throw new Error('Authentication failed (401). Check username/password.');
263
+ } else {
264
+ throw new Error(`HTTP ${res.status}: ${body}`);
265
+ }
266
+ } catch (err) {
267
+ if (err.name === 'AbortError') {
268
+ throw new Error('Request timed out after 30s. Check server/proxy status.');
269
+ }
270
+ throw err;
271
+ } finally {
272
+ clearTimeout(timeout);
273
+ }
278
274
  }
279
275
 
280
276
  // =============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luutuankiet/gsd-reader",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "Interactive Worklog Reader for GSD-Lite WORK.md files with live reload",
5
5
  "keywords": [
6
6
  "gsd-lite",