@growth-labs/cms 0.8.18 → 0.8.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine/content-insights.d.ts +27 -11
- package/dist/engine/content-insights.d.ts.map +1 -1
- package/dist/engine/content-insights.js +102 -53
- package/dist/engine/content-insights.js.map +1 -1
- package/dist/lib/publish-timezone.d.ts +38 -0
- package/dist/lib/publish-timezone.d.ts.map +1 -0
- package/dist/lib/publish-timezone.js +135 -0
- package/dist/lib/publish-timezone.js.map +1 -0
- package/dist/routes/content-insights.d.ts.map +1 -1
- package/dist/routes/content-insights.js +5 -2
- package/dist/routes/content-insights.js.map +1 -1
- package/dist/routes/content.d.ts.map +1 -1
- package/dist/routes/content.js +2 -102
- package/dist/routes/content.js.map +1 -1
- package/dist/schema/migrations.d.ts.map +1 -1
- package/dist/schema/migrations.js +7 -0
- package/dist/schema/migrations.js.map +1 -1
- package/dist/schema/types.d.ts +4 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js.map +1 -1
- package/dist/ui/inspector/PublishTab.d.ts +7 -1
- package/dist/ui/inspector/PublishTab.d.ts.map +1 -1
- package/dist/ui/inspector/PublishTab.js +24 -26
- package/dist/ui/inspector/PublishTab.js.map +1 -1
- package/migrations/0032_content_insight_publication_identity.sql +3 -0
- package/package.json +1 -1
- package/src/engine/content-insights.ts +142 -63
- package/src/lib/publish-timezone.ts +154 -0
- package/src/routes/content-insights.ts +6 -1
- package/src/routes/content.ts +5 -116
- package/src/schema/migrations.ts +7 -0
- package/src/schema/types.ts +4 -1
- package/src/ui/inspector/PublishTab.tsx +33 -25
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import {
|
|
3
3
|
dismissInsight,
|
|
4
|
+
InsightPublicationError,
|
|
4
5
|
isMissingInsightDismissalSchema,
|
|
6
|
+
isMissingInsightPublicationSchema,
|
|
5
7
|
isMissingInsightsTable,
|
|
6
8
|
listInsightBoard,
|
|
7
9
|
replaceInsightsBoard,
|
|
@@ -203,9 +205,12 @@ export function createContentInsightsRoutes(
|
|
|
203
205
|
ok: true,
|
|
204
206
|
outcome: result.outcome,
|
|
205
207
|
landedRunAttempt: result.landedRunAttempt,
|
|
208
|
+
publication: result.publication,
|
|
206
209
|
})
|
|
207
210
|
} catch (error) {
|
|
208
|
-
if (
|
|
211
|
+
if (isMissingInsightPublicationSchema(error))
|
|
212
|
+
return json({ error: 'schema_not_ready' }, 409)
|
|
213
|
+
if (error instanceof InsightPublicationError) return json({ error: error.code }, 409)
|
|
209
214
|
throw error
|
|
210
215
|
}
|
|
211
216
|
},
|
package/src/routes/content.ts
CHANGED
|
@@ -66,6 +66,11 @@ import { invalidateMediaCaptureStatements, softDeleteContent } from '../engine/s
|
|
|
66
66
|
import { normalizeSourceSections } from '../engine/source-sections.js'
|
|
67
67
|
import { TagInputError } from '../engine/taxonomy.js'
|
|
68
68
|
import type { ValidationError } from '../engine/validator/index.js'
|
|
69
|
+
import {
|
|
70
|
+
isValidTimeZone,
|
|
71
|
+
PUBLISH_TIMEZONE_FALLBACK,
|
|
72
|
+
parseLocalDateTimeInZoneToUnixSeconds,
|
|
73
|
+
} from '../lib/publish-timezone.js'
|
|
69
74
|
import type { MediaSourceResolution } from '../providers/types.js'
|
|
70
75
|
import { parseLayoutEnvelope } from '../schema/layout.js'
|
|
71
76
|
import { parsePortableTextEnvelope } from '../schema/portable-text.js'
|
|
@@ -242,9 +247,6 @@ export interface ContentRouteConfig extends CmsRouteConfig {
|
|
|
242
247
|
activeWorkspaceId?: string
|
|
243
248
|
}
|
|
244
249
|
|
|
245
|
-
const PUBLISH_TIMEZONE_FALLBACK = 'Europe/Paris'
|
|
246
|
-
const LOCAL_DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/
|
|
247
|
-
|
|
248
250
|
type ContentType = 'article' | 'video' | 'podcast' | 'newsletter' | 'page'
|
|
249
251
|
|
|
250
252
|
/**
|
|
@@ -677,119 +679,6 @@ const ContributorsReplaceSchema = z.object({
|
|
|
677
679
|
|
|
678
680
|
// --- timezone-aware local-datetime parsing (ported verbatim) --------------
|
|
679
681
|
|
|
680
|
-
type LocalDateTimeParts = { year: number; month: number; day: number; hour: number; minute: number }
|
|
681
|
-
|
|
682
|
-
function parseLocalDateTime(value: string): LocalDateTimeParts | null {
|
|
683
|
-
const match = LOCAL_DATE_TIME_RE.exec(value)
|
|
684
|
-
if (!match) return null
|
|
685
|
-
const [, y, m, d, h, min] = match
|
|
686
|
-
const parts: LocalDateTimeParts = {
|
|
687
|
-
year: Number.parseInt(y, 10),
|
|
688
|
-
month: Number.parseInt(m, 10),
|
|
689
|
-
day: Number.parseInt(d, 10),
|
|
690
|
-
hour: Number.parseInt(h, 10),
|
|
691
|
-
minute: Number.parseInt(min, 10),
|
|
692
|
-
}
|
|
693
|
-
if (
|
|
694
|
-
!Number.isInteger(parts.year) ||
|
|
695
|
-
parts.month < 1 ||
|
|
696
|
-
parts.month > 12 ||
|
|
697
|
-
parts.day < 1 ||
|
|
698
|
-
parts.day > 31 ||
|
|
699
|
-
parts.hour < 0 ||
|
|
700
|
-
parts.hour > 23 ||
|
|
701
|
-
parts.minute < 0 ||
|
|
702
|
-
parts.minute > 59
|
|
703
|
-
) {
|
|
704
|
-
return null
|
|
705
|
-
}
|
|
706
|
-
const dateCheck = new Date(Date.UTC(parts.year, parts.month - 1, parts.day))
|
|
707
|
-
if (
|
|
708
|
-
dateCheck.getUTCFullYear() !== parts.year ||
|
|
709
|
-
dateCheck.getUTCMonth() + 1 !== parts.month ||
|
|
710
|
-
dateCheck.getUTCDate() !== parts.day
|
|
711
|
-
) {
|
|
712
|
-
return null
|
|
713
|
-
}
|
|
714
|
-
return parts
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function getZonedParts(instantMs: number, timeZone: string): LocalDateTimeParts | null {
|
|
718
|
-
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
719
|
-
timeZone,
|
|
720
|
-
hour12: false,
|
|
721
|
-
year: 'numeric',
|
|
722
|
-
month: '2-digit',
|
|
723
|
-
day: '2-digit',
|
|
724
|
-
hour: '2-digit',
|
|
725
|
-
minute: '2-digit',
|
|
726
|
-
second: '2-digit',
|
|
727
|
-
})
|
|
728
|
-
const values = { year: '', month: '', day: '', hour: '', minute: '', second: '' }
|
|
729
|
-
for (const part of formatter.formatToParts(new Date(instantMs))) {
|
|
730
|
-
if (part.type in values) values[part.type as keyof typeof values] = part.value
|
|
731
|
-
}
|
|
732
|
-
const year = Number.parseInt(values.year, 10)
|
|
733
|
-
const month = Number.parseInt(values.month, 10)
|
|
734
|
-
const day = Number.parseInt(values.day, 10)
|
|
735
|
-
const hour = Number.parseInt(values.hour, 10)
|
|
736
|
-
const minute = Number.parseInt(values.minute, 10)
|
|
737
|
-
if (![year, month, day, hour, minute].every(Number.isFinite)) return null
|
|
738
|
-
return { year, month, day, hour, minute }
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
function isValidTimeZone(timeZone: string): boolean {
|
|
742
|
-
try {
|
|
743
|
-
new Intl.DateTimeFormat('en-US', { timeZone }).format(new Date())
|
|
744
|
-
return true
|
|
745
|
-
} catch {
|
|
746
|
-
return false
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
function getTimeZoneOffsetMs(instantMs: number, timeZone: string): number | null {
|
|
751
|
-
const zoned = getZonedParts(instantMs, timeZone)
|
|
752
|
-
if (!zoned) return null
|
|
753
|
-
const asUtc = Date.UTC(zoned.year, zoned.month - 1, zoned.day, zoned.hour, zoned.minute, 0)
|
|
754
|
-
return asUtc - instantMs
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
function parseLocalDateTimeInZoneToUnixSeconds(value: string, timeZone: string): number | null {
|
|
758
|
-
const target = parseLocalDateTime(value)
|
|
759
|
-
if (!target) return null
|
|
760
|
-
const targetUtcMs = Date.UTC(
|
|
761
|
-
target.year,
|
|
762
|
-
target.month - 1,
|
|
763
|
-
target.day,
|
|
764
|
-
target.hour,
|
|
765
|
-
target.minute,
|
|
766
|
-
0,
|
|
767
|
-
)
|
|
768
|
-
let candidateMs = targetUtcMs
|
|
769
|
-
for (let i = 0; i < 5; i += 1) {
|
|
770
|
-
const offsetMs = getTimeZoneOffsetMs(candidateMs, timeZone)
|
|
771
|
-
if (offsetMs === null) return null
|
|
772
|
-
const next = targetUtcMs - offsetMs
|
|
773
|
-
if (Math.abs(next - candidateMs) < 1000) {
|
|
774
|
-
candidateMs = next
|
|
775
|
-
break
|
|
776
|
-
}
|
|
777
|
-
candidateMs = next
|
|
778
|
-
}
|
|
779
|
-
const resolved = getZonedParts(candidateMs, timeZone)
|
|
780
|
-
if (
|
|
781
|
-
!resolved ||
|
|
782
|
-
resolved.year !== target.year ||
|
|
783
|
-
resolved.month !== target.month ||
|
|
784
|
-
resolved.day !== target.day ||
|
|
785
|
-
resolved.hour !== target.hour ||
|
|
786
|
-
resolved.minute !== target.minute
|
|
787
|
-
) {
|
|
788
|
-
return null
|
|
789
|
-
}
|
|
790
|
-
return Math.floor(candidateMs / 1000)
|
|
791
|
-
}
|
|
792
|
-
|
|
793
682
|
// --- read-side payload helpers (ported verbatim) --------------------------
|
|
794
683
|
|
|
795
684
|
async function getContentPayload(ctx: RouteContext, type: string, id: string) {
|
package/src/schema/migrations.ts
CHANGED
|
@@ -914,6 +914,13 @@ ALTER TABLE podcast_content ADD COLUMN processing_state TEXT CHECK (processing_s
|
|
|
914
914
|
id: '0031_podcast_processing_error',
|
|
915
915
|
sql: `ALTER TABLE podcast_content ADD COLUMN processing_error TEXT;`,
|
|
916
916
|
},
|
|
917
|
+
{
|
|
918
|
+
id: '0032_content_insight_publication_identity',
|
|
919
|
+
sql: `
|
|
920
|
+
ALTER TABLE content_insight_runs ADD COLUMN publication_run_id TEXT;
|
|
921
|
+
ALTER TABLE content_insight_runs ADD COLUMN payload_sha256 TEXT;
|
|
922
|
+
`,
|
|
923
|
+
},
|
|
917
924
|
]
|
|
918
925
|
|
|
919
926
|
/**
|
package/src/schema/types.ts
CHANGED
|
@@ -677,7 +677,7 @@ export interface ContentInsightRunRow {
|
|
|
677
677
|
site_id: string
|
|
678
678
|
run_date: string
|
|
679
679
|
status: InsightRunStatus
|
|
680
|
-
/**
|
|
680
|
+
/** Immutable event identity while this publication remains current. */
|
|
681
681
|
event_id: string
|
|
682
682
|
/** Monotonic; the stale-replay guard rejects equal-or-lower. */
|
|
683
683
|
run_attempt: number
|
|
@@ -685,6 +685,9 @@ export interface ContentInsightRunRow {
|
|
|
685
685
|
generated_at: number
|
|
686
686
|
/** Content hash of the board for change detection. */
|
|
687
687
|
content_hash: string
|
|
688
|
+
/** Sender run identity and receiver-computed RFC 8785 payload digest; null on legacy rows. */
|
|
689
|
+
publication_run_id: string | null
|
|
690
|
+
payload_sha256: string | null
|
|
688
691
|
demand_count: number
|
|
689
692
|
opportunity_count: number
|
|
690
693
|
started_at: number | null
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
// Compile-gated (tsc, jsx: react-jsx). No vitest — pure shapers are in
|
|
11
11
|
// inspector-data.ts and tested there.
|
|
12
12
|
|
|
13
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
13
|
+
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
14
|
+
import { formatInstantInZone, PUBLISH_TIMEZONE_FALLBACK } from '../../lib/publish-timezone.js'
|
|
14
15
|
import type { ContentStatus } from '../../schema/types.js'
|
|
15
16
|
import { apiErrorMessage } from '../api-error.js'
|
|
16
17
|
import { Icon } from '../icons.js'
|
|
@@ -40,6 +41,12 @@ export interface PublishTabProps {
|
|
|
40
41
|
authorId: string | null
|
|
41
42
|
/** Current scheduled publish time (ISO string, null if not scheduled). */
|
|
42
43
|
publishAt: string | null
|
|
44
|
+
/**
|
|
45
|
+
* Timezone the editor schedules in. The same zone is used to DISPLAY the
|
|
46
|
+
* stored instant and to SAVE what is typed, so a resave of untouched fields
|
|
47
|
+
* is a true no-op. Defaults to the publication timezone.
|
|
48
|
+
*/
|
|
49
|
+
publishTimezone?: string
|
|
43
50
|
/** Called after a status/field change so the parent can refresh. */
|
|
44
51
|
onChanged?: () => void
|
|
45
52
|
}
|
|
@@ -85,6 +92,7 @@ export function PublishTab({
|
|
|
85
92
|
visibility,
|
|
86
93
|
authorId,
|
|
87
94
|
publishAt,
|
|
95
|
+
publishTimezone = PUBLISH_TIMEZONE_FALLBACK,
|
|
88
96
|
onChanged,
|
|
89
97
|
}: PublishTabProps): React.ReactElement {
|
|
90
98
|
const [saving, setSaving] = useState(false)
|
|
@@ -92,16 +100,20 @@ export function PublishTab({
|
|
|
92
100
|
const [actionError, setActionError] = useState<string | null>(null)
|
|
93
101
|
|
|
94
102
|
// Local schedule date/time inputs.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
// The editor thinks in publication-local wall clock, so that is what these
|
|
104
|
+
// inputs show. Falling back to the raw UTC slice keeps an unusable zone
|
|
105
|
+
// readable rather than blank.
|
|
106
|
+
const scheduled = useMemo(() => {
|
|
107
|
+
if (!publishAt) return null
|
|
108
|
+
const ms = Date.parse(publishAt)
|
|
109
|
+
if (!Number.isFinite(ms)) return null
|
|
110
|
+
return formatInstantInZone(ms, publishTimezone)
|
|
111
|
+
}, [publishAt, publishTimezone])
|
|
112
|
+
|
|
113
|
+
const [schedDate, setSchedDate] = useState(() => scheduled?.date ?? publishAt?.slice(0, 10) ?? '')
|
|
114
|
+
const [schedTime, setSchedTime] = useState(
|
|
115
|
+
() => scheduled?.time ?? publishAt?.slice(11, 16) ?? '12:00',
|
|
116
|
+
)
|
|
105
117
|
|
|
106
118
|
// Author list (fetched once on mount).
|
|
107
119
|
const [authors, setAuthors] = useState<AuthorOption[]>([])
|
|
@@ -172,18 +184,14 @@ export function PublishTab({
|
|
|
172
184
|
setSaving(true)
|
|
173
185
|
setActionError(null)
|
|
174
186
|
try {
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
// them
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
// in that zone's offset, silently shifting publish_at by that zone's
|
|
182
|
-
// current UTC offset on every resave -- including an incidental
|
|
183
|
-
// resave that never touched these fields. 'UTC' makes display and
|
|
184
|
-
// save agree, so a resave of untouched fields is a true no-op.
|
|
187
|
+
// These digits are publication-local wall clock (see the initializers),
|
|
188
|
+
// so they are saved under that SAME zone. Display and save must agree:
|
|
189
|
+
// sending digits under a zone they were not rendered in made the server
|
|
190
|
+
// reinterpret them and shift publish_at by that zone's offset on every
|
|
191
|
+
// resave, including an incidental one that never touched these fields
|
|
192
|
+
// (the 2026-09-08 P0). Agreement is what keeps a resave a no-op.
|
|
185
193
|
const localDateTime = `${schedDate}T${schedTime}`
|
|
186
|
-
const body = buildScheduleBody(localDateTime,
|
|
194
|
+
const body = buildScheduleBody(localDateTime, publishTimezone)
|
|
187
195
|
await runAction(docId, 'schedule', body as unknown as Record<string, unknown>)
|
|
188
196
|
setSelectedStatus('scheduled')
|
|
189
197
|
onChanged?.()
|
|
@@ -192,7 +200,7 @@ export function PublishTab({
|
|
|
192
200
|
} finally {
|
|
193
201
|
setSaving(false)
|
|
194
202
|
}
|
|
195
|
-
}, [docId, schedDate, schedTime, saving, onChanged])
|
|
203
|
+
}, [docId, schedDate, schedTime, saving, onChanged, publishTimezone])
|
|
196
204
|
|
|
197
205
|
const handleVisibilityChange = useCallback(
|
|
198
206
|
async (newVis: 'free' | 'premium') => {
|
|
@@ -317,7 +325,7 @@ export function PublishTab({
|
|
|
317
325
|
{/* Scheduled date + time inputs */}
|
|
318
326
|
{showScheduleControls && (
|
|
319
327
|
<div style={schedGrid} className="fade-only">
|
|
320
|
-
<Field label=
|
|
328
|
+
<Field label={`Date (${publishTimezone})`}>
|
|
321
329
|
<input
|
|
322
330
|
className="input"
|
|
323
331
|
type="date"
|
|
@@ -325,7 +333,7 @@ export function PublishTab({
|
|
|
325
333
|
onChange={(e) => setSchedDate(e.target.value)}
|
|
326
334
|
/>
|
|
327
335
|
</Field>
|
|
328
|
-
<Field label=
|
|
336
|
+
<Field label={`Time (${publishTimezone})`}>
|
|
329
337
|
<input
|
|
330
338
|
className="input"
|
|
331
339
|
type="time"
|