uniweb 1.35.6 → 1.35.7

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.35.6",
3
+ "version": "1.35.7",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,14 +41,14 @@
41
41
  "js-yaml": "^4.3.2",
42
42
  "prompts": "^2.4.2",
43
43
  "tar": "^7.5.21",
44
- "@uniweb/schemas": "~1.7.5",
45
44
  "@uniweb/core": "~1.6.13",
46
45
  "@uniweb/semantic-parser": "~1.13.6",
46
+ "@uniweb/schemas": "~1.7.5",
47
47
  "@uniweb/content-writer": "~1.3.3"
48
48
  },
49
49
  "peerDependencies": {
50
- "@uniweb/content-reader": "~1.5.12",
51
50
  "@uniweb/semantic-parser": "~1.13.6",
51
+ "@uniweb/content-reader": "~1.5.12",
52
52
  "@uniweb/build": "~1.24.4"
53
53
  },
54
54
  "peerDependenciesMeta": {
@@ -121,6 +121,8 @@ integrations: # by a mapping the foundation declares in src/mappi
121
121
 
122
122
  A site with a backend is a solution: public pages, a members' area for each role, and an **admin area** for the people who run it — its staff, its instructors. You build the admin area: section types of your foundation, branded, in the solution's own words, with what follows. The **admin app** is the backend's own administration, the same for every site: the payment account, the teams and who is in them, roles, an integration's address and keys, the store's offerings and coupons. Never rebuild those; link to it (`adminHref`, below). The docs' Building a Solution page walks the whole path.
123
123
 
124
+ From a terminal, once the site is published and its backend is running, `uniweb site admin` opens the admin app in the browser, signed in as the site's owner, and `uniweb site visit` opens the site signed in the same way. Only the owner can use them. The address they open signs the person in, so they never print it: where no browser can open, they say so and stop, and the person runs the command where one can.
125
+
124
126
  ## Selling
125
127
 
126
128
  ```jsx
@@ -919,6 +919,22 @@ export class BackendClient {
919
919
  })
920
920
  }
921
921
 
922
+ /**
923
+ * POST /dev/site/manage/{uuid} and POST /dev/site/visit/{uuid} — a one-time sign-in of the
924
+ * site's OWNER: `manage` into the administration of the site's backend, `visit` on the site
925
+ * itself. Answers `{ url }`, a single-use credential that is valid for a short time: open it,
926
+ * never show or log it. `404` to anyone but the owner. `409` until the site's backend is
927
+ * running, and for `visit` while the site has no address.
928
+ *
929
+ * @param {string} uuid - the site-content uuid
930
+ * @param {'manage'|'visit'} door
931
+ * @returns {Promise<Response>}
932
+ */
933
+ async ownerSignIn(uuid, door) {
934
+ if (door !== 'manage' && door !== 'visit') throw new Error(`ownerSignIn: no door "${door}"`)
935
+ return this.request(`/dev/site/${door}/${encodeURIComponent(uuid)}`, { method: 'POST' })
936
+ }
937
+
922
938
  /**
923
939
  * GET /dev/site — one page of the sites in the workspace the client names
924
940
  * (`setWorkspace`; none ⇒ personal): `{ sites: [{ uuid, name?, updated_at,
@@ -574,6 +574,38 @@ export function resultNotes(results, { kind, network = null }) {
574
574
  return notes
575
575
  }
576
576
 
577
+ // ── Times ──────────────────────────────────────────────────────────────────────────
578
+
579
+ /** A time as the CLI takes one: a day and a time of day, its seconds written or not, and its offset. */
580
+ const TIME = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(Z|([+-])(\d{2}):?(\d{2}))$/
581
+
582
+ /**
583
+ * A time as the backend takes one, an RFC 3339 date-time: the seconds written out and the offset
584
+ * with its colon, the instant and the offset as given (`2026-11-24T09:00-05:00` →
585
+ * `2026-11-24T09:00:00-05:00`). Anything else comes back as it was.
586
+ *
587
+ * ⛔ The backend refuses a time without its seconds, the form the guide and every message of the
588
+ * CLI write, with `400 invalid_field … is not a valid datetime` on a post's write and
589
+ * `send_at_invalid` on its schedule (measured against a backend, 2026-11-21). So a time is written
590
+ * in this form wherever it goes to the backend, and never as the text the file holds.
591
+ */
592
+ export function wireTime(value) {
593
+ const m = typeof value === 'string' ? TIME.exec(value) : null
594
+ if (!m) return value
595
+ const [, day, hh, mm, ss = '00', fraction = '', zone, sign, oh, om] = m
596
+ return `${day}T${hh}:${mm}:${ss}${fraction}${zone === 'Z' ? 'Z' : `${sign}${oh}:${om}`}`
597
+ }
598
+
599
+ /** Whether a value is a time with its offset, as `wireTime` writes one for the backend. */
600
+ export function isTime(value) {
601
+ return typeof value === 'string' && TIME.test(value) && !Number.isNaN(Date.parse(wireTime(value)))
602
+ }
603
+
604
+ /** Two times the same instant, however each is written. */
605
+ export function sameInstant(a, b) {
606
+ return isTime(a) && isTime(b) && Date.parse(wireTime(a)) === Date.parse(wireTime(b))
607
+ }
608
+
577
609
  /** Whether a picture is an address already, kept as written, rather than a file to upload. */
578
610
  export function isAddress(picture) {
579
611
  return /^https?:\/\//i.test(picture)
@@ -60,6 +60,7 @@ import {
60
60
  idMatches,
61
61
  indexPromotion,
62
62
  isAddress,
63
+ isTime,
63
64
  kindOf,
64
65
  NETWORK_NAMES,
65
66
  overLimits,
@@ -75,6 +76,7 @@ import {
75
76
  postMarkdown,
76
77
  postShape,
77
78
  resolvePage,
79
+ sameInstant,
78
80
  shapeYaml,
79
81
  shortIds,
80
82
  sitePages,
@@ -83,7 +85,8 @@ import {
83
85
  versionOf,
84
86
  viaResolver,
85
87
  wentOut,
86
- whyNot
88
+ whyNot,
89
+ wireTime
87
90
  } from '../backend/promote-drafts.js'
88
91
  import { checkFlags } from '../utils/flag-guard.js'
89
92
  import { confirm, isNonInteractive } from '../utils/interactive.js'
@@ -1052,13 +1055,6 @@ function pick(index, arg, kinds) {
1052
1055
  return null
1053
1056
  }
1054
1057
 
1055
- /** Whether `--at`'s value is a time with its offset, as the backend takes one. */
1056
- function isTime(value) {
1057
- return typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})$/.test(value) && !Number.isNaN(Date.parse(value))
1058
- }
1059
-
1060
- const sameInstant = (a, b) => typeof a === 'string' && typeof b === 'string' && Date.parse(a) === Date.parse(b)
1061
-
1062
1058
  /** An amount as money reads: `10.00` for the `10` YAML reads `10.00` as; a string as written. */
1063
1059
  const money = (v) => (typeof v === 'number' && Number.isFinite(v) ? v.toFixed(2) : String(v))
1064
1060
 
@@ -1122,6 +1118,16 @@ function translateDraft(draft, { index, pages, connections }) {
1122
1118
  else out.fields.via = r.uuid
1123
1119
  }
1124
1120
  if (draft.fields.page !== undefined) out.fields.page = page(draft.fields.page, 'The post')
1121
+ // A time goes to the backend in its own form (`wireTime`); one that is the instant the post
1122
+ // holds stays as it is held, so writing the same file again changes nothing.
1123
+ const raw = draft.fields.send_at
1124
+ if (raw !== undefined && raw !== null) {
1125
+ if (!isTime(raw)) errors.push(`The post's \`send_at\` is ${JSON.stringify(raw)}: give a time with its offset, such as 2026-11-24T09:00-05:00.`)
1126
+ else {
1127
+ const held = draft.id ? index.byUuid.get(draft.id)?.data?.send_at : undefined
1128
+ out.fields.send_at = sameInstant(held, raw) ? held : wireTime(raw)
1129
+ }
1130
+ }
1125
1131
  return { draft: out, creates: via.creates(), errors }
1126
1132
  }
1127
1133
 
@@ -1553,7 +1559,8 @@ async function send(args) {
1553
1559
  const arg = positionals(args)[1]
1554
1560
  const now = args.includes('--now')
1555
1561
  const atGiven = args.includes('--at')
1556
- const time = flagValue(args, '--at')
1562
+ const given = flagValue(args, '--at')
1563
+ const time = wireTime(given)
1557
1564
  if (!arg) {
1558
1565
  say.err('Name the post: uniweb promote send <post> [--at <time> | --now]')
1559
1566
  return { exitCode: 2 }
@@ -1562,12 +1569,12 @@ async function send(args) {
1562
1569
  say.err('`--now` and `--at` each say when — give one.')
1563
1570
  return { exitCode: 2 }
1564
1571
  }
1565
- if (atGiven && !isTime(time)) {
1572
+ if (atGiven && !isTime(given)) {
1566
1573
  say.err('`--at` takes a time with its offset, such as 2026-11-24T09:00-05:00.')
1567
1574
  return { exitCode: 2 }
1568
1575
  }
1569
1576
  if (atGiven && Date.parse(time) <= Date.now()) {
1570
- say.err(`\`--at ${time}\` has passed: give a time ahead, or send it now with --now.`)
1577
+ say.err(`\`--at ${given}\` has passed: give a time ahead, or send it now with --now.`)
1571
1578
  return { exitCode: 2 }
1572
1579
  }
1573
1580
  const file = draftFile(arg)
@@ -1598,7 +1605,7 @@ async function send(args) {
1598
1605
 
1599
1606
  // The time it goes out at: --at's, else the file's own send_at where it names one, else the post's.
1600
1607
  const held = parsed && parsed.draft.fields.send_at !== undefined ? parsed.draft.fields.send_at : (post?.data?.send_at ?? null)
1601
- const when = now ? null : atGiven ? time : held
1608
+ const when = now ? null : atGiven ? time : wireTime(held)
1602
1609
  if (when && !atGiven && Date.parse(when) <= Date.now()) {
1603
1610
  say.err(`Post ${id} holds send_at ${when}, which has passed: send it now with --now, or at another time with --at <time>.`)
1604
1611
  return { exitCode: 2 }
@@ -7,8 +7,10 @@
7
7
  * uniweb site secret <service> <name> [<site-uuid>] set a secret a service uses;
8
8
  * it asks for the value
9
9
  * uniweb site secret <service> <name> --clear [<site-uuid>] clear it
10
+ * uniweb site admin [<site-uuid>] open the site backend's administration, as its owner
11
+ * uniweb site visit [<site-uuid>] open the site, signed in as its owner
10
12
  *
11
- * Without a uuid, `unpublish`, `delete` and `secret` act on the site this project is synced to on
13
+ * Without a uuid, every verb but `list` acts on the site this project is synced to on
12
14
  * that backend. The workspace is the command's (`--org @x` / `--personal`), else the
13
15
  * login's — as for every site request.
14
16
  *
@@ -67,8 +69,11 @@ const USAGE = [
67
69
  ' the value, which no argument or file carries',
68
70
  ' secret <service> <name> --clear [<site-uuid>]',
69
71
  ' Clear it',
72
+ ' admin [<site-uuid>] Open the administration of the site’s backend in your',
73
+ ' browser, signed in as the site’s owner',
74
+ ' visit [<site-uuid>] Open the site in your browser, signed in as its owner',
70
75
  '',
71
- 'Without a uuid, unpublish, delete and secret act on the site this project is synced to.',
76
+ 'Without a uuid, every command but list acts on the site this project is synced to.',
72
77
  'The workspace is --org @x or --personal, else the one chosen at login.'
73
78
  ].join('\n')
74
79
 
@@ -471,6 +476,89 @@ export async function siteSecret(args, { readValue = askSecretValue } = {}) {
471
476
  return { exitCode: 0 }
472
477
  }
473
478
 
479
+ /** `admin` and `visit`: the owner's door each opens, and what is behind it. */
480
+ const DOORS = {
481
+ admin: { door: 'manage', what: (label) => `the administration of ${label}’s backend`, running: 'Opening a site’s administration' },
482
+ visit: { door: 'visit', what: (label) => label, running: 'Opening a site, signed in' }
483
+ }
484
+
485
+ /**
486
+ * `uniweb site admin [<site-uuid>]` and `uniweb site visit [<site-uuid>]` — open the person's
487
+ * browser signed in as the site's owner: in the administration of the site's backend (the
488
+ * payment account, teams, roles, an integration's keys) or on the site itself. The way in from
489
+ * the terminal with no app, and the same rules as the app's buttons: owner only, and a backend
490
+ * that is running.
491
+ *
492
+ * ⛔ THE ADDRESS IS A CREDENTIAL. The backend answers a single-use sign-in, valid for a short
493
+ * time, so it is opened and never printed: not on success, not when no browser opens, not in an
494
+ * error. Where no browser opens, the command says so and stops; the person runs it where one
495
+ * can. An agent's transcript, a terminal's scrollback and a pasted log are all places a printed
496
+ * sign-in would land.
497
+ *
498
+ * @param {string[]} args
499
+ * @param {'admin'|'visit'} verb
500
+ * @param {{ open?: (url: string) => Promise<boolean> }} [io]
501
+ */
502
+ export async function siteOwnerDoor(args, verb, { open } = {}) {
503
+ const { door, what, running } = DOORS[verb]
504
+ if (positionals(args).length > 2) {
505
+ say.err(`\`uniweb site ${verb}\` takes at most a site uuid.`)
506
+ return { exitCode: 2 }
507
+ }
508
+ const conn = await connect(args, running)
509
+ if (conn.refused) {
510
+ say.err(conn.refused)
511
+ return { exitCode: 2 }
512
+ }
513
+ const { client } = conn
514
+ const target = await targetSite(args, client, verb)
515
+ if (!target) return { exitCode: 2 }
516
+ const listed = await findSite(client, target.uuid)
517
+ const label = listed?.name ? `“${listed.name}” (${target.uuid})` : target.uuid
518
+
519
+ const res = await client.ownerSignIn(target.uuid, door)
520
+ if (!res.ok) {
521
+ const body = await res.clone().json().catch(() => null)
522
+ if (res.status === 404) {
523
+ // ⭐ The backend answers 404 to anyone but the owner, never saying whether the site
524
+ // exists. A site the workspace lists is one this account is not the owner of — or a
525
+ // backend that predates the route.
526
+ say.err(
527
+ listed
528
+ ? `${client.origin} won't open ${label} for you: only the site's owner can, from this command.`
529
+ : `${client.origin} has no site ${target.uuid} that you own.`
530
+ )
531
+ if (listed) say.dim('A backend older than this command answers the same way.')
532
+ } else if (res.status === 409) {
533
+ say.err(
534
+ body?.detail
535
+ ? `${label} can't be opened yet: ${body.detail}`
536
+ : verb === 'visit'
537
+ ? `${label} can't be opened yet: its backend is not running, or it has no address. Publish it first: uniweb publish`
538
+ : `${label} can't be opened yet: its backend is not running. Publish it first: uniweb publish`
539
+ )
540
+ } else {
541
+ await sayRefusal(res, { uuid: target.uuid, verb: `open`, origin: client.origin })
542
+ }
543
+ return { exitCode: 1 }
544
+ }
545
+ const body = await res.json().catch(() => null)
546
+ const url = typeof body?.url === 'string' ? body.url : ''
547
+ if (!/^https?:\/\//i.test(url)) {
548
+ say.err(`${client.origin} answered without an address to open.`)
549
+ return { exitCode: 1 }
550
+ }
551
+ const opener = open || (await import('../utils/registry-auth.js')).openBrowser
552
+ if (!(await opener(url))) {
553
+ say.err(`Couldn't open a browser here, so ${what(label)} was not opened.`)
554
+ say.dim('Its address signs you in, so it is not printed. Run this where a browser can open:')
555
+ say.dim(`uniweb site ${verb}${positionals(args)[1] ? ` ${target.uuid}` : ''}`)
556
+ return { exitCode: 1 }
557
+ }
558
+ say.ok(`Opened ${what(label)} in your browser, signed in as its owner.`)
559
+ return { exitCode: 0 }
560
+ }
561
+
474
562
  export async function site(args = []) {
475
563
  const badFlag = checkFlags('site', args)
476
564
  if (badFlag) {
@@ -483,6 +571,7 @@ export async function site(args = []) {
483
571
  if (sub === 'unpublish') return await unpublish(args)
484
572
  if (sub === 'delete') return await remove(args)
485
573
  if (sub === 'secret') return await siteSecret(args)
574
+ if (sub === 'admin' || sub === 'visit') return await siteOwnerDoor(args, sub)
486
575
  } catch (err) {
487
576
  say.err(err instanceof WorkspaceMismatchError ? err.message : err?.message || String(err))
488
577
  return { exitCode: 1 }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-19T17:58:06.777Z",
3
+ "generatedAt": "2026-11-21T18:51:43.062Z",
4
4
  "packages": {
5
5
  "@uniweb/api": {
6
6
  "version": "1.7.6"
@@ -54,7 +54,7 @@
54
54
  "version": "1.1.2"
55
55
  },
56
56
  "@uniweb/templates": {
57
- "version": "1.2.15"
57
+ "version": "1.2.16"
58
58
  },
59
59
  "@uniweb/theming": {
60
60
  "version": "1.3.3"
package/src/index.js CHANGED
@@ -2186,6 +2186,8 @@ ${colors.bright}Usage:${colors.reset}
2186
2186
  uniweb site delete [<site-uuid>] [--yes]
2187
2187
  uniweb site secret <service> <name> [<site-uuid>]
2188
2188
  uniweb site secret <service> <name> --clear [<site-uuid>] [--yes]
2189
+ uniweb site admin [<site-uuid>]
2190
+ uniweb site visit [<site-uuid>]
2189
2191
 
2190
2192
  ${colors.bright}list${colors.reset} gives each site's name, uuid, and whether it is live.
2191
2193
  ${colors.bright}unpublish${colors.reset} takes a site offline, and its content stays.
@@ -2194,8 +2196,13 @@ ${colors.bright}secret${colors.reset} sets a secret one of the site's services u
2194
2196
  token (\`uniweb site secret x token\`). It asks for the value at a prompt that doesn't
2195
2197
  show it: no argument or file carries one, and with no terminal it refuses. The live
2196
2198
  site has it from its next publish. \`--clear\` removes it.
2199
+ ${colors.bright}admin${colors.reset} opens the administration of the site's backend (its payment account, teams,
2200
+ roles, an integration's keys) in your browser, signed in as the site's owner.
2201
+ ${colors.bright}visit${colors.reset} opens the site itself, signed in as its owner. Both are the owner's alone,
2202
+ and the site's backend must be running. The address they open signs you in, so it is
2203
+ never printed: where no browser can open, they say so and stop.
2197
2204
 
2198
- Without a uuid, \`unpublish\`, \`delete\` and \`secret\` act on the site this project is synced to.
2205
+ Without a uuid, every command but \`list\` acts on the site this project is synced to.
2199
2206
  \`unpublish\`, \`delete\` and \`secret --clear\` ask first, and \`--yes\` is the only way
2200
2207
  past the question: with no terminal and no \`--yes\` they refuse. Deleting this
2201
2208
  project's own site also forgets it here, so the next push creates a new one.
@@ -106,7 +106,7 @@ const VERBS = {
106
106
  */
107
107
  forget: ['--server', '--all'],
108
108
  /**
109
- * `site list | unpublish | delete | secret` — a workspace's sites. `--yes` confirms a write;
109
+ * `site list | unpublish | delete | secret | admin | visit` — a workspace's sites. `--yes` confirms a write;
110
110
  * `--json` is `list`'s porcelain; `--clear` makes `secret` remove one; the workspace is
111
111
  * `--org` / `--personal`.
112
112
  */