promptlike 0.6.1 → 0.6.2
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 +17 -0
- package/README.md +3 -1
- package/dist/lib/api-client.js +100 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.2 — 2026-10-12
|
|
4
|
+
|
|
5
|
+
- **Fix:** a network problem while your session is being refreshed (no DNS,
|
|
6
|
+
connection refused, a dropped Wi-Fi) no longer says "Session expired. Log in
|
|
7
|
+
again". It now says the server could not be reached: check your connection
|
|
8
|
+
and run the command again. Your saved login is kept. A temporary server
|
|
9
|
+
problem during the refresh (busy, rate limited, 5xx) asks you to run the
|
|
10
|
+
command again in a moment and keeps your login; only if it keeps happening
|
|
11
|
+
does it suggest `ple login`. Only a definite rejection from the server (the
|
|
12
|
+
refresh token expired, was revoked or was already used) still asks you to log
|
|
13
|
+
in again right away. Nothing is retried automatically.
|
|
14
|
+
- **Fix:** when the session refresh itself gets no answer within 30 s, the
|
|
15
|
+
message no longer says "the server may still have completed the request;
|
|
16
|
+
check before retrying" (that warning is for your own writes and was
|
|
17
|
+
misleading on read commands). It now says the refresh did not finish and to
|
|
18
|
+
run the command again; if it then reports an expired session, run `ple login`.
|
|
19
|
+
|
|
3
20
|
## 0.6.1 — 2026-10-12
|
|
4
21
|
|
|
5
22
|
- **Fix:** `ple <name>` commands (show, copy, get, log, ...) now find a prompt by its
|
package/README.md
CHANGED
|
@@ -581,7 +581,9 @@ out of the published tarball — only `dist/`, `LICENSE`, and `README.md` ship.
|
|
|
581
581
|
| Symptom | Cause | Fix |
|
|
582
582
|
|---|---|---|
|
|
583
583
|
| `Not logged in. Run ple login first.` | No session on disk | `ple login` |
|
|
584
|
-
| `Session expired. Log in again: ple login` |
|
|
584
|
+
| `Session expired. Log in again: ple login` | The server rejected the refresh token (expired, revoked or already used) | `ple login` again |
|
|
585
|
+
| `Cannot reach <url>. Could not refresh your session…` | Network problem while refreshing the session | Check your connection and run the command again; your saved login is kept |
|
|
586
|
+
| `Could not refresh your session right now (…)` | The server could not refresh the session for a moment (busy, rate limited) | Run the command again in a moment; your saved login is kept. If it keeps happening, run `ple login` |
|
|
585
587
|
| `Invalid email or password. If you signed up with Google…` | OAuth-only account has no password | Set a password in Account settings on the web, then `ple login` |
|
|
586
588
|
| `Clipboard command (xclip) not found` | Linux without xclip / wl-copy | `apt install xclip` (X11) or `apt install wl-clipboard` (Wayland) |
|
|
587
589
|
| `No prompt matched 'X'.` | Name doesn't match anything | Run `ple list` to see real titles |
|
package/dist/lib/api-client.js
CHANGED
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
* - map 429 / error bodies to clean, user-facing Error messages
|
|
15
15
|
* - bound every request with a timeout (O5 / PLE-03): a server that keeps the
|
|
16
16
|
* connection open without answering must not hang a command forever
|
|
17
|
+
* - only a definitive refresh rejection means "session expired" (O11): a
|
|
18
|
+
* network error or a temporary server failure keeps the saved login
|
|
17
19
|
*/
|
|
18
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.USE_SURFACES = exports.RequestTimeoutError = exports.USE_EVENT_TIMEOUT_MS = exports.IMPORT_TIMEOUT_MS = exports.WRITE_TIMEOUT_MS = exports.READ_TIMEOUT_MS = void 0;
|
|
21
|
+
exports.USE_SURFACES = exports.NetworkError = exports.ApiError = exports.DEFINITIVE_REFRESH_CODES = exports.REFRESH_UNAVAILABLE_LAST_RESORT = exports.REFRESH_NETWORK_ADVICE = exports.REFRESH_TIMEOUT_ADVICE = exports.RequestTimeoutError = exports.USE_EVENT_TIMEOUT_MS = exports.IMPORT_TIMEOUT_MS = exports.WRITE_TIMEOUT_MS = exports.READ_TIMEOUT_MS = void 0;
|
|
22
|
+
exports.refreshUnavailableMessage = refreshUnavailableMessage;
|
|
20
23
|
exports.login = login;
|
|
21
24
|
exports.ensureAuthed = ensureAuthed;
|
|
22
25
|
exports.listPrompts = listPrompts;
|
|
@@ -50,15 +53,91 @@ exports.IMPORT_TIMEOUT_MS = 120000;
|
|
|
50
53
|
exports.USE_EVENT_TIMEOUT_MS = 5000;
|
|
51
54
|
/** Zaman aşımı hatası — `refreshSession` bunu "oturum bitti"ye çevirmesin diye ayrı sınıf. */
|
|
52
55
|
class RequestTimeoutError extends Error {
|
|
53
|
-
constructor(timeoutMs, method) {
|
|
54
|
-
const
|
|
56
|
+
constructor(timeoutMs, method, advice) {
|
|
57
|
+
const defaultAdvice = method === 'GET'
|
|
55
58
|
? 'Check your connection and try again.'
|
|
56
59
|
: 'The server may still have completed the request; check before retrying.';
|
|
57
|
-
super(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ${advice}`);
|
|
60
|
+
super(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ${advice ?? defaultAdvice}`);
|
|
61
|
+
this.timeoutMs = timeoutMs;
|
|
58
62
|
this.name = 'RequestTimeoutError';
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
exports.RequestTimeoutError = RequestTimeoutError;
|
|
66
|
+
/**
|
|
67
|
+
* Oturum yenileme zaman aşımına uğradığında kullanıcıya söylenecek şey. Yenileme
|
|
68
|
+
* kullanıcının komutu değil, arka plandaki bir POST'tur; "yazma sunucuda
|
|
69
|
+
* tamamlanmış olabilir, önce kontrol et" uyarısı okuma komutunda bile çıkıp
|
|
70
|
+
* yanıltırdı. Sunucu yenilemeyi tamamlamış ama yeni token yerelde saklanmamış
|
|
71
|
+
* olabilir; bu durumda bir sonraki çalıştırma "Session expired" der.
|
|
72
|
+
*/
|
|
73
|
+
exports.REFRESH_TIMEOUT_ADVICE = 'Session refresh did not finish. Run the command again; if it then says the session expired, run `ple login`.';
|
|
74
|
+
/**
|
|
75
|
+
* Yenileme isteği sunucuya hiç ulaşamadığında (DNS, bağlantı reddi, kopma; O11).
|
|
76
|
+
* Ağ hatası oturumun bittiğini göstermez: yerel oturum silinmez (yalnız `ple
|
|
77
|
+
* logout` siler), kullanıcı gereksiz yere `ple login`'e yönlendirilmez.
|
|
78
|
+
*/
|
|
79
|
+
exports.REFRESH_NETWORK_ADVICE = 'Could not refresh your session: check your connection and run the command again. Your saved login is kept.';
|
|
80
|
+
/**
|
|
81
|
+
* Sunucu yenilemeyi kesin reddetmedi ama tamamlayamadı (503 + Retry-After, 429,
|
|
82
|
+
* 5xx, tanınmayan yanıt; O11). Web `/api/auth/cli/refresh` sözleşmesi: bunlar
|
|
83
|
+
* geçicidir, oturum korunur, sonra yeniden denenir. Otomatik tekrar YOK.
|
|
84
|
+
* Son çare cümlesi: web tanınmayan üst servis hatasını (kodsuz 401/403, yeni bir
|
|
85
|
+
* GoTrue kodu) da 503 geçici sayar; refresh token gerçekten iptal edilmişse
|
|
86
|
+
* kullanıcı "az sonra tekrar dene"de takılı kalmasın.
|
|
87
|
+
*/
|
|
88
|
+
exports.REFRESH_UNAVAILABLE_LAST_RESORT = 'If this keeps happening, run `ple login`.';
|
|
89
|
+
function refreshUnavailableMessage(detail) {
|
|
90
|
+
return `Could not refresh your session right now (${detail}). Run the command again in a moment; your saved login is kept. ${exports.REFRESH_UNAVAILABLE_LAST_RESORT}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sunucunun yenilemeyi KESİN reddettiğini gösteren yanıt kodları (O11). Web
|
|
94
|
+
* `src/app/api/auth/cli/refresh/_handlers/classify.ts` DEFINITIVE_CODES (GoTrue
|
|
95
|
+
* `error_code`) ile aynı liste + rotanın kendi `SESSION_EXPIRED` kodu; tutarlılık
|
|
96
|
+
* `api-client.refresh.test.ts` ile kilitli. Yalnız bunlar (ya da 401 / 400)
|
|
97
|
+
* "Session expired" sayılır; tanınmayan her şey geçicidir (emin değilsen oturumu bitirme).
|
|
98
|
+
*/
|
|
99
|
+
exports.DEFINITIVE_REFRESH_CODES = new Set([
|
|
100
|
+
'SESSION_EXPIRED',
|
|
101
|
+
'refresh_token_not_found',
|
|
102
|
+
'refresh_token_already_used',
|
|
103
|
+
'session_expired',
|
|
104
|
+
'session_not_found',
|
|
105
|
+
'invalid_grant',
|
|
106
|
+
'user_not_found',
|
|
107
|
+
'user_banned',
|
|
108
|
+
'validation_failed',
|
|
109
|
+
]);
|
|
110
|
+
/** HTTP hatası; durum kodu ve sunucu kodu korunur (yenileme sınıflaması için). İleti değişmedi. */
|
|
111
|
+
class ApiError extends Error {
|
|
112
|
+
constructor(message, status, code) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.status = status;
|
|
115
|
+
this.code = code;
|
|
116
|
+
this.name = 'ApiError';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ApiError = ApiError;
|
|
120
|
+
/** İstek sunucuya ulaşamadı (DNS, bağlantı reddi, kopma). Varsayılan ileti eskisiyle aynı. */
|
|
121
|
+
class NetworkError extends Error {
|
|
122
|
+
constructor(detail, advice = 'Check your connection.') {
|
|
123
|
+
super(`Cannot reach ${constants_1.API_BASE_URL}. ${advice} (${detail})`);
|
|
124
|
+
this.detail = detail;
|
|
125
|
+
this.name = 'NetworkError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.NetworkError = NetworkError;
|
|
129
|
+
/**
|
|
130
|
+
* Yenileme yanıtı oturumun gerçekten bittiğini mi söylüyor? Web sözleşmesi:
|
|
131
|
+
* 401 SESSION_EXPIRED (kesin ret) ve 400 (refresh_token eksik: yerel oturum
|
|
132
|
+
* kaydı bozuk) kesindir; 503 / 429 / 5xx / ağ / zaman aşımı geçicidir.
|
|
133
|
+
*/
|
|
134
|
+
function isDefinitiveRefreshRejection(err) {
|
|
135
|
+
if (!(err instanceof ApiError))
|
|
136
|
+
return false;
|
|
137
|
+
if (err.status === 401 || err.status === 400)
|
|
138
|
+
return true;
|
|
139
|
+
return err.code !== undefined && exports.DEFINITIVE_REFRESH_CODES.has(err.code);
|
|
140
|
+
}
|
|
62
141
|
/**
|
|
63
142
|
* Hata süre aşımından mı geldi? Önce sinyalin kendisine bakılır: eski Node /
|
|
64
143
|
* undici sürümlerinde gövde okuması yarıda kesilince hata `TimeoutError` yerine
|
|
@@ -113,12 +192,13 @@ async function toError(res) {
|
|
|
113
192
|
catch {
|
|
114
193
|
// Non-JSON error body — fall back to a generic message below.
|
|
115
194
|
}
|
|
195
|
+
const code = typeof body.code === 'string' ? body.code : undefined;
|
|
116
196
|
if (body.error)
|
|
117
|
-
return new
|
|
118
|
-
if (
|
|
119
|
-
return new
|
|
197
|
+
return new ApiError(body.error, res.status, code);
|
|
198
|
+
if (code && ERROR_FALLBACKS[code]) {
|
|
199
|
+
return new ApiError(ERROR_FALLBACKS[code], res.status, code);
|
|
120
200
|
}
|
|
121
|
-
return new
|
|
201
|
+
return new ApiError(`Request failed (${res.status}).`, res.status, code);
|
|
122
202
|
}
|
|
123
203
|
function getAccessTokenOrThrow() {
|
|
124
204
|
const config = (0, config_1.readConfig)();
|
|
@@ -154,9 +234,17 @@ async function refreshSession() {
|
|
|
154
234
|
}
|
|
155
235
|
catch (err) {
|
|
156
236
|
// Asılı sunucu "oturumun bitti, yeniden giriş yap" demek değildir.
|
|
157
|
-
if (err instanceof RequestTimeoutError)
|
|
158
|
-
throw err;
|
|
159
|
-
|
|
237
|
+
if (err instanceof RequestTimeoutError) {
|
|
238
|
+
throw new RequestTimeoutError(err.timeoutMs, 'POST', exports.REFRESH_TIMEOUT_ADVICE);
|
|
239
|
+
}
|
|
240
|
+
// Yalnız sunucunun kesin reddi oturumu bitirir (O11).
|
|
241
|
+
if (isDefinitiveRefreshRejection(err))
|
|
242
|
+
throw new Error(SESSION_EXPIRED);
|
|
243
|
+
// Ağ hatası (DNS, bağlantı reddi): sunucuya ulaşılamadı, oturum hakkında bilgi yok.
|
|
244
|
+
if (err instanceof NetworkError)
|
|
245
|
+
throw new NetworkError(err.detail, exports.REFRESH_NETWORK_ADVICE);
|
|
246
|
+
// 503 / 429 / 5xx / tanınmayan yanıt: geçici; yerel oturum korunur.
|
|
247
|
+
throw new Error(refreshUnavailableMessage(err instanceof Error ? err.message : String(err)));
|
|
160
248
|
}
|
|
161
249
|
persist(data);
|
|
162
250
|
}
|
|
@@ -187,7 +275,7 @@ async function apiFetch(path, opts = {}) {
|
|
|
187
275
|
catch (err) {
|
|
188
276
|
if (isTimeout(err, signal))
|
|
189
277
|
throw new RequestTimeoutError(timeoutMs, method);
|
|
190
|
-
throw new
|
|
278
|
+
throw new NetworkError(err instanceof Error ? err.message : String(err));
|
|
191
279
|
}
|
|
192
280
|
// Reactive refresh: expired/invalid access token → refresh once, retry once.
|
|
193
281
|
if (res.status === 401 && auth) {
|
package/package.json
CHANGED