gingee-cli 1.0.2 → 1.0.3

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.
@@ -43,6 +43,26 @@ async function getAuthenticatedClient(serverUrl = 'http://localhost:7070') {
43
43
  return { client, serverUrl };
44
44
  }
45
45
 
46
+ async function ensureAuthenticated(serverUrl) {
47
+ const { default: ora } = await import('ora');
48
+ const spinner = ora('Verifying session...').start();
49
+ try {
50
+ const { client } = await getAuthenticatedClient(serverUrl);
51
+ // Use a simple, lightweight endpoint for the check.
52
+ await client.get(`${serverUrl}/glade/api/apps`);
53
+ spinner.succeed('Session verified.');
54
+ } catch (err) {
55
+ spinner.fail('Session verification failed.');
56
+ if (err.response && err.response.status === 401) {
57
+ throw new Error(`Authentication failed. Your session may have expired. Please run 'gingee-cli login --serverUrl ${serverUrl}' again.`);
58
+ }else if(err.message.includes('You are not logged in')) {
59
+ throw err; // Propagate the not logged in error as is.
60
+ }
61
+ // For other errors (e.g., network, server down), provide a generic message.
62
+ throw new Error(`Could not connect to the server at ${serverUrl}. Please ensure it is running and accessible.`);
63
+ }
64
+ }
65
+
46
66
  function deleteSession(serverUrl) {
47
67
  const credsPath = getCredsFilePath(serverUrl);
48
68
  if (fs.existsSync(credsPath)) {
@@ -125,6 +145,7 @@ async function getAppPermissions(serverUrl, appName) {
125
145
  module.exports = {
126
146
  getCredsFilePath,
127
147
  getAuthenticatedClient,
148
+ ensureAuthenticated,
128
149
  deleteSession,
129
150
  installApp,
130
151
  upgradeApp,
@@ -10,6 +10,8 @@ async function deleteApp(options) {
10
10
  const spinner = ora();
11
11
 
12
12
  try {
13
+ await apiClient.ensureAuthenticated(serverUrl);
14
+
13
15
  let confirmation = false;
14
16
  if (presetFilePath) {
15
17
  // --- NON-INTERACTIVE MODE ---
@@ -22,6 +22,8 @@ async function installApp(options) {
22
22
  const { serverUrl = 'http://localhost:7070', appName, ginPath: ginFilePath, file: presetFilePath } = options;
23
23
  let finalPermissions, finalDbConfig;
24
24
 
25
+ await apiClient.ensureAuthenticated(serverUrl);
26
+
25
27
  if (!fs.existsSync(ginFilePath)) {
26
28
  throw new Error(`Package file not found at: ${ginFilePath}`);
27
29
  }
@@ -22,6 +22,8 @@ async function installStoreApp(appName, options) {
22
22
  const { gStoreUrl, serverUrl } = options;
23
23
 
24
24
  try {
25
+ await apiClient.ensureAuthenticated(serverUrl);
26
+
25
27
  // Step 1: Resolve the manifest URL using the new utility
26
28
  const resolvedStoreUrl = _resolveStoreUrl(gStoreUrl);
27
29
  spinner.start(`Fetching manifest from ${resolvedStoreUrl}...`);
@@ -1,13 +1,18 @@
1
- const { getAuthenticatedClient } = require('./apiClient');
1
+ const apiClient = require('./apiClient');
2
2
 
3
3
  async function listApps(options) {
4
4
  const { default: chalk } = await import('chalk');
5
5
  const { default: ora } = await import('ora');
6
- const spinner = ora('Fetching application list...').start();
6
+ const spinner = ora();
7
7
 
8
8
  try {
9
9
  const { serverUrl = 'http://localhost:7070' } = options;
10
- const { client } = await getAuthenticatedClient(serverUrl);
10
+
11
+ await apiClient.ensureAuthenticated(serverUrl);
12
+
13
+ spinner.start('Fetching installed applications...');
14
+
15
+ const { client } = await apiClient.getAuthenticatedClient(serverUrl);
11
16
  const response = await client.get(`${serverUrl}/glade/api/apps`);
12
17
 
13
18
  if (response.data.status !== 'success' || !response.data.apps) {
@@ -1,12 +1,16 @@
1
1
  const apiClient = require('./apiClient');
2
+ const { _getHttpClientErrorMessage } = require('./installerUtils');
2
3
 
3
4
  async function listBackups(options) {
4
5
  const { default: chalk } = await import('chalk');
5
6
  const { default: ora } = await import('ora');
6
7
  const { serverUrl, appName } = options;
7
- const spinner = ora(`Fetching backups for '${appName}'...`).start();
8
+ const spinner = ora();
8
9
 
9
10
  try {
11
+ await apiClient.ensureAuthenticated(serverUrl);
12
+
13
+ spinner.start(`Fetching backups for '${appName}'...`);
10
14
  const result = await apiClient.listBackups(serverUrl, appName);
11
15
 
12
16
  if (result.status !== 'success' || !result.backups) {
@@ -1,14 +1,18 @@
1
1
  const apiClient = require('./apiClient');
2
2
  const fs = require('fs-extra');
3
3
  const path = require('path');
4
+ const { _getHttpClientErrorMessage } = require('./installerUtils');
4
5
 
5
6
  async function packageApp(options) {
6
7
  const { default: chalk } = await import('chalk');
7
8
  const { default: ora } = await import('ora');
8
9
  const { serverUrl, appName, dest: destFolder } = options;
9
- const spinner = ora(`Requesting package for '${appName}' from server...`).start();
10
+ const spinner = ora();
10
11
 
11
12
  try {
13
+ await apiClient.ensureAuthenticated(serverUrl);
14
+
15
+ spinner.start(`Requesting package for '${appName}' from server...`);
12
16
  // This returns a readable stream of the file being downloaded.
13
17
  const response = await apiClient.packageApp(serverUrl, appName);
14
18
  const fileStream = response.data;
@@ -10,6 +10,8 @@ async function rollbackApp(options) {
10
10
  const spinner = ora();
11
11
 
12
12
  try {
13
+ await apiClient.ensureAuthenticated(serverUrl);
14
+
13
15
  if (presetFilePath) {
14
16
  // --- NON-INTERACTIVE MODE ---
15
17
  console.log(chalk.blueBright(`Running in non-interactive mode using preset file: ${presetFilePath}`));
@@ -15,6 +15,8 @@ async function upgradeApp(options) {
15
15
 
16
16
  try {
17
17
 
18
+ await apiClient.ensureAuthenticated(serverUrl);
19
+
18
20
  if (!fs.existsSync(ginFilePath)) {
19
21
  throw new Error(`Package file not found at: ${ginFilePath}`);
20
22
  }
@@ -21,12 +21,14 @@ async function upgradeStoreApp(appName, options) {
21
21
  const { gStoreUrl, serverUrl } = options;
22
22
 
23
23
  try {
24
+ await apiClient.ensureAuthenticated(serverUrl);
25
+
24
26
  // 1. Resolve URL and fetch the store manifest
25
27
  const resolvedStoreUrl = _resolveStoreUrl(gStoreUrl);
26
28
  spinner.start(`Fetching manifest from ${resolvedStoreUrl}...`);
27
29
 
28
30
  const manifestResponse = await axios.get(resolvedStoreUrl);
29
- const appConfig = manifestResponse.data.apps.find(a => a.name === appName);
31
+ const appConfig = manifestResponse.data.apps.find(a => a.installName === appName);
30
32
  if (!appConfig) {
31
33
  throw new Error(`App '${appName}' not found in the store manifest.`);
32
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gingee-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "The Gingee Command Line Interface (CLI), official command line tool for creating and managing Gingee projects.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -41,7 +41,7 @@
41
41
  "commander": "^14.0.0",
42
42
  "form-data": "^4.0.4",
43
43
  "fs-extra": "^11.3.1",
44
- "gingee": "^1.0.1",
44
+ "gingee": "^1.0.2",
45
45
  "inquirer": "^12.9.2",
46
46
  "ora": "^8.2.0",
47
47
  "yauzl": "^3.2.0"