@trainheroic-unofficial/cli 4.1.0 → 4.2.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/dist/cli.mjs +27 -2
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -1063,6 +1063,28 @@ var TrainHeroicHttpError = class extends Error {
|
|
|
1063
1063
|
this.responseBody = diagnostics.responseBody === void 0 ? void 0 : safeResponseBodyDiagnostics(diagnostics.responseBody);
|
|
1064
1064
|
}
|
|
1065
1065
|
};
|
|
1066
|
+
/**
|
|
1067
|
+
* True for statuses that mean TrainHeroic's servers could not be reached or did not answer: a
|
|
1068
|
+
* gateway failure (502, 503, 504) or a Cloudflare edge error (520-530). TrainHeroic sits behind
|
|
1069
|
+
* Cloudflare, so a 522 means the edge timed out connecting to TrainHeroic's origin. These describe
|
|
1070
|
+
* an upstream outage, so the same request can succeed when retried later.
|
|
1071
|
+
*/
|
|
1072
|
+
function isTrainHeroicUnavailableStatus(status) {
|
|
1073
|
+
return status === 502 || status === 503 || status === 504 || status >= 520 && status <= 530;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Thrown when TrainHeroic answers with an outage status (see `isTrainHeroicUnavailableStatus`).
|
|
1077
|
+
* The message tells the reader to retry later, so a model relaying it does not ask the user to
|
|
1078
|
+
* re-check credentials that are fine.
|
|
1079
|
+
*/
|
|
1080
|
+
var TrainHeroicUnavailableError = class extends Error {
|
|
1081
|
+
name = "TrainHeroicUnavailableError";
|
|
1082
|
+
status;
|
|
1083
|
+
constructor(status) {
|
|
1084
|
+
super(`TrainHeroic is not responding right now (HTTP ${status}). Try again in a few minutes.`);
|
|
1085
|
+
this.status = status;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1066
1088
|
/** Call observability hooks without allowing them to change SDK behavior. */
|
|
1067
1089
|
function notifyHttpError(handler, method, url, status, diagnostics = {}) {
|
|
1068
1090
|
if (!handler) return;
|
|
@@ -1090,8 +1112,10 @@ function authUrl() {
|
|
|
1090
1112
|
return DEFAULT_AUTH_URL;
|
|
1091
1113
|
}
|
|
1092
1114
|
/**
|
|
1093
|
-
* Authenticate against TrainHeroic. Returns the session bundle, or null
|
|
1094
|
-
*
|
|
1115
|
+
* Authenticate against TrainHeroic. Returns the session bundle, or null when TrainHeroic
|
|
1116
|
+
* rejects the login. Throws `TrainHeroicUnavailableError` when TrainHeroic is unreachable (an
|
|
1117
|
+
* outage status such as a Cloudflare 522), so callers can tell the user to retry later.
|
|
1118
|
+
* TrainHeroic returns only { id, scope, role, session_id } (verified in
|
|
1095
1119
|
* the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
|
|
1096
1120
|
* is sent as the `session-token` header and works against both API hosts.
|
|
1097
1121
|
*/
|
|
@@ -1111,6 +1135,7 @@ async function loginTrainHeroic(email, password, options = {}) {
|
|
|
1111
1135
|
if (!res.ok) {
|
|
1112
1136
|
await res.body?.cancel().catch(() => {});
|
|
1113
1137
|
notifyHttpError(options.onHttpError, "POST", url, res.status);
|
|
1138
|
+
if (isTrainHeroicUnavailableStatus(res.status)) throw new TrainHeroicUnavailableError(res.status);
|
|
1114
1139
|
return null;
|
|
1115
1140
|
}
|
|
1116
1141
|
const data = await res.json().catch(() => null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"zod": "^4.6.5",
|
|
24
|
-
"@trainheroic-unofficial/dto": "4.
|
|
25
|
-
"@trainheroic-unofficial/js": "4.
|
|
24
|
+
"@trainheroic-unofficial/dto": "4.2.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "4.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.6.4",
|