myskillshub 1.0.7 → 1.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myskillshub",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "CLI tool for SkillHub skill management",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -268,9 +268,38 @@ async function getAuthCookie(apiUrl, options, spinner) {
268
268
  }
269
269
  }
270
270
 
271
- const credentials = await resolveCredentials(options, spinner);
272
- const cookie = await loginAndGetCookie(normalizedApiUrl, credentials.username, credentials.password);
271
+ let usedStoredCredentials = false;
272
+ let credentials = hasCompleteExplicitCredentials
273
+ ? { username: resolvedUsername, password: resolvedPassword }
274
+ : null;
275
+
276
+ if (!credentials) {
277
+ const storedCredentials = getCachedCredentials(normalizedApiUrl);
278
+ if (storedCredentials) {
279
+ credentials = storedCredentials;
280
+ usedStoredCredentials = true;
281
+ }
282
+ }
283
+
284
+ if (!credentials) {
285
+ credentials = await resolveCredentials(options, spinner);
286
+ }
287
+
288
+ let cookie;
289
+ try {
290
+ cookie = await loginAndGetCookie(normalizedApiUrl, credentials.username, credentials.password);
291
+ } catch (error) {
292
+ if (usedStoredCredentials) {
293
+ // Stored credentials may be stale, fallback to interactive prompt once.
294
+ credentials = await resolveCredentials(options, spinner);
295
+ cookie = await loginAndGetCookie(normalizedApiUrl, credentials.username, credentials.password);
296
+ } else {
297
+ throw error;
298
+ }
299
+ }
300
+
273
301
  saveCachedCookie(normalizedApiUrl, cookie);
302
+ saveCachedCredentials(normalizedApiUrl, credentials.username, credentials.password);
274
303
  return { cookie, fromCache: false };
275
304
  }
276
305
 
@@ -312,20 +341,43 @@ function getCachedCookie(apiUrl) {
312
341
  return store.sessions?.[apiUrl]?.cookie || null;
313
342
  }
314
343
 
315
- function saveCachedCookie(apiUrl, cookie) {
344
+ function getCachedCredentials(apiUrl) {
345
+ const store = readSessionStore();
346
+ const username = store.sessions?.[apiUrl]?.username || '';
347
+ const password = store.sessions?.[apiUrl]?.password || '';
348
+ if (!username || !password) {
349
+ return null;
350
+ }
351
+ return { username, password };
352
+ }
353
+
354
+ function saveSessionData(apiUrl, patch) {
316
355
  const store = readSessionStore();
317
356
  store.sessions = store.sessions || {};
318
357
  store.sessions[apiUrl] = {
319
- cookie,
320
- updatedAt: new Date().toISOString()
358
+ ...(store.sessions[apiUrl] || {}),
359
+ ...patch,
360
+ updatedAt: new Date().toISOString(),
321
361
  };
322
362
  writeSessionStore(store);
323
363
  }
324
364
 
365
+ function saveCachedCookie(apiUrl, cookie) {
366
+ saveSessionData(apiUrl, { cookie });
367
+ }
368
+
369
+ function saveCachedCredentials(apiUrl, username, password) {
370
+ saveSessionData(apiUrl, { username, password });
371
+ }
372
+
325
373
  function removeCachedCookie(apiUrl) {
326
374
  const store = readSessionStore();
327
375
  if (store.sessions && store.sessions[apiUrl]) {
328
- delete store.sessions[apiUrl];
376
+ delete store.sessions[apiUrl].cookie;
377
+ store.sessions[apiUrl].updatedAt = new Date().toISOString();
378
+ if (!store.sessions[apiUrl].username || !store.sessions[apiUrl].password) {
379
+ delete store.sessions[apiUrl];
380
+ }
329
381
  writeSessionStore(store);
330
382
  }
331
383
  }
@@ -404,7 +456,7 @@ function promptPassword(question) {
404
456
  terminal: true
405
457
  });
406
458
 
407
- rl.stdoutMuted = true;
459
+ rl.stdoutMuted = false;
408
460
  const originalWriteToOutput = rl._writeToOutput;
409
461
  rl._writeToOutput = function writeToOutput(stringToWrite) {
410
462
  if (rl.stdoutMuted) {
@@ -423,6 +475,7 @@ function promptPassword(question) {
423
475
  rl.close();
424
476
  resolve(String(password || '').trim());
425
477
  });
478
+ rl.stdoutMuted = true;
426
479
  });
427
480
  }
428
481
 
@@ -443,7 +496,7 @@ async function loginAndGetCookie(apiUrl, username, password) {
443
496
  function createZipPackage(directory) {
444
497
  return new Promise((resolve, reject) => {
445
498
  const baseName = path.basename(path.resolve(directory));
446
- const zipPath = path.join(process.cwd(), `${baseName}-package-${Date.now()}.zip`);
499
+ const zipPath = path.join(os.tmpdir(), `${baseName}-package-${Date.now()}.zip`);
447
500
  const output = createWriteStream(zipPath);
448
501
  const archive = archiver('zip', {
449
502
  zlib: { level: 9 }
@@ -469,7 +522,10 @@ function createZipPackage(directory) {
469
522
  ignore: [
470
523
  '**/node_modules/**',
471
524
  '**/.git/**',
472
- '**/.DS_Store'
525
+ '**/.DS_Store',
526
+ '**/*-package-*.zip',
527
+ '**/*-package.zip',
528
+ '**/.-package.zip'
473
529
  ]
474
530
  });
475
531