uniweb 1.34.2 → 1.34.4

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": "uniweb",
3
- "version": "1.34.2",
3
+ "version": "1.34.4",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,15 +41,15 @@
41
41
  "js-yaml": "^4.3.2",
42
42
  "prompts": "^2.4.2",
43
43
  "tar": "^7.5.21",
44
+ "@uniweb/schemas": "~1.7.4",
44
45
  "@uniweb/content-writer": "~1.3.2",
45
46
  "@uniweb/core": "~1.6.12",
46
- "@uniweb/schemas": "~1.7.3",
47
47
  "@uniweb/semantic-parser": "~1.13.4"
48
48
  },
49
49
  "peerDependencies": {
50
- "@uniweb/build": "~1.23.2",
50
+ "@uniweb/content-reader": "~1.5.10",
51
51
  "@uniweb/semantic-parser": "~1.13.4",
52
- "@uniweb/content-reader": "~1.5.10"
52
+ "@uniweb/build": "~1.23.3"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@uniweb/build": {
@@ -45,7 +45,7 @@ site/
45
45
  | `form` | a form an author designs | a list of controls |
46
46
  | `scene` | a Scene Composition Format document | flat |
47
47
 
48
- Each type's fields, with what each is for: https://github.com/uniweb/schemas/tree/main/src/standard. A record holds only its type's fields: `uniweb validate` reports one the type lacks and a push refuses it, while a build notes it and still delivers it. What a site says differently (a topic) goes in a field the type has (`tags`), or the type is not the one.
48
+ Each type's fields, with what each is for: https://github.com/uniweb/schemas/tree/main/src/standard. A record holds only its type's fields: `uniweb validate` reports one the type lacks, a push refuses it, and a build notes it and leaves it out, so a component receives the same record on a static host and a hosted site. What a site says differently (a topic) goes in a field the type has (`tags`), or the type is not the one.
49
49
 
50
50
  Keep directories flat — `records/article/2025/x.md` reads as the `2025` schema of an `article` org. A `_`-prefixed file is not a record.
51
51
 
@@ -29,6 +29,7 @@ import {
29
29
  } from '../utils/sync-point.js'
30
30
  import { sentRoots } from '../utils/site-roots.js'
31
31
  import { humanBytes } from '../utils/bytes.js'
32
+ import { anotherClientsSessionLines } from '../utils/registry-auth.js'
32
33
  import {
33
34
  describeRequestError,
34
35
  describeWorkspace,
@@ -2446,8 +2447,10 @@ export async function pushSyncPackages({
2446
2447
  const body = await res.text().catch(() => '')
2447
2448
  // Two unrelated conflicts share HTTP 409, so branch on the machine-readable
2448
2449
  // `reason` — never on `detail`, which is prose the backend may reword.
2450
+ // A 401 is read too, for a session made for another of the backend's clients (below).
2451
+ // ⛔ Until 2026-11-11 it was not, so that refusal could never be told from any other 401.
2449
2452
  let problem = null
2450
- if ((res.status === 409 || res.status === 400 || res.status === 403 || res.status === 413 || res.status === 422 || res.status === 507) && body) {
2453
+ if ((res.status === 409 || res.status === 400 || res.status === 401 || res.status === 403 || res.status === 413 || res.status === 422 || res.status === 507) && body) {
2451
2454
  try {
2452
2455
  problem = JSON.parse(body)
2453
2456
  } catch {
@@ -2633,8 +2636,16 @@ export async function pushSyncPackages({
2633
2636
  return null
2634
2637
  }
2635
2638
  error(`${label} push rejected: HTTP ${res.status} ${res.statusText}`)
2636
- // A typed 403 says its own cause (a plan's limit, say), which is not the credentials.
2637
- if ((res.status === 401 || res.status === 403) && typeof problem?.reason !== 'string') {
2639
+ // A session made for another of the backend's clients says so, and names a sign-in. Any
2640
+ // other 401 is the credentials, as before; a typed 403 says its own cause (a plan's limit,
2641
+ // say), which is not the credentials.
2642
+ const anotherClient = await anotherClientsSessionLines(problem, {
2643
+ origin: client.origin,
2644
+ fromEnv: Boolean(process.env.UNIWEB_TOKEN)
2645
+ })
2646
+ if (anotherClient) {
2647
+ for (const line of anotherClient) note(line)
2648
+ } else if (res.status === 401 || (res.status === 403 && typeof problem?.reason !== 'string')) {
2638
2649
  note(
2639
2650
  "Credentials weren't accepted — log in again (`uniweb login --server <url>`), or check UNIWEB_TOKEN."
2640
2651
  )
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-11T23:15:48.024Z",
3
+ "generatedAt": "2026-11-12T00:25:23.192Z",
4
4
  "packages": {
5
5
  "@uniweb/api": {
6
6
  "version": "1.7.0"
7
7
  },
8
8
  "@uniweb/build": {
9
- "version": "1.23.2"
9
+ "version": "1.23.3"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.10"
@@ -24,7 +24,7 @@
24
24
  "version": "1.0.9"
25
25
  },
26
26
  "@uniweb/kit": {
27
- "version": "1.7.20"
27
+ "version": "1.7.21"
28
28
  },
29
29
  "@uniweb/loom": {
30
30
  "version": "1.1.3"
@@ -42,10 +42,10 @@
42
42
  "version": "1.0.1"
43
43
  },
44
44
  "@uniweb/schemas": {
45
- "version": "1.7.3"
45
+ "version": "1.7.4"
46
46
  },
47
47
  "@uniweb/scholar": {
48
- "version": "1.1.2"
48
+ "version": "1.1.3"
49
49
  },
50
50
  "@uniweb/semantic-parser": {
51
51
  "version": "1.13.4"
package/src/index.js CHANGED
@@ -2036,7 +2036,8 @@ Authenticates with a backend and stores its session in
2036
2036
  logs you out of the first (once the new login succeeds). The backend you are
2037
2037
  logged in to is where the backend commands go (push, pull, publish, status,
2038
2038
  register, clone) — so this is how you switch. Already logged in to it, login
2039
- does nothing; add --password, --browser, --token-paste or --token to log in again.
2039
+ does nothing, unless that backend no longer accepts the session: then it signs in
2040
+ again. Add --password, --browser, --token-paste or --token to log in again anyway.
2040
2041
 
2041
2042
  Without --server: https://uniweb.app (or \$UNIWEB_SERVER). No command talks
2042
2043
  to a backend you are not logged in to — run one before logging in and it asks first.
@@ -356,12 +356,50 @@ export async function fetchMe({ apiBase, token }) {
356
356
  `token check failed: HTTP ${res.status} ${res.statusText}`
357
357
  )
358
358
  e.status = res.status
359
+ // The refusal's body, so a caller can say why: a session made for another of the
360
+ // backend's clients (`anotherClientsSessionLines`) is not a wrong or expired token.
361
+ e.problem = await res.json().catch(() => null)
359
362
  throw e
360
363
  }
361
364
  const data = await res.json().catch(() => null)
362
365
  return data?.account || null
363
366
  }
364
367
 
368
+ /** The reason a backend gives when a session was made for another of its clients. */
369
+ export const SESSION_FOR_ANOTHER_CLIENT = 'session_for_another_client'
370
+
371
+ /**
372
+ * What to say when a backend refuses a session because it was made for another of its
373
+ * clients. Its problem body says `reason: "session_for_another_client"`, and `client` names
374
+ * whose session the route takes: here a session made for the Uniweb app, sent to a route that
375
+ * takes only the CLI's (`client: "cli"`). Null for any other refusal, so a caller keeps its
376
+ * own message.
377
+ *
378
+ * ⭐ IT NAMES THE FIX: a session the CLI signs in for itself, on the backend that refused
379
+ * (`loginCommand`). ⛔ Until 2026-11-11 the token checks said only "HTTP 401", and a push gave
380
+ * only its general "log in again" advice, since it never read a 401's body.
381
+ *
382
+ * @param {object|null|undefined} problem - the refusal's parsed body
383
+ * @param {{ origin: string, fromEnv?: boolean }} o - the backend that refused, and whether the
384
+ * session came from UNIWEB_TOKEN
385
+ * @returns {Promise<string[]|null>}
386
+ */
387
+ export async function anotherClientsSessionLines(problem, { origin, fromEnv = false } = {}) {
388
+ if (problem?.reason !== SESSION_FOR_ANOTHER_CLIENT || problem?.client !== 'cli') return null
389
+ const { loginCommand } = await import('./config.js')
390
+ const { getCliPrefix } = await import('./interactive.js')
391
+ const login = loginCommand(origin, getCliPrefix())
392
+ return fromEnv
393
+ ? [
394
+ `UNIWEB_TOKEN holds a session made for the Uniweb app, and ${origin} takes only a session the uniweb CLI signed in with.`,
395
+ `Set UNIWEB_TOKEN to a CLI session, or unset it and sign in: ${login} --browser (or --password).`
396
+ ]
397
+ : [
398
+ `This session was made for the Uniweb app, and ${origin} takes only a session the uniweb CLI signed in with.`,
399
+ `Sign in from the CLI: ${login} --browser (or --password).`
400
+ ]
401
+ }
402
+
365
403
  // Username/password — prompts unless UNIWEB_USERNAME/PASSWORD are set.
366
404
  async function loginViaPassword({ apiBase, nonInteractive }) {
367
405
  let username = process.env.UNIWEB_USERNAME
@@ -423,7 +461,15 @@ async function loginViaTokenPaste({ apiBase, nonInteractive }) {
423
461
  }
424
462
  )
425
463
  if (!token) process.exit(1)
426
- const account = await fetchMe({ apiBase, token }) // throws if the token is invalid
464
+ let account
465
+ try {
466
+ account = await fetchMe({ apiBase, token })
467
+ } catch (err) {
468
+ // Said as the `--token` check says it (`anotherClientsSessionLines`); any other refusal as before.
469
+ const lines = await anotherClientsSessionLines(err.problem, { origin: normOrigin(apiBase) })
470
+ if (lines) throw new Error(lines.join('\n '))
471
+ throw err
472
+ }
427
473
  const record = { token, origin: normOrigin(apiBase) }
428
474
  if (account?.uuid) record.uuid = account.uuid
429
475
  if (account?.username) record.username = account.username
@@ -730,7 +776,22 @@ export async function runRegistryLogin({ apiBase, args = [] } = {}) {
730
776
  )
731
777
  }
732
778
 
733
- if (existing?.token && !isExpired(existing)) {
779
+ // ⭐ A STORED SESSION THE BACKEND REFUSES IS NOT A LOGIN. A login that names no way of signing
780
+ // in keeps the session it finds, so it asks the backend first (`/dev/auth/me`) and signs in
781
+ // again on a 401: a session revoked, or one made for the Uniweb app, which a backend refuses on
782
+ // the CLI's routes since 2026-11-11. ⛔ Until then such a session got "Already logged in" here,
783
+ // while every command answered 401 and named this command as the fix. Any other answer (no
784
+ // network, a 5xx) keeps the session, as before: it says nothing about the session.
785
+ let refused = null
786
+ if (existing?.token && !isExpired(existing) && !forced) {
787
+ try {
788
+ await fetchMe({ apiBase, token: existing.token })
789
+ } catch (err) {
790
+ if (err.status === 401) refused = err
791
+ }
792
+ }
793
+
794
+ if (existing?.token && !isExpired(existing) && !refused) {
734
795
  const who =
735
796
  existing.username ||
736
797
  existing.handle ||
@@ -776,6 +837,13 @@ export async function runRegistryLogin({ apiBase, args = [] } = {}) {
776
837
  console.error(
777
838
  `Already logged in${who ? ` as \x1b[1m${who}\x1b[0m` : ''} (${key}) — logging in again replaces that session.\n`
778
839
  )
840
+ } else if (refused) {
841
+ const why = await anotherClientsSessionLines(refused.problem, { origin: key })
842
+ console.error(
843
+ `\x1b[33m!\x1b[0m ${key} refuses the session stored for it${why ? '' : ` (HTTP ${refused.status})`} — signing in again.`
844
+ )
845
+ if (why) console.error(`\x1b[2m ${why[0]}\x1b[0m`)
846
+ console.error('')
779
847
  } else if (current && current !== key) {
780
848
  // ⭐ ONE SESSION AT A TIME *[Diego, 2026-09-21]*: logging in here logs you out of there
781
849
  // — when this login succeeds (writeRegistryAuth replaces the file), so cancelling or
@@ -794,9 +862,13 @@ export async function runRegistryLogin({ apiBase, args = [] } = {}) {
794
862
  try {
795
863
  account = await fetchMe({ apiBase, token: tokenFlag })
796
864
  } catch (err) {
797
- console.error(
798
- `\x1b[31m✗\x1b[0m Token rejected by ${apiBase}: ${err.message}`
799
- )
865
+ const lines = await anotherClientsSessionLines(err.problem, { origin: normOrigin(apiBase) })
866
+ if (lines) {
867
+ console.error(`\x1b[31m✗\x1b[0m ${normOrigin(apiBase)} refuses this token.`)
868
+ for (const line of lines) console.error(` ${line}`)
869
+ } else {
870
+ console.error(`\x1b[31m✗\x1b[0m Token rejected by ${apiBase}: ${err.message}`)
871
+ }
800
872
  process.exit(1)
801
873
  }
802
874
  const record = { token: tokenFlag, origin: normOrigin(apiBase) }
@@ -949,6 +1021,9 @@ async function reportTokenProcess({ named, token }) {
949
1021
  ? `\x1b[31m✗\x1b[0m ${origin} refuses UNIWEB_TOKEN (HTTP ${err.status}).`
950
1022
  : `\x1b[31m✗\x1b[0m Could not check UNIWEB_TOKEN with ${origin}: ${err.message}`
951
1023
  )
1024
+ for (const line of (await anotherClientsSessionLines(err.problem, { origin, fromEnv: true })) || []) {
1025
+ console.error(` ${line}`)
1026
+ }
952
1027
  process.exit(1)
953
1028
  }
954
1029
  const who = account?.username || account?.handle || (account?.uuid ? `account ${account.uuid}` : null)