uniweb 1.35.1 → 1.35.3

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.1",
3
+ "version": "1.35.3",
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",
45
- "@uniweb/semantic-parser": "~1.13.5",
44
+ "@uniweb/content-writer": "~1.3.2",
46
45
  "@uniweb/core": "~1.6.13",
47
- "@uniweb/content-writer": "~1.3.2"
46
+ "@uniweb/schemas": "~1.7.4",
47
+ "@uniweb/semantic-parser": "~1.13.5"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@uniweb/semantic-parser": "~1.13.5",
51
51
  "@uniweb/content-reader": "~1.5.11",
52
- "@uniweb/build": "~1.24.0"
52
+ "@uniweb/build": "~1.24.2"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@uniweb/build": {
@@ -136,6 +136,27 @@ await checkout(offering) // sends the buyer to pay; a free one-off is he
136
136
  - `useEntitlements()` — what the viewer holds, for "My courses". `useHolders({ schema, uuid })` — who holds a record, for a roster: its owner's or an `admin`'s to read, `forbidden` for anyone else, so draw nothing.
137
137
  - Why a checkout was refused: `error.extensions.reason` — `payments_not_ready`, `coupon_not_applicable` (with `cause`), `not_for_sale`.
138
138
 
139
+ **Prices for visitors who aren't signed in** come as records, so the first page a visit lands on already shows them, to people and to search engines. A section declares the store's catalog, a site query reads it, and the site's `blueprint.yml` opens it to visitors:
140
+
141
+ ```yaml
142
+ # queries.yml
143
+ store: { schema: '@uniweb/catalog' }
144
+ # blueprint.yml
145
+ publicQueries:
146
+ '@uniweb/catalog': { whole: true }
147
+ ```
148
+
149
+ ```jsx
150
+ // meta.js: data: { store: { schema: '@uniweb/catalog', whole: true } }
151
+ const catalogs = content.data.store // [{ info: { name, currency }, offering: [{ entry: { schema, entity, brief }, price, currency?, charge_kind }] }]
152
+ ```
153
+
154
+ - Join each record to the offering whose `entry.entity` is its uuid. `price` is in the currency's smallest unit, and `currency` is the offering's own or else `info.currency`.
155
+ - More than one catalog means none is the store, and a buyer can't pay: show no price.
156
+ - It needs the site's backend and Live Records (`records: true`). Buying, and anything that is one member's own, is `useStore()` after sign-in.
157
+ - A price the owner changes reaches visitors within about five minutes: the host keeps each answer that long, by design.
158
+ - The catalog is the backend's, written by the owner in the app, so a build and a push refuse `records/uniweb/catalog/` files.
159
+
139
160
  ## The inbox
140
161
 
141
162
  ```jsx
@@ -218,6 +239,10 @@ await createEntity({ schema: '@/submission', unit: course.unit, items: [...] })
218
239
 
219
240
  Nested items in one create: give an item `uuid: uuidv7()` and a later item names it as `parent` (`{ section: 'degrees/thesis', parent: degree, data }`); those uuids serve the write alone.
220
241
 
242
+ **Sent twice, made once:** give a create the new entry's own `uuid`, made once when the person starts adding it (`const [uuid] = useState(uuidv7)`), and a second click or a retry answers with the entry the first one made. Without it, each call makes an entry.
243
+
244
+ **A member's uploads:** `const { upload } = useUpload({ entity })`, then `await upload(input.files)` → `[{ url, assetId, assetExt, name, type, size, prepared, note? }]`; store `url` in the entry. Each file is prepared in the browser first, by the rule for uploaded media: a picture becomes a WebP when that makes it 10% smaller or turns it upright, and whatever is kept in its own format loses its location and camera data. Tell the member a `note`: `unconverted` (a TIFF or HEIC the browser couldn't convert) or `unreduced` (a video over the rule's bitrate). Upload through `useUpload`: it is what keeps a photo's location from going up with it.
245
+
221
246
  ## A backend on your machine
222
247
 
223
248
  ```yaml
@@ -6,6 +6,7 @@ On-demand guide (`uniweb guide promote`); AGENTS.md is assumed read. For a site
6
6
 
7
7
  - **The person** connects each account at its network, in a browser signed in to the app; you hand them the address `uniweb promote connect <network>` prints. They turn on the site's Analytics, which carries Promote, in the app. They reconnect an account that needs it, and an admin hands on one whose person left. They decide what goes out and what is spent.
8
8
  - **You** draft posts and campaigns, check the pages they link to, send and start what your person agreed to, and read what it brought. You act with their session, at the access they have; an account's tokens never pass through the CLI.
9
+ - **Access follows the site's.** Reading and drafting take edit on the site; sending, scheduling, starting, pausing and resuming take admin. Someone who can only view the site sees none of its Promote.
9
10
 
10
11
  ## On one screen
11
12
 
@@ -52,6 +53,8 @@ uniweb promote unschedule holiday.md # a draft again, its time kept
52
53
 
53
54
  - **`send` given the file writes it first,** as `post` does, so what goes out is what the file says. If the app changed the post since, it is refused and nothing goes out. `send <id>` sends the post as stored.
54
55
  - **`via`** names a network, and the post goes out through the site's account there. The first time, the CLI chooses it from your one account on that network. With several, give `via: { network: x, connection: <id> }`; the refusal lists them.
56
+ - **`uniweb promote use <network> posts`** chooses what on that account the site posts as, such as a page; `ads`, `search` and `listing` choose its ad account, property or listing. It lists the choices when there are several, and `--connection <id>` and `--target <id>` choose. A started campaign's account stays as it is.
57
+ - **What a network takes:** `post` says when a part is longer than its network takes, as that network counts it, the link included; most accounts would be refused. A post with more parts than its network takes (Facebook and LinkedIn take one) isn't sent until it has fewer.
55
58
  - **`page`** is a page of the site as pushed, so push a new page first. The live site must serve it in the post's language, or the send fails: publish first.
