tsoft-cli 3.6.0 → 3.7.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/api-client.js +36 -1
- package/src/commands/theme-dev.js +40 -0
- package/src/index.js +7 -3
- package/src/output-mode.js +15 -0
- package/src/storage.js +4 -8
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to T-Soft CLI will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.7.0] - 2026-04-15
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Live preview link in `tsoft theme dev` — press **P** to open the dev theme in your browser
|
|
12
|
+
- HMAC-signed preview URL with cookie-based session (default 24h) so navigation across pages keeps the dev theme rendered
|
|
13
|
+
- `?_preview_clear=1` to exit preview mode
|
|
14
|
+
|
|
8
15
|
## [3.5.1] - 2026-04-09
|
|
9
16
|
|
|
10
17
|
### Fixed
|
package/package.json
CHANGED
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
|
}
|
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import AdmZip from 'adm-zip';
|
|
6
6
|
import chokidar from 'chokidar';
|
|
7
7
|
import {createApiClient} from '../api-client.js';
|
|
8
|
+
import open from 'open';
|
|
8
9
|
import {normalizeStoreDomain, slugify, setActiveTheme, getActiveTheme, getActiveStore} from '../storage.js';
|
|
9
10
|
import {brandedConfirm, brandedSelect, showWarning, showError, showInfo} from '../ui/prompt-wrapper.js';
|
|
10
11
|
import { t } from '../i18n.js';
|
|
@@ -169,6 +170,45 @@ async function startFileWatcher(themeUuid, themePath) {
|
|
|
169
170
|
console.log(chalk.gray(t('dev.env_running')));
|
|
170
171
|
console.log(chalk.gray(' ' + t('dev.exit_tip') + '\n'));
|
|
171
172
|
|
|
173
|
+
// Preview URL — backend HMAC token uretip dev temayi onizleme link'i veriyor
|
|
174
|
+
let previewUrl = null;
|
|
175
|
+
try {
|
|
176
|
+
const apiClient = await createApiClient();
|
|
177
|
+
const previewRes = await apiClient.get(`/theme/${themeUuid}/preview-url`);
|
|
178
|
+
previewUrl = previewRes?.data?.preview_url || null;
|
|
179
|
+
if (previewUrl) {
|
|
180
|
+
const expIso = previewRes?.data?.expires_at;
|
|
181
|
+
console.log(chalk.bgGreen.black(' [P] Preview ') + ' ' + chalk.white(previewUrl));
|
|
182
|
+
console.log(chalk.gray(' ' + chalk.dim('basın: ') + chalk.bold('P') + chalk.dim(' tarayıcıda aç')) + (expIso ? chalk.gray(` ${chalk.dim('exp:')} ${expIso}`) : '') + '\n');
|
|
183
|
+
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.log(chalk.gray(' (preview link alinamadi: ' + (err?.message || 'unknown') + ')\n'));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Klavye dinleyici — 'P' tarayıcıda preview URL'ini acar, Ctrl+C cikis
|
|
189
|
+
if (previewUrl && process.stdin.isTTY) {
|
|
190
|
+
try {
|
|
191
|
+
process.stdin.setRawMode(true);
|
|
192
|
+
process.stdin.resume();
|
|
193
|
+
process.stdin.setEncoding('utf8');
|
|
194
|
+
process.stdin.on('data', async (key) => {
|
|
195
|
+
if (key === '\u0003') { // Ctrl+C
|
|
196
|
+
process.exit(0);
|
|
197
|
+
}
|
|
198
|
+
if (key === 'p' || key === 'P') {
|
|
199
|
+
console.log(chalk.cyan(' tarayıcıda açılıyor: ') + chalk.white(previewUrl));
|
|
200
|
+
try {
|
|
201
|
+
await open(previewUrl);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.log(chalk.red(' tarayıcı acilamadi: ' + e.message));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// raw mode bazi terminallerde calismaz — sessizce gec
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
172
212
|
const watcher = chokidar.watch(themePath, {
|
|
173
213
|
ignored: /(^|[\/\\])\../, persistent: true, ignoreInitial: true, awaitWriteFinish: {
|
|
174
214
|
stabilityThreshold: 300, pollInterval: 100
|
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
|
|
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;
|
|
42
|
+
chalk.level = 0;
|
|
43
|
+
}
|
|
44
|
+
if (opts.verbose) {
|
|
45
|
+
setVerboseMode(true);
|
|
42
46
|
}
|
|
43
47
|
});
|
|
44
48
|
|
package/src/output-mode.js
CHANGED
|
@@ -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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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/
|
|
148
|
+
'Content-Type': 'application/json',
|
|
153
149
|
'Accept': 'application/json',
|
|
154
150
|
},
|
|
155
151
|
});
|