tsoft-cli 3.6.0 → 3.6.1

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": "tsoft-cli",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "tsoft360 tema geliştirme ve yönetim aracı",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api-client.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import axios from 'axios';
2
- import { loadTokens, ensureValidToken } from './storage.js';
2
+ import { loadTokens, ensureValidToken, refreshAccessToken, saveTokens, isRefreshTokenValid } from './storage.js';
3
+ import { verboseLog } from './output-mode.js';
3
4
 
4
5
  export class ApiClient {
5
6
  constructor(store) {
6
7
  this.store = store;
7
8
  this.baseURL = `https://${store}/api/v3/public/onlinestore`;
9
+ this._retried = false;
8
10
  }
9
11
 
10
12
  async getAuthHeaders() {
@@ -22,6 +24,29 @@ export class ApiClient {
22
24
  };
23
25
  }
24
26
 
27
+ async refreshAndRetry(requestFn) {
28
+ if (this._retried) {
29
+ throw new Error('Yetkilendirme hatası. Lütfen tekrar giriş yapın: tsoft login');
30
+ }
31
+ this._retried = true;
32
+
33
+ const tokens = await loadTokens(this.store);
34
+ verboseLog('refresh token valid:', tokens ? isRefreshTokenValid(tokens) : 'no tokens');
35
+ if (tokens && isRefreshTokenValid(tokens)) {
36
+ try {
37
+ verboseLog('calling refreshAccessToken...');
38
+ const newTokens = await refreshAccessToken(tokens.refreshToken, tokens.store);
39
+ await saveTokens(newTokens, tokens.store);
40
+ verboseLog('refresh success, retrying request...');
41
+ return await requestFn();
42
+ } catch (refreshError) {
43
+ verboseLog('refresh failed:', refreshError.message);
44
+ }
45
+ }
46
+
47
+ throw new Error('Yetkilendirme hatası. Lütfen tekrar giriş yapın: tsoft login');
48
+ }
49
+
25
50
  async get(endpoint, config = {}) {
26
51
  const headers = await this.getAuthHeaders();
27
52
 
@@ -33,6 +58,10 @@ export class ApiClient {
33
58
 
34
59
  return response.data;
35
60
  } catch (error) {
61
+ if (error.response?.status === 401 && !this._retried) {
62
+ verboseLog('401 received, attempting refresh...');
63
+ return await this.refreshAndRetry(() => this.get(endpoint, config));
64
+ }
36
65
  this.handleError(error);
37
66
  }
38
67
  }
@@ -48,6 +77,9 @@ export class ApiClient {
48
77
 
49
78
  return response.data;
50
79
  } catch (error) {
80
+ if (error.response?.status === 401 && !this._retried) {
81
+ return await this.refreshAndRetry(() => this.post(endpoint, data, config));
82
+ }
51
83
  this.handleError(error);
52
84
  }
53
85
  }
@@ -63,6 +95,9 @@ export class ApiClient {
63
95
 
64
96
  return response;
65
97
  } catch (error) {
98
+ if (error.response?.status === 401 && !this._retried) {
99
+ return await this.refreshAndRetry(() => this.download(endpoint, params));
100
+ }
66
101
  this.handleError(error);
67
102
  }
68
103
  }
package/src/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { createRequire } from 'module';
4
4
  import { Command } from 'commander';
5
5
  import chalk from 'chalk';
6
- import { setJsonMode } from './output-mode.js';
6
+ import { setJsonMode, setVerboseMode } from './output-mode.js';
7
7
  import { initLocale } from './i18n.js';
8
8
  import { renderBrandedHelp } from './ui/help-renderer.js';
9
9
  import { loginCommand } from './commands/login.js';
@@ -30,15 +30,19 @@ program
30
30
  .description('tsoft360 theme development and management tool')
31
31
  .version(version);
32
32
 
33
- // Global --json flag for machine-readable output (CI/CD)
33
+ // Global flags
34
34
  program.option('--json', 'Machine-readable JSON output for CI/CD');
35
+ program.option('--verbose', 'Verbose debug output');
35
36
 
36
37
  // preAction hook: runs before every command
37
38
  program.hook('preAction', (thisCommand) => {
38
39
  const opts = thisCommand.opts();
39
40
  if (opts.json) {
40
41
  setJsonMode(true);
41
- chalk.level = 0; // Disable chalk colors — no ANSI codes inside JSON
42
+ chalk.level = 0;
43
+ }
44
+ if (opts.verbose) {
45
+ setVerboseMode(true);
42
46
  }
43
47
  });
44
48
 
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  let _jsonMode = false;
8
+ let _verboseMode = false;
8
9
 
9
10
  /**
10
11
  * JSON modu aktif et (index.js preAction hook'undan cagrilir)
@@ -43,3 +44,17 @@ export function humanOut(fn) {
43
44
  fn();
44
45
  }
45
46
  }
47
+
48
+ export function setVerboseMode(val) {
49
+ _verboseMode = Boolean(val);
50
+ }
51
+
52
+ export function isVerbose() {
53
+ return _verboseMode;
54
+ }
55
+
56
+ export function verboseLog(...args) {
57
+ if (_verboseMode) {
58
+ console.error('[verbose]', ...args);
59
+ }
60
+ }
package/src/storage.js CHANGED
@@ -141,15 +141,11 @@ export async function refreshAccessToken(refreshToken, store) {
141
141
  const refreshUrl = config.getRefreshUrl(store);
142
142
 
143
143
  try {
144
- // Laravel Passport application/x-www-form-urlencoded formatında bekler
145
- const params = new URLSearchParams();
146
- params.append('grant_type', 'refresh_token');
147
- params.append('refresh_token', refreshToken);
148
- params.append('client_id', config.CLIENT_ID);
149
-
150
- const response = await axios.post(refreshUrl, params, {
144
+ const response = await axios.post(refreshUrl, {
145
+ refreshToken: refreshToken,
146
+ }, {
151
147
  headers: {
152
- 'Content-Type': 'application/x-www-form-urlencoded',
148
+ 'Content-Type': 'application/json',
153
149
  'Accept': 'application/json',
154
150
  },
155
151
  });