56
59
  - **A picture** given as a file is uploaded as one of the site's own, in its format. An `https:` address is kept as written, and so is one `show` printed.
57
60
  - **The words go out as written**, as plain text: Markdown formatting shows as typed.
@@ -96,7 +99,7 @@ uniweb promote resume holiday --yes
96
99
  - **A change made since then is never written over.** If the app or another run changed the draft, your write is refused and nothing is written. `uniweb promote show <id> > file` gives you the draft as it stands, to put your change into.
97
100
  - **Nothing is deleted by leaving it out.** An ad group or an ad the file doesn't hold is kept, and named. `uniweb promote delete <id>` deletes. A post's parts are its words, so the parts the file gives are the post's.
98
101
  - **A post that went out isn't edited or deleted.** To post again, drop `id` and `version` and make a new draft.
99
- - **Changing a scheduled post makes it a draft again,** its time kept, and `send` schedules it again.
102
+ - **Changing a scheduled post makes it a draft again,** its time kept, and `send` schedules it again. `send --at` moves the time and schedules in one step, so if it's refused the post stays as it was.
100
103
  - **An `<id>`** is the short one `status` shows, the file a draft was written from, or a campaign's name.
101
104
 
102
105
  ## The page it lands on
@@ -133,6 +136,7 @@ A campaign with `goal: conversions` optimizes for what its network hears back. T
133
136
  | `status` | the site's Promote, and what needs the person |
134
137
  | `check <step>` · `check <route>` | one getting-found step (`sitemap`), or a page as a landing page |
135
138
  | `connect <network>` | the address where the person connects an account |
139
+ | `use <network> <posts\|ads\|search\|listing>` | what on that account the site goes out through; `--connection`, `--target` choose |
136
140
  | `post <file>` · `campaign <file>` | a draft, made or updated; `-` reads stdin |
137
141
  | `show <id>` | one post or campaign as its file holds it; its state goes to stderr |
138
142
  | `delete <id>` | a post, a campaign, an ad group or an ad |
