@hapico/cli 0.0.10 → 0.0.11

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/bin/index.js CHANGED
@@ -56,8 +56,11 @@ if (!fs.existsSync(CONFIG_DIR)) {
56
56
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
57
57
  }
58
58
  // Function to save token
59
- const saveToken = (token) => {
60
- fs.writeFileSync(TOKEN_FILE, JSON.stringify({ access_token: token }, null, 2), {
59
+ const saveToken = (tokens) => {
60
+ if (!tokens || !tokens.accessToken) {
61
+ throw new Error("Invalid token data");
62
+ }
63
+ fs.writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), {
61
64
  encoding: "utf8",
62
65
  });
63
66
  };
@@ -66,9 +69,15 @@ const getStoredToken = () => {
66
69
  if (fs.existsSync(TOKEN_FILE)) {
67
70
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
68
71
  const json = JSON.parse(data);
69
- return json.access_token || null;
72
+ return json !== null && json !== void 0 ? json : {
73
+ accessToken: null,
74
+ refreshToken: null,
75
+ };
70
76
  }
71
- return null;
77
+ return {
78
+ accessToken: null,
79
+ refreshToken: null,
80
+ };
72
81
  };
73
82
  // Function to save project ID
74
83
  const saveProjectId = (projectDir, id) => {
@@ -289,13 +298,13 @@ class RoomState {
289
298
  return this.isConnected;
290
299
  }
291
300
  }
292
- commander_1.program.version("0.0.9").description("Hapico CLI for project management");
301
+ commander_1.program.version("0.0.10").description("Hapico CLI for project management");
293
302
  commander_1.program
294
303
  .command("clone <id>")
295
304
  .description("Clone a project by ID")
296
305
  .action(async (id) => {
297
- const token = getStoredToken();
298
- if (!token) {
306
+ const { accessToken } = getStoredToken();
307
+ if (!accessToken) {
299
308
  console.error("You need to login first. Use 'hapico login' command.");
300
309
  return;
301
310
  }
@@ -350,8 +359,8 @@ commander_1.program
350
359
  .command("dev")
351
360
  .description("Start the project in development mode")
352
361
  .action(() => {
353
- const token = getStoredToken();
354
- if (!token) {
362
+ const { accessToken } = getStoredToken();
363
+ if (!accessToken) {
355
364
  console.error("You need to login first. Use 'hapico login' command.");
356
365
  return;
357
366
  }
@@ -395,8 +404,9 @@ commander_1.program
395
404
  .command("push")
396
405
  .description("Push the project source code to the server")
397
406
  .action(() => {
398
- const token = getStoredToken();
399
- if (!token) {
407
+ const data = getStoredToken();
408
+ const { accessToken } = data || {};
409
+ if (!accessToken) {
400
410
  console.error("You need to login first. Use 'hapico login' command.");
401
411
  return;
402
412
  }
@@ -422,7 +432,7 @@ commander_1.program
422
432
  }),
423
433
  }, {
424
434
  headers: {
425
- Authorization: `Bearer ${token}`,
435
+ Authorization: `Bearer ${accessToken}`,
426
436
  "Content-Type": "application/json",
427
437
  },
428
438
  })
@@ -437,6 +447,7 @@ commander_1.program
437
447
  .command("login")
438
448
  .description("Login to the system")
439
449
  .action(async () => {
450
+ console.log("Logging in to the system...");
440
451
  const loginSpinner = (0, ora_1.default)("Initiating login...").start();
441
452
  try {
442
453
  const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
package/dist/index.js CHANGED
@@ -56,8 +56,11 @@ if (!fs.existsSync(CONFIG_DIR)) {
56
56
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
57
57
  }
58
58
  // Function to save token
59
- const saveToken = (token) => {
60
- fs.writeFileSync(TOKEN_FILE, JSON.stringify({ access_token: token }, null, 2), {
59
+ const saveToken = (tokens) => {
60
+ if (!tokens || !tokens.accessToken) {
61
+ throw new Error("Invalid token data");
62
+ }
63
+ fs.writeFileSync(TOKEN_FILE, JSON.stringify(tokens, null, 2), {
61
64
  encoding: "utf8",
62
65
  });
63
66
  };
@@ -66,9 +69,15 @@ const getStoredToken = () => {
66
69
  if (fs.existsSync(TOKEN_FILE)) {
67
70
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
68
71
  const json = JSON.parse(data);
69
- return json.access_token || null;
72
+ return json !== null && json !== void 0 ? json : {
73
+ accessToken: null,
74
+ refreshToken: null,
75
+ };
70
76
  }
71
- return null;
77
+ return {
78
+ accessToken: null,
79
+ refreshToken: null,
80
+ };
72
81
  };
73
82
  // Function to save project ID
74
83
  const saveProjectId = (projectDir, id) => {
@@ -289,13 +298,13 @@ class RoomState {
289
298
  return this.isConnected;
290
299
  }
291
300
  }
292
- commander_1.program.version("0.0.9").description("Hapico CLI for project management");
301
+ commander_1.program.version("0.0.10").description("Hapico CLI for project management");
293
302
  commander_1.program
294
303
  .command("clone <id>")
295
304
  .description("Clone a project by ID")
296
305
  .action(async (id) => {
297
- const token = getStoredToken();
298
- if (!token) {
306
+ const { accessToken } = getStoredToken();
307
+ if (!accessToken) {
299
308
  console.error("You need to login first. Use 'hapico login' command.");
300
309
  return;
301
310
  }
@@ -350,8 +359,8 @@ commander_1.program
350
359
  .command("dev")
351
360
  .description("Start the project in development mode")
352
361
  .action(() => {
353
- const token = getStoredToken();
354
- if (!token) {
362
+ const { accessToken } = getStoredToken();
363
+ if (!accessToken) {
355
364
  console.error("You need to login first. Use 'hapico login' command.");
356
365
  return;
357
366
  }
@@ -395,8 +404,9 @@ commander_1.program
395
404
  .command("push")
396
405
  .description("Push the project source code to the server")
397
406
  .action(() => {
398
- const token = getStoredToken();
399
- if (!token) {
407
+ const data = getStoredToken();
408
+ const { accessToken } = data || {};
409
+ if (!accessToken) {
400
410
  console.error("You need to login first. Use 'hapico login' command.");
401
411
  return;
402
412
  }
@@ -422,7 +432,7 @@ commander_1.program
422
432
  }),
423
433
  }, {
424
434
  headers: {
425
- Authorization: `Bearer ${token}`,
435
+ Authorization: `Bearer ${accessToken}`,
426
436
  "Content-Type": "application/json",
427
437
  },
428
438
  })
@@ -437,6 +447,7 @@ commander_1.program
437
447
  .command("login")
438
448
  .description("Login to the system")
439
449
  .action(async () => {
450
+ console.log("Logging in to the system...");
440
451
  const loginSpinner = (0, ora_1.default)("Initiating login...").start();
441
452
  try {
442
453
  const response = await axios_1.default.post("https://auth.myworkbeast.com/auth/device");
package/index.ts CHANGED
@@ -24,10 +24,13 @@ if (!fs.existsSync(CONFIG_DIR)) {
24
24
  }
25
25
 
26
26
  // Function to save token
27
- const saveToken = (token: string) => {
27
+ const saveToken = (tokens: { accessToken: string; refreshToken?: string }) => {
28
+ if (!tokens || !tokens.accessToken) {
29
+ throw new Error("Invalid token data");
30
+ }
28
31
  fs.writeFileSync(
29
32
  TOKEN_FILE,
30
- JSON.stringify({ access_token: token }, null, 2),
33
+ JSON.stringify(tokens, null, 2),
31
34
  {
32
35
  encoding: "utf8",
33
36
  }
@@ -35,13 +38,22 @@ const saveToken = (token: string) => {
35
38
  };
36
39
 
37
40
  // Function to get stored token
38
- const getStoredToken = (): string | null => {
41
+ const getStoredToken = (): {
42
+ accessToken: string | null;
43
+ refreshToken: string | null;
44
+ } => {
39
45
  if (fs.existsSync(TOKEN_FILE)) {
40
46
  const data = fs.readFileSync(TOKEN_FILE, { encoding: "utf8" });
41
47
  const json = JSON.parse(data);
42
- return json.access_token || null;
48
+ return json ?? {
49
+ accessToken: null,
50
+ refreshToken: null,
51
+ };
43
52
  }
44
- return null;
53
+ return {
54
+ accessToken: null,
55
+ refreshToken: null,
56
+ };
45
57
  };
46
58
 
47
59
  // Function to save project ID
@@ -333,14 +345,14 @@ class RoomState {
333
345
  }
334
346
  }
335
347
 
336
- program.version("0.0.9").description("Hapico CLI for project management");
348
+ program.version("0.0.10").description("Hapico CLI for project management");
337
349
 
338
350
  program
339
351
  .command("clone <id>")
340
352
  .description("Clone a project by ID")
341
353
  .action(async (id: string) => {
342
- const token = getStoredToken();
343
- if (!token) {
354
+ const { accessToken } = getStoredToken();
355
+ if (!accessToken) {
344
356
  console.error("You need to login first. Use 'hapico login' command.");
345
357
  return;
346
358
  }
@@ -413,8 +425,8 @@ program
413
425
  .command("dev")
414
426
  .description("Start the project in development mode")
415
427
  .action(() => {
416
- const token = getStoredToken();
417
- if (!token) {
428
+ const { accessToken } = getStoredToken();
429
+ if (!accessToken) {
418
430
  console.error("You need to login first. Use 'hapico login' command.");
419
431
  return;
420
432
  }
@@ -474,8 +486,9 @@ program
474
486
  .command("push")
475
487
  .description("Push the project source code to the server")
476
488
  .action(() => {
477
- const token = getStoredToken();
478
- if (!token) {
489
+ const data = getStoredToken();
490
+ const { accessToken } = data || {};
491
+ if (!accessToken) {
479
492
  console.error("You need to login first. Use 'hapico login' command.");
480
493
  return;
481
494
  }
@@ -508,7 +521,7 @@ program
508
521
  },
509
522
  {
510
523
  headers: {
511
- Authorization: `Bearer ${token}`,
524
+ Authorization: `Bearer ${accessToken}`,
512
525
  "Content-Type": "application/json",
513
526
  },
514
527
  }
@@ -525,6 +538,7 @@ program
525
538
  .command("login")
526
539
  .description("Login to the system")
527
540
  .action(async () => {
541
+ console.log("Logging in to the system...");
528
542
  const loginSpinner: Ora = ora("Initiating login...").start();
529
543
 
530
544
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hapico/cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "A simple CLI tool for project management",
5
5
  "main": "index.js",
6
6
  "bin": {