@trainheroic-unofficial/cli 2.1.0 → 2.1.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/dist/cli.mjs +43 -6
- package/package.json +5 -5
package/dist/cli.mjs
CHANGED
|
@@ -375,6 +375,34 @@ function parseWorkoutDate(s) {
|
|
|
375
375
|
];
|
|
376
376
|
}
|
|
377
377
|
//#endregion
|
|
378
|
+
//#region ../js/src/http-error.ts
|
|
379
|
+
/**
|
|
380
|
+
* A final non-2xx response from TrainHeroic. The error deliberately carries only request
|
|
381
|
+
* metadata that is safe to send to telemetry: never the path, query string, request body,
|
|
382
|
+
* response body, credentials, or session token.
|
|
383
|
+
*/
|
|
384
|
+
var TrainHeroicHttpError = class extends Error {
|
|
385
|
+
name = "TrainHeroicHttpError";
|
|
386
|
+
method;
|
|
387
|
+
status;
|
|
388
|
+
host;
|
|
389
|
+
constructor(method, url, status) {
|
|
390
|
+
const parsed = new URL(url);
|
|
391
|
+
const normalizedMethod = method.toUpperCase();
|
|
392
|
+
super(`TrainHeroic ${normalizedMethod} request failed with HTTP ${status}`);
|
|
393
|
+
this.method = normalizedMethod;
|
|
394
|
+
this.status = status;
|
|
395
|
+
this.host = parsed.host;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
/** Call observability hooks without allowing them to change SDK behavior. */
|
|
399
|
+
function notifyHttpError(handler, method, url, status) {
|
|
400
|
+
if (!handler) return;
|
|
401
|
+
try {
|
|
402
|
+
Promise.resolve(handler(new TrainHeroicHttpError(method, url, status))).catch(() => {});
|
|
403
|
+
} catch {}
|
|
404
|
+
}
|
|
405
|
+
//#endregion
|
|
378
406
|
//#region ../js/src/auth.ts
|
|
379
407
|
const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
|
|
380
408
|
/**
|
|
@@ -396,8 +424,9 @@ function authUrl() {
|
|
|
396
424
|
* the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
|
|
397
425
|
* is sent as the `session-token` header and works against both API hosts.
|
|
398
426
|
*/
|
|
399
|
-
async function loginTrainHeroic(email, password) {
|
|
400
|
-
const
|
|
427
|
+
async function loginTrainHeroic(email, password, options = {}) {
|
|
428
|
+
const url = authUrl();
|
|
429
|
+
const res = await fetch(url, {
|
|
401
430
|
method: "POST",
|
|
402
431
|
headers: {
|
|
403
432
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -408,7 +437,10 @@ async function loginTrainHeroic(email, password) {
|
|
|
408
437
|
password
|
|
409
438
|
}).toString()
|
|
410
439
|
});
|
|
411
|
-
if (!res.ok)
|
|
440
|
+
if (!res.ok) {
|
|
441
|
+
notifyHttpError(options.onHttpError, "POST", url, res.status);
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
412
444
|
const data = await res.json().catch(() => null);
|
|
413
445
|
if (!data || typeof data.id !== "number" || !data.session_id) return null;
|
|
414
446
|
return {
|
|
@@ -451,6 +483,7 @@ var TrainHeroicClient = class {
|
|
|
451
483
|
#email;
|
|
452
484
|
#password;
|
|
453
485
|
#onSession;
|
|
486
|
+
#onHttpError;
|
|
454
487
|
#sessionId;
|
|
455
488
|
#loginInFlight = null;
|
|
456
489
|
constructor(email, password, sessionId = null, options = {}) {
|
|
@@ -458,6 +491,7 @@ var TrainHeroicClient = class {
|
|
|
458
491
|
this.#password = password;
|
|
459
492
|
this.#sessionId = sessionId;
|
|
460
493
|
this.#onSession = options.onSession;
|
|
494
|
+
this.#onHttpError = options.onHttpError;
|
|
461
495
|
}
|
|
462
496
|
get sessionId() {
|
|
463
497
|
return this.#sessionId;
|
|
@@ -472,7 +506,7 @@ var TrainHeroicClient = class {
|
|
|
472
506
|
}
|
|
473
507
|
}
|
|
474
508
|
async #login() {
|
|
475
|
-
const session = await loginTrainHeroic(this.#email, this.#password);
|
|
509
|
+
const session = await loginTrainHeroic(this.#email, this.#password, this.#onHttpError ? { onHttpError: this.#onHttpError } : {});
|
|
476
510
|
if (!session) throw new TrainHeroicAuthError("TrainHeroic login failed");
|
|
477
511
|
this.#sessionId = session.sessionId;
|
|
478
512
|
try {
|
|
@@ -489,6 +523,7 @@ var TrainHeroicClient = class {
|
|
|
489
523
|
session = await this.#ensureSession();
|
|
490
524
|
res = await this.#send(method, url, session, options.body);
|
|
491
525
|
}
|
|
526
|
+
if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
|
|
492
527
|
const text = await res.text();
|
|
493
528
|
let data = text;
|
|
494
529
|
if (text.length > 0) try {
|
|
@@ -2364,8 +2399,10 @@ function unitAdvisory(blockTitle, ex, defaults) {
|
|
|
2364
2399
|
if (ex.weight !== void 0 && ex.weight !== null) {
|
|
2365
2400
|
const sentP2 = Math.trunc(Number(ex.param_2_type ?? 1));
|
|
2366
2401
|
const effP2 = defaults.param2 === 0 || defaults.param2 === null ? 1 : defaults.param2;
|
|
2367
|
-
if (sentP2 !== effP2)
|
|
2368
|
-
|
|
2402
|
+
if (sentP2 !== effP2) {
|
|
2403
|
+
if (sentP2 === 2 || sentP2 === 14) warnings.push(`${label}: ${u(sentP2)} does not stick on this exercise — it renders as ${u(effP2)}. Put it in the exercise 'instr' text and leave load blank.`);
|
|
2404
|
+
else warnings.push(`${label}: load renders as ${u(effP2)}, not ${u(sentP2)} (this exercise's secondary unit is fixed).`);
|
|
2405
|
+
}
|
|
2369
2406
|
}
|
|
2370
2407
|
return {
|
|
2371
2408
|
notes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/dto": "2.1.
|
|
25
|
-
"@trainheroic-unofficial/js": "2.1.
|
|
24
|
+
"@trainheroic-unofficial/dto": "2.1.1",
|
|
25
|
+
"@trainheroic-unofficial/js": "2.1.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^26.
|
|
28
|
+
"@types/node": "^26.2.0",
|
|
29
29
|
"tsdown": "^0.22.14",
|
|
30
|
-
"tsx": "^4.23.
|
|
30
|
+
"tsx": "^4.23.11",
|
|
31
31
|
"typescript": "^7.0.2",
|
|
32
32
|
"vitest": "^4.1.10"
|
|
33
33
|
},
|