@@ -1049,20 +1049,21 @@ export class BackendClient {
1049
1049
 
1050
1050
  /**
1051
1051
  * POST /dev/site/promotion/{site}/posts/{post}/{act} — a post's doors: `publish` (now),
1052
- * `schedule` (at its `send_at`) and `unschedule` (a draft again, its `send_at` kept). Each
1053
- * answers `{ delivery }`; `unschedule`'s is `null` once a draft. Publishing and scheduling
1054
- * take `admin` on the site and `edit` on the account it goes out through; unscheduling takes
1055
- * `edit` on the site.
1052
+ * `schedule` (at its `send_at`, or at the `send_at` the body gives, in one act refused whole)
1053
+ * and `unschedule` (a draft again, its `send_at` kept). Each answers `{ delivery }`;
1054
+ * `unschedule`'s is `null` once a draft. Publishing and scheduling take `admin` on the site and
1055
+ * `edit` on the account it goes out through; unscheduling takes `edit` on the site.
1056
1056
  *
1057
1057
  * @param {string} siteUuid
1058
1058
  * @param {string} postUuid
1059
1059
  * @param {'publish'|'schedule'|'unschedule'} act
1060
+ * @param {{ send_at: string } | null} [body] - `schedule`'s new time
1060
1061
  * @returns {Promise<Response>}
1061
1062
  */
1062
- async postAction(siteUuid, postUuid, act) {
1063
+ async postAction(siteUuid, postUuid, act, body = null) {
1063
1064
  return this.request(
1064
1065
  `/dev/site/promotion/${encodeURIComponent(siteUuid)}/posts/${encodeURIComponent(postUuid)}/${act}`,
1065
- { method: 'POST' }
1066
+ { method: 'POST', ...(body ? { body: JSON.stringify(body) } : {}) }
1066
1067
  )
1067
1068
  }
1068
1069
 
@@ -1110,6 +1111,20 @@ export class BackendClient {
1110
1111
  return this.request('/dev/connections')
1111
1112
  }
1112
1113
 
1114
+ /**
1115
+ * GET /dev/connections/{uuid}/reach?use= — `{ reach: [{ id, name }] }`: what the connection
1116
+ * reaches at its network for one use (`posts`, `ads`, `search`, `listing`), read from the
1117
+ * network as asked. Each is the shape a `networks` item's `target` holds. An empty list is an
1118
+ * account that reaches nothing for that use yet. Takes `read` on the connection.
1119
+ *
1120
+ * @param {string} connectionUuid
1121
+ * @param {string} use
1122
+ * @returns {Promise<Response>}
1123
+ */
1124
+ async connectionReach(connectionUuid, use) {
1125
+ return this.request(`/dev/connections/${encodeURIComponent(connectionUuid)}/reach`, { query: { use } })
1126
+ }
1127
+
1113
1128
  /**
1114
1129
  * POST /dev/connections/consent — `{ network, return_to? }` → `{ address }`, the network's
1115
1130
  * consent page. The browser that finishes it must be signed in to the app as the same
@@ -79,15 +79,23 @@ function referencedFirst(libraries, schemas, mappings = {}) {
79
79
  return out
80
80
  }
81
81
 
82
- /** The types a mapping names, as its `_mappings` entry holds them (in full): its `model` and its `follow` lines'. */
82
+ /**
83
+ * The types a mapping names, as its `_mappings` entry holds them (in full) or as written: its `model`
84
+ * and its `follow` lines', and the same in each of a `set`'s `parts`.
85
+ */
83
86
  export function typesNamedBy(mapping) {
84
87
  if (!mapping || typeof mapping !== 'object') return []
85
88
  const out = []
86
- if (typeof mapping.model === 'string') out.push(mapping.model)
87
- for (const line of Array.isArray(mapping.follow) ? mapping.follow : []) {
88
- if (!line || typeof line !== 'object') continue
89
- for (const spec of Object.values(line)) if (spec && typeof spec.model === 'string') out.push(spec.model)
89
+ const rulesOf = (rules) => {
90
+ if (!rules || typeof rules !== 'object') return
91
+ if (typeof rules.model === 'string') out.push(rules.model)
92
+ for (const line of Array.isArray(rules.follow) ? rules.follow : []) {
93
+ if (!line || typeof line !== 'object') continue
94
+ for (const spec of Object.values(line)) if (spec && typeof spec.model === 'string') out.push(spec.model)
95
+ }
90
96
  }
97
+ rulesOf(mapping)
98
+ for (const part of Array.isArray(mapping.parts) ? mapping.parts : []) rulesOf(part)
91
99
  return out
92
100
  }
93
101
 
@@ -183,6 +183,7 @@ export const REASONS = {
183
183
  connection_not_permitted: 'whoever scheduled it may no longer post through its account',
184
184
  network_not_offered: 'this backend does not offer that network',
185
185
  network_refused: 'the network refused it',
186
+ too_many_parts: 'it has more parts than its network takes in a post',
186
187
  promote_off: 'the site has no Promote: it comes with the site\'s Analytics, which the person turns on in the app',
187
188
  feature_not_subscribed: 'Promote comes with the site\'s Analytics, which this site does not have yet. The person turns it on in the app'
188
189
  }
@@ -430,6 +431,86 @@ export function picturesOf(draft) {
430
431
  return [...new Set(out)]
431
432
  }
432
433
 
434
+ // ── What a network takes in a post ─────────────────────────────────────────────────
435
+
436
+ /** A network as a person names it. */
437
+ export const NETWORK_NAMES = { x: 'X', linkedin: 'LinkedIn', facebook: 'Facebook', google: 'Google', bing: 'Bing' }
438
+
439
+ /** The code points X counts as one; any other counts two (X's own ranges). */
440
+ const X_LIGHT = [[0, 4351], [8192, 8205], [8208, 8223], [8242, 8247]]
441
+ /** What X counts an address as, wherever it stands. */
442
+ const X_URL = 23
443
+ /** A grapheme X counts as one emoji, sequences included: a pictograph, a keycap, a flag. */
444
+ const EMOJI = /\p{Extended_Pictographic}|⃣|\p{Regional_Indicator}/u
445
+
446
+ /**
447
+ * A text's length as its network counts it. As X counts (`counting: "x"`): NFC first, each
448
+ * address 23, each emoji 2, a code point in X's light ranges 1 and any other 2. Otherwise, by its
449
+ * characters.
450
+ */
451
+ export function countedLength(text, counting) {
452
+ const t = String(text ?? '').normalize('NFC')
453
+ if (counting !== 'x') return Array.from(t).length
454
+ let n = 0
455
+ const rest = t.replace(/https?:\/\/\S+/gi, () => {
456
+ n += X_URL
457
+ return ''
458
+ })
459
+ for (const { segment } of new Intl.Segmenter(undefined, { granularity: 'grapheme' }).segment(rest)) {
460
+ if (EMOJI.test(segment)) {
461
+ n += 2
462
+ continue
463
+ }
464
+ for (const ch of segment) {
465
+ const cp = ch.codePointAt(0)
466
+ n += X_LIGHT.some(([a, b]) => cp >= a && cp <= b) ? 1 : 2
467
+ }
468
+ }
469
+ return n
470
+ }
471
+
472
+ /**
473
+ * What a post's network takes, as `/dev/config` tells it (`promote.limits[network].posts`):
474
+ * `characters` a part, counted as `counting` says; `link`, what the post's link counts in its
475
+ * first part; `parts`, how many parts it takes (none told: a thread). Null when none is told.
476
+ */
477
+ export function postLimits(config, network) {
478
+ const limits = config?.promote?.limits?.[network]?.posts
479
+ return isPlainObject(limits) ? limits : null
480
+ }
481
+
482
+ /**
483
+ * Where a post asks more than its network takes, in words: more parts, which the backend refuses
484
+ * before anything goes out, and a part longer than the network takes, which the network refuses
485
+ * for most accounts (some post longer), so it is a note.
486
+ *
487
+ * @param {{ text?: string }[]} parts - the post's parts, in order
488
+ * @param {object|null} limits - `postLimits`
489
+ * @param {{ network: string, link: boolean }} post - its network, and whether it carries a link
490
+ * @returns {{ parts: string|null, lengths: string[] }}
491
+ */
492
+ export function overLimits(parts, limits, { network, link }) {
493
+ const out = { parts: null, lengths: [] }
494
+ if (!limits) return out
495
+ const name = NETWORK_NAMES[network] ?? network
496
+ if (Number.isInteger(limits.parts) && parts.length > limits.parts) {
497
+ const takes = limits.parts === 1 ? 'one part' : `${limits.parts} parts`
498
+ out.parts = `${name} takes ${takes} in a post, and this one has ${parts.length}: make it ${limits.parts === 1 ? 'one' : limits.parts}.`
499
+ }
500
+ if (Number.isInteger(limits.characters)) {
501
+ parts.forEach((p, i) => {
502
+ const withLink = i === 0 && link && Number.isInteger(limits.link)
503
+ const n = countedLength(p.text, limits.counting) + (withLink ? limits.link : 0)
504
+ if (n <= limits.characters) return
505
+ out.lengths.push(
506
+ `${parts.length === 1 ? 'It' : `Part ${i + 1}`} is ${n} characters${limits.counting === 'x' ? ' as X counts them' : ''}` +
507
+ `${withLink ? `, its link's ${limits.link} among them` : ''}, and ${name} takes ${limits.characters}: most accounts there would be refused.`
508
+ )
509
+ })
510
+ }
511
+ return out
512
+ }
513
+
433
514
  /** Whether a picture is an address already, kept as written, rather than a file to upload. */
434
515
  export function isAddress(picture) {
435
516
  return /^https?:\/\//i.test(picture)
@@ -5,6 +5,7 @@
5
5
  * uniweb promote status [--json] the site's Promote on one screen, and what needs a person
6
6
  * uniweb promote check <step> [--json] check one getting-found step (`sitemap`, say)
7
7
  * uniweb promote connect <network> the address where a person connects an account
8
+ * uniweb promote use <network> <use> the account, and the page or ad account, it goes out through
8
9
  * uniweb promote post <file> make a post's draft, or update the one the file names
9
10
  * uniweb promote campaign <file> the same for a campaign, its ad groups and ads
10
11
  * uniweb promote show <id> [--json] one post or campaign, as a draft holds it
@@ -59,7 +60,10 @@ import {
59
60
  indexPromotion,
60
61
  isAddress,
61
62
  kindOf,
63
+ NETWORK_NAMES,
64
+ overLimits,
62
65
  pageRoute,
66
+ postLimits,
63
67
  parseDraft,
64
68
  picturesOf,
65
69
  planCampaign,
@@ -107,6 +111,9 @@ const USAGE = [
107
111
  ' and what needs a person',
108
112
  ' check <step> Check one getting-found step, e.g. uniweb promote check sitemap',
109
113
  ' connect <network> The address where a person connects an account at a network',
114
+ ' use <network> <use> The account and the page, ad account, property or listing the site',
115
+ ' goes out through for posts, ads, search or listing; it lists the',
116
+ ' choices, and --connection <id> and --target <id> choose',
110
117
  ' post <file> Make a post\'s draft (Markdown, YAML or JSON), or update the one',
111
118
  ' the file names; the file gets its id and version back',
112
119
  ' campaign <file> The same for a campaign (YAML or JSON), its ad groups and ads',
@@ -131,7 +138,7 @@ const USAGE = [
131
138
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
132
139
 
133
140
  /** Flags that take a value, so the value is not read as an argument. */
134
- const VALUED = new Set(['--org', '--site', '--at'])
141
+ const VALUED = new Set(['--org', '--site', '--at', '--connection', '--target', '--from', '--to'])
135
142
 
136
143
  /** The arguments that are not flags, skipping the values of the flags that take one. */
137
144
  function positionals(args) {
@@ -203,7 +210,7 @@ async function targetSite(args, client, verb) {
203
210
  * @param {{ site: string, origin: string, what: string, index?: object }} ctx - `what` completes
204
211
  * "You may not …"; `index` names a campaign a refusal names by uuid
205
212
  */
206
- async function sayRefusal(res, { site, origin, what, index = null, notFound = null }) {
213
+ async function sayRefusal(res, { site, origin, what, index = null, notFound = null, forbidden = null }) {
207
214
  const body = await res.clone().json().catch(() => null)
208
215
  const reason = typeof body?.reason === 'string' ? body.reason : null
209
216
  const own = [reason, body?.detail ?? body?.message ?? body?.title].filter((x) => typeof x === 'string' && x).join(': ')
@@ -213,7 +220,10 @@ async function sayRefusal(res, { site, origin, what, index = null, notFound = nu
213
220
  say.err(`${REASONS.feature_not_subscribed}.`)
214
221
  } else if (res.status === 403 && body?.op === 'admin') {
215
222
  say.err(`Only an admin of the site may ${what}. What is written stays, for one of them to do it.`)
216
- } else if (res.status === 403 && body?.op === 'edit' && body?.target) {
223
+ } else if (res.status === 403 && forbidden) {
224
+ say.err(forbidden)
225
+ } else if (res.status === 403 && body?.op === 'edit' && body?.target && !String(body.target).includes(site)) {
226
+ // A refusal names what it refused (`target`): the site itself, or the account a post or a campaign goes out through.
217
227
  say.err(`The account it goes out through is not shared with you for that. Use one you can use, or ask whoever connected it to share it.`)
218
228
  } else if (res.status === 403) {
219
229
  say.err(`You may not ${what} on this site${body?.op ? ` (it takes ${body.op})` : ''}.`)
@@ -225,6 +235,9 @@ async function sayRefusal(res, { site, origin, what, index = null, notFound = nu
225
235
  `${name ? `“${name}”` : 'The campaign'} has started in an ad account, and what runs there is fixed, so the write is refused — nothing changed. ` +
226
236
  'Add an ad account to its `via`, or draft a new campaign.'
227
237
  )
238
+ } else if (res.status === 400 && reason === 'too_many_parts') {
239
+ const takes = body?.parts === 1 ? 'one part' : `${body?.parts ?? 'fewer'} parts`
240
+ say.err(`${NETWORK_NAMES[body?.network] ?? body?.network ?? 'Its network'} takes ${takes} in a post, and this one has more, so nothing went out. Make it ${body?.parts === 1 ? 'one' : (body?.parts ?? 'fewer')}.`)
228
241
  } else if (res.status === 409) {
229
242
  say.err(`Refused, nothing changed: what was named changed since it was read — in the app, or by another run${own ? ` (${own})` : ''}. Read it again: uniweb promote show <id>`)
230
243
  } else {
@@ -235,6 +248,9 @@ async function sayRefusal(res, { site, origin, what, index = null, notFound = nu
235
248
  /** A 404 on reading a site's Promote: no such site there, or a backend without these routes. */
236
249
  const notOffered = (origin, site) => `${origin} has no site ${site}, or does not offer Promote to this CLI yet.`
237
250
 
251
+ /** A 403 on reading it: the site is shared with you to view, and Promote takes edit. */
252
+ const VIEW_ONLY = 'Promote is for those who can edit the site, and you can only view it: an owner or admin of the site can give you edit, in the app.'
253
+
238
254
  /**
239
255
  * The networks the deployment offers to connect, as tokens. None when `/dev/config` names none,
240
256
  * since the backend leaves `promote.networks` out while it offers none; null when `/dev/config`
@@ -353,7 +369,7 @@ async function status(args) {
353
369
  offeredNetworks(client)
354
370
  ])
355
371
  if (!res.ok) {
356
- await sayRefusal(res, { site, origin: client.origin, what: 'read Promote', notFound: notOffered(client.origin, site) })
372
+ await sayRefusal(res, { site, origin: client.origin, what: 'read Promote', notFound: notOffered(client.origin, site), forbidden: VIEW_ONLY })
357
373
  return { exitCode: 1 }
358
374
  }
359
375
  const promotion = (await res.json().catch(() => null))?.promotion ?? null
@@ -718,11 +734,127 @@ async function begin(args, command, verb) {
718
734
  return { client: conn.client, workspace: conn.workspace, site }
719
735
  }
720
736
 
737
+ /** What a site goes out through a network for. */
738
+ const USES = ['posts', 'ads', 'search', 'listing']
739
+
740
+ /**
741
+ * `uniweb promote use <network> <posts|ads|search|listing>` — the account the site goes out
742
+ * through on a network for one use, and what at that account: the profile or page it posts as,
743
+ * the ad account its ads run in, a property, a listing. It lists the choices when there is more
744
+ * than one; `--connection <id>` and `--target <id>` choose. It makes or updates the site's one
745
+ * `networks` item for that network and use.
746
+ */
747
+ async function useAccount(args) {
748
+ const json = args.includes('--json')
749
+ const [, network, use] = positionals(args)
750
+ if (!network || !USES.includes(use)) {
751
+ say.err(`Name the network and what for: uniweb promote use <network> <${USES.join('|')}>`)
752
+ return { exitCode: 2 }
753
+ }
754
+ const at = await begin(args, 'Choosing an account', `use ${network} ${use}`)
755
+ if (!at.client) return at
756
+ const { client, site } = at
757
+ const index = await readIndex(client, site)
758
+ if (!index) return { exitCode: 1 }
759
+ const connections = await listedConnections(client)
760
+ if (connections === null) {
761
+ say.err(`Could not list the accounts you can use on ${client.origin}.`)
762
+ return { exitCode: 1 }
763
+ }
764
+ const name = NETWORK_NAMES[network] ?? network
765
+ const mine = connections.filter((k) => k.card?.network === network)
766
+ if (!mine.length) {
767
+ say.err(`You have no ${name} account to use. Its person connects one, in a browser: uniweb promote connect ${network}`)
768
+ return { exitCode: 2 }
769
+ }
770
+ const item = index.top('networks').find((n) => n.data?.network === network && n.data?.use === use) ?? null
771
+ const current = connectionOf(item?.data?.connection).uuid
772
+ const kIds = shortIds(mine.map((k) => k.uuid))
773
+ const named = (k) => `“${k.card?.name || k.card?.handle || k.uuid}”`
774
+ const choices = (lines, how) => {
775
+ if (json) console.log(JSON.stringify({ backend: client.origin, site, network, use, choose: how, ...lines }))
776
+ return { exitCode: 2 }
777
+ }
778
+
779
+ // The account: the one named, else the only one, else the one the site goes out through now.
780
+ const wantConnection = flagValue(args, '--connection')
781
+ const conn = wantConnection
782
+ ? mine.find((k) => idMatches(k.uuid, wantConnection))
783
+ : mine.length === 1 ? mine[0] : mine.find((k) => k.uuid === current)
784
+ if (!conn) {
785
+ if (!json) {
786
+ say.err(wantConnection ? `None of your ${name} accounts is ${wantConnection}. Choose one:` : `You have ${mine.length} ${name} accounts. Choose one:`)
787
+ for (const k of mine) say.dim(`${kIds.get(k.uuid)} ${named(k)}${k.card?.state && k.card.state !== 'connected' ? ` (${k.card.state})` : ''}`)
788
+ say.dim(`uniweb promote use ${network} ${use} --connection <id>`)
789
+ }
790
+ return choices({ connections: mine.map((k) => ({ uuid: k.uuid, short: kIds.get(k.uuid), card: k.card ?? null })) }, '--connection')
791
+ }
792
+
793
+ // What that account reaches for this use, read from the network as asked.
794
+ const res = await client.connectionReach(conn.uuid, use)
795
+ if (!res.ok) {
796
+ const body = await res.clone().json().catch(() => null)
797
+ if (res.status === 400 && body?.reason === 'use_not_offered') say.err(`${name} offers no ${use} to go out through.`)
798
+ else if (res.status === 409 && body?.reason === 'connection_cannot_act') say.err(`${named(conn)} can't act now: ${reasonWords(body?.why)}.`)
799
+ else if (res.status === 502) say.err(`${name} refused to say what ${named(conn)} reaches${body?.detail ? `: ${body.detail}` : ''}.`)
800
+ else if (res.status === 404) say.err(`${named(conn)} is not shared with you to read what it reaches: ask whoever connected it.`)
801
+ else await sayRefusal(res, { site, origin: client.origin, what: 'read what that account reaches', index })
802
+ return { exitCode: res.status === 400 ? 2 : 1 }
803
+ }
804
+ const reach = ((await res.json().catch(() => null))?.reach ?? []).filter((t) => t && typeof t.id === 'string')
805
+ if (!reach.length) {
806
+ say.err(`${named(conn)} reaches nothing on ${name} for ${use} yet. Make it there first (a page, an ad account), then run this again.`)
807
+ return { exitCode: 1 }
808
+ }
809
+ const wantTarget = flagValue(args, '--target')
810
+ const target = wantTarget
811
+ ? reach.find((t) => t.id === wantTarget || t.name === wantTarget)
812
+ : reach.length === 1 ? reach[0] : reach.find((t) => conn.uuid === current && t.id === item?.data?.target?.id)
813
+ if (!target) {
814
+ if (!json) {
815
+ say.err(`${wantTarget ? `${named(conn)} reaches no ${wantTarget} for ${use}.` : `${named(conn)} reaches ${reach.length} for ${use}.`} Choose one:`)
816
+ for (const t of reach) say.dim(`${t.id} “${t.name ?? t.id}”`)
817
+ say.dim(`uniweb promote use ${network} ${use}${mine.length > 1 ? ` --connection ${kIds.get(conn.uuid)}` : ''} --target <id>`)
818
+ }
819
+ return choices({ connection: conn.uuid, reach }, '--target')
820
+ }
821
+
822
+ // The site's one item for this network and use, made or pointed at what was chosen.
823
+ const same = Boolean(item) && current === conn.uuid && item.data?.target?.id === target.id
824
+ let uuid = item?.uuid ?? null
825
+ if (!same) {
826
+ const data = { ...(item?.data ?? {}), network, use, connection: conn.uuid, target: { id: target.id, name: target.name ?? target.id } }
827
+ uuid = uuid ?? mintUuidV7()
828
+ const op = item
829
+ ? { kind: 'update', uuid, data, if_unmodified_since: item.updated_at }
830
+ : { kind: 'create', section: 'networks', uuid, data }
831
+ const w = await client.writePromotionItems(site, [op])
832
+ if (!w.ok) {
833
+ const body = await w.clone().json().catch(() => null)
834
+ if (w.status === 409 && body?.reason === 'campaign_started') {
835
+ const started = index.byUuid.get(body?.campaign)?.data?.name
836
+ say.err(`${started ? `“${started}”` : 'A campaign'} has started through the site's ${name} ${use} account, and a started campaign's account stays as it is, paused or not. Nothing changed.`)
837
+ } else {
838
+ await sayRefusal(w, { site, origin: client.origin, what: 'choose its accounts', index })
839
+ }
840
+ return { exitCode: 1 }
841
+ }
842
+ }
843
+ if (json) {
844
+ console.log(JSON.stringify({ backend: client.origin, site, network, use, item: uuid, connection: conn.uuid, target, changed: !same }))
845
+ return { exitCode: 0 }
846
+ }
847
+ say.ok(`${same ? 'Already so: the' : 'The'} site's ${use} on ${name} go out through ${named(conn)}, as “${target.name ?? target.id}”.`)
848
+ const others = reach.filter((t) => t.id !== target.id)
849
+ if (others.length) say.dim(`It also reaches ${others.map((t) => `“${t.name ?? t.id}” (${t.id})`).join(', ')}: --target <id> chooses one.`)
850
+ return { exitCode: 0 }
851
+ }
852
+
721
853
  /** The site's Promote, read fresh and indexed — or null, the refusal said. */
722
854
  async function readIndex(client, site) {
723
855
  const res = await client.readPromotion(site)
724
856
  if (!res.ok) {
725
- await sayRefusal(res, { site, origin: client.origin, what: 'read Promote', notFound: notOffered(client.origin, site) })
857
+ await sayRefusal(res, { site, origin: client.origin, what: 'read Promote', notFound: notOffered(client.origin, site), forbidden: VIEW_ONLY })
726
858
  return null
727
859
  }
728
860
  return indexPromotion((await res.json().catch(() => null))?.promotion ?? null)
@@ -741,6 +873,17 @@ async function readPages(client, site) {
741
873
  }
742
874
  }
743
875
 
876
+ /**
877
+ * Where a post as stored asks more than its network takes (`overLimits`), by the limits this
878
+ * backend tells; none when it tells none.
879
+ */
880
+ async function limitsOf(client, index, post) {
881
+ const network = index.byUuid.get(post?.data?.via)?.data?.network
882
+ const config = network ? await client.discover().catch(() => null) : null
883
+ const parts = index.children('posts/parts', post.uuid).map((p) => p.data ?? {})
884
+ return overLimits(parts, postLimits(config, network), { network, link: Boolean(post.data?.page) })
885
+ }
886
+
744
887
  /** The caller's connections — null when they could not be listed. */
745
888
  async function listedConnections(client) {
746
889
  const res = await client.listConnections().catch(() => null)
@@ -1099,6 +1242,8 @@ async function writeDraft(args, kind) {
1099
1242
  const ids = shortIds(after.items.map((i) => i.uuid))
1100
1243
  const item = after.byUuid.get(plan.uuid)
1101
1244
  const id = ids.get(plan.uuid) ?? plan.uuid
1245
+ // What its network takes: more parts is refused when it goes out, a long part only noted.
1246
+ const over = kind === 'post' && item ? await limitsOf(client, after, item) : { parts: null, lengths: [] }
1102
1247
  if (json) {
1103
1248
  console.log(JSON.stringify({
1104
1249
  backend: client.origin,
@@ -1110,7 +1255,8 @@ async function writeDraft(args, kind) {
1110
1255
  made: !draft.id,
1111
1256
  writes: ops.length,
1112
1257
  file: input.file ? input.shown : null,
1113
- kept: (plan.kept ?? []).map((k) => ({ ...k, short: ids.get(k.uuid) }))
1258
+ kept: (plan.kept ?? []).map((k) => ({ ...k, short: ids.get(k.uuid) })),
1259
+ ...(kind === 'post' ? { limits: over } : {})
1114
1260
  }))
1115
1261
  return { exitCode: 0 }
1116
1262
  }
@@ -1139,6 +1285,8 @@ async function writeDraft(args, kind) {
1139
1285
  say.info(`Kept, not in your file: ${k.kind} ${k.name ? `“${k.name}” ` : ''}(${ids.get(k.uuid)}). \`uniweb promote delete ${ids.get(k.uuid)}\` deletes it.`)
1140
1286
  }
1141
1287
  }
1288
+ if (over.parts) say.warn(`${over.parts} Until then it can't be sent.`)
1289
+ for (const line of over.lengths) say.warn(line)
1142
1290
  if (fileNote) say.warn(fileNote)
1143
1291
  else if (!input.file && ops.length) say.dim(`From stdin, so no file keeps its ids: give your next draft of it \`id: ${plan.uuid}\` and \`version: ${version(plan.uuid)}\`.`)
1144
1292
  // The pages it lands on, checked in the site's files where this project holds them.
@@ -1148,7 +1296,7 @@ async function writeDraft(args, kind) {
1148
1296
  console.log()
1149
1297
  await landingNotes(dir, landing.routes, { networks: landing.networks, goal: landing.goal })
1150
1298
  }
1151
- if (kind === 'post' && wentOut(deliveryOf(after, item)) === false) {
1299
+ if (kind === 'post' && wentOut(deliveryOf(after, item)) === false && !over.parts) {
1152
1300
  const sendAt = item?.data?.send_at
1153
1301
  if (deliveryOf(after, item)?.status === 'scheduled') say.dim(`Scheduled for ${sendAt}: \`uniweb promote unschedule ${id}\` makes it a draft again`)
1154
1302
  else say.dim(sendAt ? `Send it at its time, ${sendAt}: uniweb promote send ${id}` : `Send it: uniweb promote send ${id} [--at <time>]`)
@@ -1371,23 +1519,14 @@ async function send(args) {
1371
1519
  const scheduledFor = before?.status === 'scheduled' ? (post.data?.send_at ?? null) : null
1372
1520
 
1373
1521
  if (file) {
1374
- // `--at` moves the file's own send_at, so the one write carries it and the file keeps saying it.
1375
- let text = file.text
1376
- if (atGiven && !sameInstant(held, time)) {
1377
- text = fileWithFields(file.text, file.format, { send_at: time })
1378
- if (!text) {
1379
- say.err(`Could not set the time in ${arg}: give it \`send_at: ${time}\`, then send it.`)
1380
- return { exitCode: 2 }
1381
- }
1382
- }
1383
- const draft = text === file.text ? parsed.draft : parseDraft(text, { format: file.format, kind: 'post' }).draft
1522
+ // The file's draft is written first, as `post` writes it; a new time goes with the schedule, below.
1384
1523
  const wrote = await writeParsed({
1385
1524
  client,
1386
1525
  site,
1387
1526
  index,
1388
- input: { file: file.path, shown: arg, text, dir: dirname(file.path) },
1527
+ input: { file: file.path, shown: arg, text: file.text, dir: dirname(file.path) },
1389
1528
  format: file.format,
1390
- draft,
1529
+ draft: parsed.draft,
1391
1530
  kind: 'post'
1392
1531
  })
1393
1532
  if (!wrote.after) return wrote
@@ -1397,44 +1536,49 @@ async function send(args) {
1397
1536
  post = index.byUuid.get(wrote.plan.uuid)
1398
1537
  id = shortIds(index.items.map((i) => i.uuid)).get(post.uuid)
1399
1538
  before = deliveryOf(index, post)
1400
- if (writes && text === file.text && !json) say.info(`Wrote what ${arg} says to post ${id} first: it differed from the post as stored.`)
1539
+ if (writes && !json) say.info(`Wrote what ${arg} says to post ${id} first: it differed from the post as stored.`)
1540
+ }
1541
+
1542
+ // What its network takes: more parts is refused before anything goes out, a long part noted.
1543
+ const over = await limitsOf(client, index, post)
1544
+ if (over.parts) {
1545
+ say.err(`${over.parts} Nothing went out.`)
1546
+ return { exitCode: 2 }
1401
1547
  }
1548
+ if (!json) for (const line of over.lengths) say.warn(line)
1402
1549
 
1550
+ // A new time goes with the schedule itself, in one act refused whole, so a refusal leaves the
1551
+ // post as it was: still scheduled at its old time, or a draft.
1552
+ const moving = Boolean(when) && !sameInstant(post.data?.send_at, when)
1403
1553
  let res
1404
- let moved = false
1405
1554
  if (when) {
1406
- if (before?.status === 'scheduled' && sameInstant(post.data?.send_at, when)) {
1555
+ if (before?.status === 'scheduled' && !moving) {
1407
1556
  if (!json) say.ok(`Post ${id} is scheduled for ${post.data.send_at} already.`)
1408
1557
  return out(before, 0)
1409
1558
  }
1410
- if (!sameInstant(post.data?.send_at, when)) {
1411
- // The time is the post's own field, written first. A write makes a scheduled post a draft again.
1412
- const wrote = await client.writePromotionItems(site, [
1413
- { kind: 'update', uuid: post.uuid, data: { ...post.data, send_at: when }, if_unmodified_since: post.updated_at }
1414
- ])
1415
- if (!wrote.ok) {
1416
- await sayRefusal(wrote, { site, origin: client.origin, what: 'set its time', index })
1417
- return { exitCode: 1 }
1418
- }
1419
- post.data = { ...post.data, send_at: when }
1420
- moved = true
1421
- writes++
1422
- }
1423
- res = await client.postAction(site, post.uuid, 'schedule')
1559
+ res = await client.postAction(site, post.uuid, 'schedule', moving ? { send_at: when } : null)
1424
1560
  } else {
1425
1561
  res = await client.postAction(site, post.uuid, 'publish')
1426
1562
  }
1427
1563
  if (!res.ok) {
1428
1564
  await sayRefusal(res, { site, origin: client.origin, what: 'send posts', index })
1429
- // What this command wrote stays written, so say what the post is now.
1430
- if (scheduledFor && writes) {
1431
- say.warn(`Post ${id} was scheduled for ${scheduledFor}, and writing to it made it a draft again${moved || (when && !sameInstant(scheduledFor, when)) ? `, its time now ${when}` : ''}: it is not scheduled now.`)
1432
- } else if (moved) {
1433
- say.warn(`Post ${id}'s time is ${when} now, and it is not scheduled.`)
1434
- }
1565
+ // The file's changes stay written, and a write makes a scheduled post a draft again.
1566
+ if (scheduledFor && writes) say.warn(`Post ${id} was scheduled for ${scheduledFor}, and writing what ${arg} says made it a draft again: it is not scheduled now.`)
1435
1567
  return { exitCode: 1 }
1436
1568
  }
1437
1569
  const delivery = (await res.json().catch(() => null))?.delivery ?? null
1570
+ if (moving) {
1571
+ post.data = { ...post.data, send_at: when }
1572
+ // The file says the post's new time, at the version the schedule left, so its next run is not stale.
1573
+ if (file) {
1574
+ const after = await readIndex(client, site).catch(() => null)
1575
+ const item = after?.byUuid.get(post.uuid)
1576
+ const text = readFileSync(file.path, 'utf8')
1577
+ const next = item ? fileWithFields(text, file.format, { send_at: when, version: versionOf(after, item) }) : null
1578
+ if (next && next !== text) writeFileSync(file.path, next)
1579
+ else if (!next && !json) say.warn(`Could not write its new time into ${arg}: run \`uniweb promote show ${id} > ${arg}\` before you edit it again.`)
1580
+ }
1581
+ }
1438
1582
  if (json) return out(delivery, delivery?.status === 'failed' || delivery?.status === 'refused' ? 1 : 0)
1439
1583
  return { exitCode: sayDelivery(index, post, delivery, id) }
1440
1584
  }
@@ -1667,6 +1811,7 @@ export async function promote(args = []) {
1667
1811
  if (sub === 'status') return await status(args)
1668
1812
  if (sub === 'check') return await check(args)
1669
1813
  if (sub === 'connect') return await connectNetwork(args)
1814
+ if (sub === 'use') return await useAccount(args)
1670
1815
  if (sub === 'post' || sub === 'campaign') return await writeDraft(args, sub)
1671
1816
  if (sub === 'show') return await show(args)
1672
1817
  if (sub === 'delete') return await deleteItem(args)
@@ -108,7 +108,7 @@ import { resolveWorkspace, scopeOfWorkspace, topOfChildHandle, SOURCE_LABEL } fr
108
108
  import { writeJsonPreservingStyleAsync } from '../utils/json-file.js'
109
109
  import { newerInput } from '../utils/foundation-freshness.js'
110
110
  import { unregisteredLocalTypes } from '../backend/unregistered-types.js'
111
- import { typesFromLibraries } from '../backend/library-types.js'
111
+ import { typesFromLibraries, typesNamedBy } from '../backend/library-types.js'
112
112
  import {
113
113
  findWorkspaceRoot,
114
114
  findFoundations,
@@ -352,16 +352,6 @@ async function uploadVendorFiles(entities, files, { client }) {
352
352
  return true
353
353
  }
354
354
 
355
- /** A mapping's reverse `follow` lines' `model`s, as written. */
356
- function followModelsOf(decl) {
357
- const out = []
358
- for (const line of Array.isArray(decl?.follow) ? decl.follow : []) {
359
- if (!line || typeof line !== 'object') continue
360
- for (const spec of Object.values(line)) if (spec && typeof spec.model === 'string') out.push(spec.model)
361
- }
362
- return out
363
- }
364
-
365
355
  /**
366
356
  * Register the data schemas a library defines, before the foundation that names them
367
357
  * (`backend/library-types.js`): the library's package whole, as `uniweb register` there sends it.
@@ -394,7 +384,7 @@ async function registerLibraryTypes(lib, { client, exporter, at, upload = true }
394
384
  // of this library they name: a registry takes a mapping only after what it names.
395
385
  const mappings = await libraryMappingsWanted(lib, own)
396
386
  for (const decl of Object.values(mappings)) {
397
- for (const ref of [decl.model, ...followModelsOf(decl)]) {
387
+ for (const ref of typesNamedBy(decl)) {
398
388
  const local = typeof ref === 'string' ? own(ref) : null
399
389
  if (local && all[local]) wanted.add(local)
400
390
  }
@@ -869,7 +869,8 @@ async function appChecks(siteDir, siteYml, { offline, args, git }) {
869
869
  * @param {Response|null} res - the promotion read, made beside the site's other reads
870
870
  */
871
871
  async function promoteChecks(client, uuid, res, { now = Date.now() } = {}) {
872
- if (!res || res.status === 404) return { checks: [], proposals: [] }
872
+ // A 403 is someone who can only view the site: Promote is shown to those who can edit it.
873
+ if (!res || res.status === 404 || res.status === 403) return { checks: [], proposals: [] }
873
874
  if (!res.ok) {
874
875
  return { checks: [{ id: 'promote.site', state: 'unknown', summary: `Could not read the site's Promote: HTTP ${res.status}.` }], proposals: [] }
875
876
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-16T19:23:17.851Z",
3
+ "generatedAt": "2026-11-17T05:37:54.819Z",
4
4
  "packages": {
5
5
  "@uniweb/api": {
6
- "version": "1.7.1"
6
+ "version": "1.7.3"
7
7
  },
8
8
  "@uniweb/build": {
9
- "version": "1.24.0"
9
+ "version": "1.24.2"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.11"
@@ -114,9 +114,11 @@ const VERBS = {
114
114
  /**
115
115
  * `promote <command>` — a site's Promote. `--json` is every command's porcelain; `--site` names
116
116
  * a site this project isn't synced to; `--at` and `--now` are `send`'s time; `--yes` is what
117
- * `start` and `resume` take in place of their question; the workspace is `--org` / `--personal`.
117
+ * `start` and `resume` take in place of their question; `--connection` and `--target` are what
118
+ * `use` chooses; `--from` and `--to` are the days `results` reads; the workspace is `--org` /
119
+ * `--personal`.
118
120
  */
119
- promote: ['--json', '--site', '--at', '--now', '--yes', '--org', '--personal'],
121
+ promote: ['--json', '--site', '--at', '--now', '--yes', '--connection', '--target', '--from', '--to', '--org', '--personal'],
120
122
  status: [
121
123
  '--json', '--offline', '--dry-run',
122
124
  '--force', '--no-verify', '--no-validate', '--yes', '--org', '--personal',