uniweb 1.34.12 → 1.35.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/package.json +5 -5
- package/partials/agents.md +2 -1
- package/partials/guides/index.json +5 -0
- package/partials/guides/promote.md +144 -0
- package/src/backend/client.js +140 -7
- package/src/backend/promote-drafts.js +1032 -0
- package/src/backend/site-sync.js +2 -1
- package/src/commands/doctor.js +21 -5
- package/src/commands/promote.js +1690 -0
- package/src/commands/pull.js +120 -7
- package/src/commands/site.js +1 -1
- package/src/commands/status.js +169 -2
- package/src/framework-index.json +3 -3
- package/src/index.js +12 -1
- package/src/utils/flag-guard.js +6 -0
- package/src/utils/status-next.js +2 -2
package/src/commands/pull.js
CHANGED
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
* uniweb pull --no-records Pull pages only; skip the folder (records) lane
|
|
48
48
|
* uniweb pull --no-delete Keep files with no backend item
|
|
49
49
|
* uniweb pull --force Take the backend's version, discarding local changes
|
|
50
|
-
* uniweb pull --dry-run
|
|
50
|
+
* uniweb pull --dry-run In git, name each file it would change (a YAML file's keys
|
|
51
|
+
* too, and whether this copy changed it too); write nothing
|
|
51
52
|
*
|
|
52
53
|
* The content + folder pull lanes are both keyed by the site's uuid on that backend
|
|
53
54
|
* (sync.json).
|
|
@@ -167,11 +168,13 @@ const colors = {
|
|
|
167
168
|
blue: '\x1b[36m'
|
|
168
169
|
}
|
|
169
170
|
// Looked up at each call, so a caller that captures the console captures these too — and
|
|
170
|
-
// silent while a probe runs (`probePull`), which answers by what it returns.
|
|
171
|
+
// silent while a probe runs (`probePull`), which answers by what it returns. What it would
|
|
172
|
+
// have said went wrong is kept (`quietErrors`), so a dry run whose probe stopped can say why.
|
|
171
173
|
let quiet = false
|
|
174
|
+
let quietErrors = []
|
|
172
175
|
const log = (...a) => quiet || console.log(...a)
|
|
173
176
|
const success = (m) => log(`${colors.green}✓${colors.reset} ${m}`)
|
|
174
|
-
const error = (m) => quiet
|
|
177
|
+
const error = (m) => (quiet ? quietErrors.push(m) : console.error(`${colors.red}✗${colors.reset} ${m}`))
|
|
175
178
|
const info = (m) => log(`${colors.blue}→${colors.reset} ${m}`)
|
|
176
179
|
const note = (m) => log(` ${colors.dim}${m}${colors.reset}`)
|
|
177
180
|
|
|
@@ -764,12 +767,94 @@ const takenFrom = (origin) => `Take the site's content from ${origin}`
|
|
|
764
767
|
* `files` — `[status, path]`, status `A`, `M` or `D`, the path relative to the site
|
|
765
768
|
*/
|
|
766
769
|
export async function probePull(args = [], deps = {}) {
|
|
770
|
+
return (await probeWithReason(args, deps)).probe
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/** `probePull`, and when it does not answer, the last thing the pull would have said went wrong. */
|
|
774
|
+
async function probeWithReason(args, deps) {
|
|
767
775
|
quiet = true
|
|
776
|
+
quietErrors = []
|
|
768
777
|
try {
|
|
769
|
-
|
|
778
|
+
const probe = (await pull(args, { ...deps, probe: true }))?.probe ?? null
|
|
779
|
+
return { probe, reason: probe ? null : quietErrors.at(-1) ?? null }
|
|
770
780
|
} finally {
|
|
771
781
|
quiet = false
|
|
782
|
+
quietErrors = []
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* In each YAML file a pull would change (`M`, in the site), the keys whose values it changes, read as
|
|
788
|
+
* values: a key in a map the pull changes is named by its path (`services.search`), to three levels,
|
|
789
|
+
* and a list as a whole. A file whose values are all the same is named with none.
|
|
790
|
+
*
|
|
791
|
+
* @param {Array<[string, string]>} files - the stand-in's `changes()`
|
|
792
|
+
* @param {{ repo: object, rev: string, siteDir: string }} at - the commit the stand-in holds, and its site
|
|
793
|
+
* @returns {Record<string, string[]>} path → the keys, for each file that has any
|
|
794
|
+
*/
|
|
795
|
+
function yamlKeysChanged(files, { repo, rev, siteDir }) {
|
|
796
|
+
const out = {}
|
|
797
|
+
for (const [status, path] of files) {
|
|
798
|
+
if (status !== 'M' || !/\.ya?ml$/i.test(path) || path.startsWith('..')) continue
|
|
799
|
+
try {
|
|
800
|
+
const was = yaml.load(fileAt(repo, rev, path)?.toString('utf8') ?? '') ?? {}
|
|
801
|
+
const now = yaml.load(readFileSync(join(siteDir, path), 'utf8')) ?? {}
|
|
802
|
+
const keys = changedKeys(was, now)
|
|
803
|
+
if (keys.length) out[path] = keys
|
|
804
|
+
} catch {
|
|
805
|
+
// A file that does not read is named with no keys.
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
return out
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Of the files a pull would change, those this copy's commits changed too since `rev`, the sync point
|
|
813
|
+
* the pull merges from: the pull merges each with the backend's, where a dry run could not show the result.
|
|
814
|
+
* A file outside the site (a mounted folder's, `..`) is left out, as `yamlKeysChanged` leaves it.
|
|
815
|
+
*
|
|
816
|
+
* @param {object} repo
|
|
817
|
+
* @param {string} rev - the sync point
|
|
818
|
+
* @param {Array<[string, string]>} files - the stand-in's `changes()`
|
|
819
|
+
* @returns {string[]} their paths, relative to the site
|
|
820
|
+
*/
|
|
821
|
+
function changedSince(repo, rev, files) {
|
|
822
|
+
const same = (a, b) => (a === null || b === null ? a === b : a.equals(b))
|
|
823
|
+
return files.filter(([, path]) => !path.startsWith('..') && !same(fileAt(repo, rev, path), fileAt(repo, repo.head, path))).map(([, path]) => path)
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function changedKeys(was, now, at = '', depth = 0) {
|
|
827
|
+
const plainMap = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
828
|
+
if (!plainMap(was) || !plainMap(now)) return JSON.stringify(was) === JSON.stringify(now) ? [] : [at || '(the whole file)']
|
|
829
|
+
const out = []
|
|
830
|
+
for (const key of new Set([...Object.keys(was), ...Object.keys(now)])) {
|
|
831
|
+
const a = was[key]
|
|
832
|
+
const b = now[key]
|
|
833
|
+
if (JSON.stringify(sortedDeep(a)) === JSON.stringify(sortedDeep(b))) continue
|
|
834
|
+
const path = at ? `${at}.${key}` : key
|
|
835
|
+
if (depth < 2 && plainMap(a) && plainMap(b)) out.push(...changedKeys(a, b, path, depth + 1))
|
|
836
|
+
else out.push(path)
|
|
837
|
+
}
|
|
838
|
+
return out
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** A dry run's account of the pull it stands for (`probePull`). */
|
|
842
|
+
function printPreview({ files, keys = {}, changedHereToo = [], noBase, recordsNotPlaced, itemsBehind = 0, mountedMoved = [], held = [] }, origin) {
|
|
843
|
+
const from = `${colors.dim}${origin}${colors.reset}`
|
|
844
|
+
if (!files.length) {
|
|
845
|
+
info(`Dry run — a pull from ${from} would change no file.`)
|
|
846
|
+
if (itemsBehind || mountedMoved.length || held.length) note('The backend moved with no file here to show it; the pull would record that (`uniweb status` says what moved).')
|
|
847
|
+
return
|
|
848
|
+
}
|
|
849
|
+
info(`Dry run — a pull from ${from} would change ${files.length === 1 ? '1 file' : `${files.length} files`}:`)
|
|
850
|
+
const both = new Set(changedHereToo)
|
|
851
|
+
for (const [status, path] of files) {
|
|
852
|
+
const what = status === 'A' ? ' (new)' : status === 'D' ? ' (removed)' : ''
|
|
853
|
+
note(`${path}${what}${keys[path] ? ` — ${keys[path].join(', ')}` : ''}${both.has(path) ? ' (changed here too: the pull merges the two)' : ''}`)
|
|
772
854
|
}
|
|
855
|
+
if (both.size) note('A file changed in both places is merged, and the pull stops on any part changed both ways, for you to settle.')
|
|
856
|
+
if (noBase) note('This copy has no sync point with the site, so these are the files that differ, either way.')
|
|
857
|
+
if (recordsNotPlaced) note('Some records could not be placed in files; the pull says which, and why.')
|
|
773
858
|
}
|
|
774
859
|
|
|
775
860
|
export async function pull(args = [], deps = {}) {
|
|
@@ -831,8 +916,8 @@ export async function pull(args = [], deps = {}) {
|
|
|
831
916
|
// anything is asked or taken, as it stops the build.
|
|
832
917
|
const mounts = writableMounts(siteDir)
|
|
833
918
|
if (mounts.refused.length) {
|
|
834
|
-
if (probe) return { exitCode: 1, probe: null }
|
|
835
919
|
error(`${mounts.refused.length === 1 ? 'A mount is' : `${mounts.refused.length} mounts are`} written in a form a pull no longer reads:`)
|
|
920
|
+
if (probe) return { exitCode: 1, probe: null }
|
|
836
921
|
for (const m of mounts.refused) for (const line of refusedMountLines(m)) note(line)
|
|
837
922
|
return { exitCode: 1 }
|
|
838
923
|
}
|
|
@@ -920,6 +1005,23 @@ export async function pull(args = [], deps = {}) {
|
|
|
920
1005
|
}
|
|
921
1006
|
|
|
922
1007
|
if (dryRun) {
|
|
1008
|
+
// ⭐ IN A REPOSITORY A DRY RUN IS THE PULL ITSELF, STOPPED BEFORE IT TAKES ANYTHING (`probePull`), as
|
|
1009
|
+
// `uniweb status` asks it: each file it would change, and in a YAML file the keys. ⛔ Until 2026-11-16
|
|
1010
|
+
// it said only "would pull content", and a pull that rewrote a whole `site.yml` to change its favicon
|
|
1011
|
+
// gave no sign of it beforehand (measured on a site, 2026-11-16).
|
|
1012
|
+
if (repo?.head && !probe) {
|
|
1013
|
+
const { probe: preview, reason } = await probeWithReason(args.filter((a) => a !== '--dry-run'), deps)
|
|
1014
|
+
if (preview) {
|
|
1015
|
+
printPreview(preview, client.origin)
|
|
1016
|
+
return { exitCode: 0 }
|
|
1017
|
+
}
|
|
1018
|
+
// ⛔ Not the lines below, which say only what a pull fetches: a preview that stopped is no
|
|
1019
|
+
// answer, and until 2026-11-16 "would pull content" stood in for one (a clone whose videos
|
|
1020
|
+
// git could not fetch, measured that day).
|
|
1021
|
+
error(`Dry run — could not tell what a pull from ${client.origin} would change, so nothing was pulled.`)
|
|
1022
|
+
if (reason) for (const line of String(reason).split('\n').map((l) => l.trim()).filter(Boolean).slice(0, 12)) note(line)
|
|
1023
|
+
return { exitCode: 1 }
|
|
1024
|
+
}
|
|
923
1025
|
info(
|
|
924
1026
|
`Dry run — would pull content from ${colors.dim}${client.origin}${colors.reset}`
|
|
925
1027
|
)
|
|
@@ -1083,7 +1185,11 @@ export async function pull(args = [], deps = {}) {
|
|
|
1083
1185
|
if (probe) {
|
|
1084
1186
|
// A lane that did not answer is not knowing — a records lane the backend has none of
|
|
1085
1187
|
// (404) is no records; both unchanged is nothing to take.
|
|
1086
|
-
if (!content || (!noRecords && !folderLane && !missing.has('records')))
|
|
1188
|
+
if (!content || (!noRecords && !folderLane && !missing.has('records'))) {
|
|
1189
|
+
// A lane that failed said why (`getDocs`); a site the backend answers 404 for only noted it.
|
|
1190
|
+
if (missing.has('content')) error(`${client.origin} has no such site — it was deleted there, or you lack access.`)
|
|
1191
|
+
return { exitCode: 1, probe: null }
|
|
1192
|
+
}
|
|
1087
1193
|
if (!projected) return { exitCode: 0, probe: { files: [], recordsNotPlaced: false } }
|
|
1088
1194
|
}
|
|
1089
1195
|
|
|
@@ -1461,10 +1567,17 @@ export async function pull(args = [], deps = {}) {
|
|
|
1461
1567
|
// another copy these files already hold; either way a push from here may be refused.
|
|
1462
1568
|
const seen = readItemBaseVersions(siteDir, client.origin)
|
|
1463
1569
|
const itemsBehind = Object.entries(content?.itemVersions || {}).filter(([uuid, v]) => seen[uuid] && seen[uuid] !== v).length
|
|
1570
|
+
const files = standIn.changes()
|
|
1464
1571
|
return {
|
|
1465
1572
|
exitCode: 0,
|
|
1466
1573
|
probe: {
|
|
1467
|
-
files
|
|
1574
|
+
files,
|
|
1575
|
+
// In a YAML file the pull would change, the keys whose values it changes (`changedKeys`).
|
|
1576
|
+
keys: yamlKeysChanged(files, { repo, rev: onto, siteDir: standIn.siteDir }),
|
|
1577
|
+
// Of those, the files this copy changed too since the sync point: the pull merges the two, and
|
|
1578
|
+
// stops on a part changed both ways. ⛔ Until 2026-11-16 a dry run named such a file as one the
|
|
1579
|
+
// pull "would change", and the pull then stopped on it (measured that day on a site's copy).
|
|
1580
|
+
changedHereToo: base ? changedSince(repo, onto, files) : [],
|
|
1468
1581
|
itemsBehind,
|
|
1469
1582
|
// By route: the mounted pages the backend moved, which the next push puts back, and the pages
|
|
1470
1583
|
// held because their files cannot say what the app made of them.
|
package/src/commands/site.js
CHANGED
|
@@ -95,7 +95,7 @@ function positionals(args) {
|
|
|
95
95
|
* workspace's only site. ⛔ Never a stop: outside a project — or from an install without
|
|
96
96
|
* `@uniweb/build`, which finding a workspace's sites may load — there is simply none.
|
|
97
97
|
*/
|
|
98
|
-
async function projectSiteDir() {
|
|
98
|
+
export async function projectSiteDir() {
|
|
99
99
|
try {
|
|
100
100
|
const cwd = process.cwd()
|
|
101
101
|
if (existsSync(join(cwd, 'site.yml'))) return { dir: cwd }
|
package/src/commands/status.js
CHANGED
|
@@ -92,6 +92,16 @@ import { siteAround } from '../utils/pick-site.js'
|
|
|
92
92
|
import { getCliVersion } from '../versions.js'
|
|
93
93
|
import { planNext } from '../utils/status-next.js'
|
|
94
94
|
import { AD_PLATFORMS } from '../backend/ad-platforms.js'
|
|
95
|
+
import {
|
|
96
|
+
campaignDeliveries,
|
|
97
|
+
connectionOf,
|
|
98
|
+
deliveryOf,
|
|
99
|
+
indexPromotion,
|
|
100
|
+
reasonWords,
|
|
101
|
+
shortIds,
|
|
102
|
+
stateCounts,
|
|
103
|
+
whyNot
|
|
104
|
+
} from '../backend/promote-drafts.js'
|
|
95
105
|
|
|
96
106
|
const c = {
|
|
97
107
|
reset: '\x1b[0m',
|
|
@@ -739,10 +749,11 @@ async function appChecks(siteDir, siteYml, { offline, args, git }) {
|
|
|
739
749
|
}
|
|
740
750
|
return readAppChanges({ client, siteDir, siteUuid: uuid })
|
|
741
751
|
}
|
|
742
|
-
const [state, changes, foundation] = await Promise.all([
|
|
752
|
+
const [state, changes, foundation, promotion] = await Promise.all([
|
|
743
753
|
uuid ? client.siteState(uuid) : null,
|
|
744
754
|
uuid ? readChanges().catch((err) => ({ error: err })) : null,
|
|
745
|
-
foundationCheck(siteDir, siteYml, client).catch(() => null)
|
|
755
|
+
foundationCheck(siteDir, siteYml, client).catch(() => null),
|
|
756
|
+
uuid ? client.readPromotion(uuid).catch(() => null) : null
|
|
746
757
|
])
|
|
747
758
|
|
|
748
759
|
if (state) {
|
|
@@ -836,9 +847,164 @@ async function appChecks(siteDir, siteYml, { offline, args, git }) {
|
|
|
836
847
|
}
|
|
837
848
|
}
|
|
838
849
|
if (foundation) checks.push(foundation)
|
|
850
|
+
if (site && !elsewhere) {
|
|
851
|
+
const promote = await promoteChecks(client, uuid, promotion)
|
|
852
|
+
checks.push(...promote.checks)
|
|
853
|
+
proposals.push(...promote.proposals)
|
|
854
|
+
}
|
|
839
855
|
return { checks, proposals, backend, site: site ?? null }
|
|
840
856
|
}
|
|
841
857
|
|
|
858
|
+
/**
|
|
859
|
+
* `promote.*` — the site's Promote, once the site has used it: what only the person can do (an
|
|
860
|
+
* account to reconnect or hand on, Promote to turn on where its ads were paused), the steps that
|
|
861
|
+
* get it found, the posts that failed and the ones going out this week, and what each running
|
|
862
|
+
* campaign spent. `uniweb promote status` says the rest.
|
|
863
|
+
*
|
|
864
|
+
* Nothing is said for a backend that has no Promote, or a site that never used it; a read that
|
|
865
|
+
* failed otherwise is `unknown`.
|
|
866
|
+
*
|
|
867
|
+
* @param {object} client
|
|
868
|
+
* @param {string} uuid - the site
|
|
869
|
+
* @param {Response|null} res - the promotion read, made beside the site's other reads
|
|
870
|
+
*/
|
|
871
|
+
async function promoteChecks(client, uuid, res, { now = Date.now() } = {}) {
|
|
872
|
+
if (!res || res.status === 404) return { checks: [], proposals: [] }
|
|
873
|
+
if (!res.ok) {
|
|
874
|
+
return { checks: [{ id: 'promote.site', state: 'unknown', summary: `Could not read the site's Promote: HTTP ${res.status}.` }], proposals: [] }
|
|
875
|
+
}
|
|
876
|
+
const promotion = (await res.json().catch(() => null))?.promotion ?? null
|
|
877
|
+
if (!promotion) return { checks: [], proposals: [] }
|
|
878
|
+
const index = indexPromotion(promotion)
|
|
879
|
+
const ids = shortIds(index.items.map((i) => i.uuid))
|
|
880
|
+
const checks = []
|
|
881
|
+
const proposals = []
|
|
882
|
+
|
|
883
|
+
// ── Getting found: each step's reading ──
|
|
884
|
+
const steps = index.top('getting_found').filter((s) => s.data?.skipped !== true)
|
|
885
|
+
if (steps.length) {
|
|
886
|
+
const reading = (s) => index.child('getting_found/reading', s.uuid)?.data ?? null
|
|
887
|
+
const todo = steps.filter((s) => reading(s)?.state !== 'done')
|
|
888
|
+
checks.push({
|
|
889
|
+
id: 'promote.found',
|
|
890
|
+
state: todo.length ? 'attention' : 'ok',
|
|
891
|
+
summary: todo.length
|
|
892
|
+
? `Getting found: ${todo.map((s) => `${s.data?.step} ${{ todo: 'to do' }[reading(s)?.state] ?? reading(s)?.state ?? 'not checked'}`).join(', ')}.`
|
|
893
|
+
: `Getting found: ${steps.map((s) => s.data?.step).join(', ')} done.`,
|
|
894
|
+
lines: todo.length ? ['`npx uniweb promote check <step>` checks one again.'] : [],
|
|
895
|
+
detail: { steps: steps.map((s) => ({ step: s.data?.step ?? null, reading: reading(s) })) }
|
|
896
|
+
})
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// ── The accounts it goes out through: the person's to reconnect or hand on ──
|
|
900
|
+
const accounts = index.top('networks').map((n) => ({ network: n.data?.network, use: n.data?.use, ...connectionOf(n.data?.connection) }))
|
|
901
|
+
const stuck = accounts.filter((a) => a.state === 'needs_reconnect' || a.state === 'stopped')
|
|
902
|
+
if (accounts.length) {
|
|
903
|
+
checks.push({
|
|
904
|
+
id: 'promote.accounts',
|
|
905
|
+
state: stuck.length ? 'attention' : 'ok',
|
|
906
|
+
summary: stuck.length
|
|
907
|
+
? `${count(stuck.length, 'account')} the site goes out through ${stuck.length === 1 ? 'needs' : 'need'} its person.`
|
|
908
|
+
: `Goes out through ${accounts.map((a) => `${a.network} (${a.use})`).join(', ')}.`,
|
|
909
|
+
lines: stuck.map((a) => `${a.network} “${a.name ?? a.handle ?? a.uuid}”: ${a.state === 'stopped' ? 'stopped — its person left; an admin hands it on' : 'needs reconnecting'}`),
|
|
910
|
+
detail: { accounts }
|
|
911
|
+
})
|
|
912
|
+
for (const a of stuck) {
|
|
913
|
+
proposals.push({
|
|
914
|
+
step: 'promote',
|
|
915
|
+
command: null,
|
|
916
|
+
why: a.state === 'stopped'
|
|
917
|
+
? `the ${a.network} account “${a.name ?? a.handle ?? a.uuid}” stopped when its person left: an admin of the workspace hands it on, in the app`
|
|
918
|
+
: `the ${a.network} account “${a.name ?? a.handle ?? a.uuid}” needs reconnecting: its person does it, in the app`,
|
|
919
|
+
ask: true
|
|
920
|
+
})
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// ── Posts: what failed, and what goes out this week ──
|
|
925
|
+
const posts = index.top('posts').map((p) => ({ item: p, delivery: deliveryOf(index, p) }))
|
|
926
|
+
if (posts.length) {
|
|
927
|
+
const weekAhead = now + 7 * 86400000
|
|
928
|
+
const failed = posts.filter((p) => p.delivery?.status === 'failed' || p.delivery?.status === 'refused')
|
|
929
|
+
const soon = posts
|
|
930
|
+
.filter((p) => p.delivery?.status === 'scheduled' && Date.parse(p.item.data?.send_at) <= weekAhead)
|
|
931
|
+
.sort((a, b) => Date.parse(a.item.data?.send_at) - Date.parse(b.item.data?.send_at))
|
|
932
|
+
const network = (p) => index.byUuid.get(p.item.data?.via)?.data?.network ?? 'its network'
|
|
933
|
+
// Every state the posts are in, a network's review included, so no post goes uncounted.
|
|
934
|
+
const tally = stateCounts(posts.map((p) => p.delivery?.status)).map(([state, n]) => `${n} ${state}`)
|
|
935
|
+
checks.push({
|
|
936
|
+
id: 'promote.posts',
|
|
937
|
+
state: failed.length ? 'attention' : 'ok',
|
|
938
|
+
summary: `Posts: ${tally.join(' · ')}.`,
|
|
939
|
+
lines: [
|
|
940
|
+
...failed.map((p) => `${ids.get(p.item.uuid)} ${p.delivery.status} on ${network(p)}: ${whyNot(p.delivery) ?? 'no reason given'}`),
|
|
941
|
+
...soon.map((p) => `${ids.get(p.item.uuid)} goes out on ${network(p)} at ${p.item.data.send_at}`)
|
|
942
|
+
],
|
|
943
|
+
detail: {
|
|
944
|
+
failed: failed.map((p) => ({ id: p.item.uuid, reason: p.delivery.reason ?? null })),
|
|
945
|
+
scheduled: soon.map((p) => ({ id: p.item.uuid, send_at: p.item.data.send_at }))
|
|
946
|
+
}
|
|
947
|
+
})
|
|
948
|
+
if (failed.some((p) => p.delivery?.reason === 'promote_off')) {
|
|
949
|
+
proposals.push({ step: 'promote', command: null, why: 'a scheduled post failed because the site has no Promote: it comes with the site\'s Analytics, which the person turns on in the app', ask: true })
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// ── Campaigns: what runs, and what it spent ──
|
|
954
|
+
const campaigns = index.top('campaigns').map((x) => ({ item: x, deliveries: campaignDeliveries(index, x) }))
|
|
955
|
+
if (campaigns.length) {
|
|
956
|
+
const running = campaigns.filter((x) => x.deliveries.some((d) => d.status === 'active'))
|
|
957
|
+
const spent = await Promise.all(
|
|
958
|
+
running.map(async (x) => {
|
|
959
|
+
const r = await client.campaignSpend(uuid, x.item.uuid).catch(() => null)
|
|
960
|
+
return r?.ok ? ((await r.json().catch(() => null))?.spend ?? null) : null
|
|
961
|
+
})
|
|
962
|
+
)
|
|
963
|
+
const offPaused = campaigns.some((x) => x.deliveries.some((d) => d.status === 'paused' && d.reason === 'promote_off'))
|
|
964
|
+
const attention = campaigns.filter((x) => x.deliveries.some((d) => d.status === 'attention'))
|
|
965
|
+
const lines = running.map((x, i) => `“${x.item.data?.name ?? ids.get(x.item.uuid)}” running — ${spendWords(spent[i])}`)
|
|
966
|
+
for (const x of attention) {
|
|
967
|
+
for (const d of x.deliveries.filter((d) => d.status === 'attention')) {
|
|
968
|
+
lines.push(`“${x.item.data?.name ?? ids.get(x.item.uuid)}” waits in an ad account: ${reasonWords(d.reason)}${d.detail ? ` — ${d.detail}` : ''}`)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (offPaused) lines.push('Its ads were paused because the site has no Promote.')
|
|
972
|
+
checks.push({
|
|
973
|
+
id: 'promote.campaigns',
|
|
974
|
+
state: attention.length || offPaused ? 'attention' : 'ok',
|
|
975
|
+
summary: `Campaigns: ${running.length} running, ${campaigns.length - running.length} not.`,
|
|
976
|
+
lines,
|
|
977
|
+
detail: {
|
|
978
|
+
running: running.map((x, i) => ({ id: x.item.uuid, name: x.item.data?.name ?? null, spend: spent[i] }))
|
|
979
|
+
}
|
|
980
|
+
})
|
|
981
|
+
if (offPaused) {
|
|
982
|
+
proposals.push({ step: 'promote', command: null, why: 'the site\'s ads were paused because it has no Promote: it comes with the site\'s Analytics, which the person turns on in the app', ask: true })
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return { checks, proposals }
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* What a campaign spent, from the days the network last reported: the latest day and the one
|
|
990
|
+
* before it, each per currency. A day not reported is unknown, never zero.
|
|
991
|
+
*/
|
|
992
|
+
function spendWords(rows) {
|
|
993
|
+
if (!Array.isArray(rows) || !rows.length) return 'no spend reported yet'
|
|
994
|
+
const days = [...new Set(rows.map((r) => r.day).filter(Boolean))].sort()
|
|
995
|
+
const on = (day) => {
|
|
996
|
+
const cents = {}
|
|
997
|
+
for (const r of rows.filter((x) => x.day === day)) {
|
|
998
|
+
const n = Math.round(Number(r.amount) * 100)
|
|
999
|
+
if (r.currency && Number.isFinite(n)) cents[r.currency] = (cents[r.currency] ?? 0) + n
|
|
1000
|
+
}
|
|
1001
|
+
return Object.entries(cents).map(([cur, n]) => `${(n / 100).toFixed(2)} ${cur}`).join(' + ') || 'unknown'
|
|
1002
|
+
}
|
|
1003
|
+
const last = days[days.length - 1]
|
|
1004
|
+
const before = days[days.length - 2]
|
|
1005
|
+
return before ? `${on(before)} on ${before}, ${on(last)} on ${last} so far` : `${on(last)} on ${last}`
|
|
1006
|
+
}
|
|
1007
|
+
|
|
842
1008
|
/** The name a backend's hosting goes by: Uniweb Cloud on the default backend, its origin elsewhere. */
|
|
843
1009
|
const cloudName = (origin) => (origin === DEFAULT_BACKEND_ORIGIN ? 'Uniweb Cloud' : origin)
|
|
844
1010
|
|
|
@@ -1710,6 +1876,7 @@ const GROUPS = [
|
|
|
1710
1876
|
['git', 'Git'],
|
|
1711
1877
|
['app', 'App'],
|
|
1712
1878
|
['hosting', 'Hosting'],
|
|
1879
|
+
['promote', 'Promote'],
|
|
1713
1880
|
['uniweb', 'Uniweb'],
|
|
1714
1881
|
['health', 'Health'],
|
|
1715
1882
|
['dev', 'Dev server']
|
package/src/framework-index.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-16T19:23:17.851Z",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@uniweb/api": {
|
|
6
6
|
"version": "1.7.1"
|
|
7
7
|
},
|
|
8
8
|
"@uniweb/build": {
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.24.0"
|
|
10
10
|
},
|
|
11
11
|
"@uniweb/content-reader": {
|
|
12
12
|
"version": "1.5.11"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"version": "1.3.2"
|
|
61
61
|
},
|
|
62
62
|
"@uniweb/unipress": {
|
|
63
|
-
"version": "1.1.
|
|
63
|
+
"version": "1.1.41"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"templates": {
|
package/src/index.js
CHANGED
|
@@ -1059,6 +1059,14 @@ async function main() {
|
|
|
1059
1059
|
await exitWhenDrained(result?.exitCode ?? 0)
|
|
1060
1060
|
}
|
|
1061
1061
|
|
|
1062
|
+
// Handle promote command — a site's Promote: getting found, networks, posts, campaigns.
|
|
1063
|
+
// Runs anywhere: inside a project it acts on the site the project is synced to.
|
|
1064
|
+
if (command === 'promote') {
|
|
1065
|
+
const { promote } = await import('./commands/promote.js')
|
|
1066
|
+
const result = await promote(args.slice(1))
|
|
1067
|
+
await exitWhenDrained(result?.exitCode ?? 0)
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1062
1070
|
// Handle org command (new-backend orgs/units — publish-scope management)
|
|
1063
1071
|
if (command === 'org') {
|
|
1064
1072
|
const { org } = await import('./commands/org.js')
|
|
@@ -2136,7 +2144,9 @@ Outside a repository there is nothing to merge against: the files are rewritten
|
|
|
2136
2144
|
what the backend holds, after asking if any of them are yours.
|
|
2137
2145
|
|
|
2138
2146
|
${colors.bright}Options:${colors.reset}
|
|
2139
|
-
--dry-run
|
|
2147
|
+
--dry-run Name each file it would change, and in a YAML file the keys, and
|
|
2148
|
+
mark those changed here too, which it merges; write nothing
|
|
2149
|
+
(outside a repository: what it would fetch)
|
|
2140
2150
|
--force Take the backend's version, discarding local changes
|
|
2141
2151
|
--no-records Pull pages only; skip records
|
|
2142
2152
|
--no-assets Don't download media; the content keeps its URLs
|
|
@@ -2499,6 +2509,7 @@ ${colors.bright}Commands:${colors.reset}
|
|
|
2499
2509
|
status What changed in the app, in git and in Uniweb — and what to run
|
|
2500
2510
|
forget Forget a backend, or --all to make a copied project a new one
|
|
2501
2511
|
site <cmd> The sites in a workspace: list, unpublish, delete
|
|
2512
|
+
promote <cmd> A site's Promote: its posts and ads, getting found, and the accounts
|
|
2502
2513
|
org <cmd> The organizations you belong to: list, create
|
|
2503
2514
|
inspect <path> Inspect parsed content shape of a markdown file or folder
|
|
2504
2515
|
docs Generate component documentation
|
package/src/utils/flag-guard.js
CHANGED
|
@@ -111,6 +111,12 @@ const VERBS = {
|
|
|
111
111
|
* `--org` / `--personal`.
|
|
112
112
|
*/
|
|
113
113
|
site: ['--json', '--yes', '--clear', '--org', '--personal'],
|
|
114
|
+
/**
|
|
115
|
+
* `promote <command>` — a site's Promote. `--json` is every command's porcelain; `--site` names
|
|
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`.
|
|
118
|
+
*/
|
|
119
|
+
promote: ['--json', '--site', '--at', '--now', '--yes', '--org', '--personal'],
|
|
114
120
|
status: [
|
|
115
121
|
'--json', '--offline', '--dry-run',
|
|
116
122
|
'--force', '--no-verify', '--no-validate', '--yes', '--org', '--personal',
|
package/src/utils/status-next.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* sign in → settle conflicts → finish a merge → take what others did (refresh, or pull)
|
|
10
10
|
* → commit what else changed → push → push to git → go live → deploy to another host
|
|
11
|
-
* → update Uniweb → read doctor's findings
|
|
11
|
+
* → update Uniweb → read doctor's findings → what Promote needs of the person
|
|
12
12
|
*
|
|
13
13
|
* A commit of the project's other files needs nothing above it — refresh's `git pull` keeps
|
|
14
14
|
* uncommitted work (`--autostash`, `utils/git.js::pullRemote`) — and comes before the push,
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* already does, and drops duplicates.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
const ORDER = ['login', 'conflicts', 'merge', 'refresh', 'pull', 'commit', 'push', 'gitpush', 'publish', 'deploy', 'update', 'doctor']
|
|
22
|
+
const ORDER = ['login', 'conflicts', 'merge', 'refresh', 'pull', 'commit', 'push', 'gitpush', 'publish', 'deploy', 'update', 'doctor', 'promote']
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @param {Array<{ step: string, command: string|null, why: string, ask?: boolean }>} proposals
|