Files
Siteforge/server/state.js
T
nmemmertandClaude Sonnet 5 fe4c09f8a3
Publish Container / build (push) Successful in 20m51s
Add a newsletter archive so past issues can be shared and found; v2.3.0
Web-hosted copies of episode newsletters, published from Resend broadcasts
tagged with the "New Episode" topic. Gives Facebook (and anyone else) a
proper link to share instead of raw HTML email, and makes issues findable
via site search and Google.

- Admin "Newsletter Archive" tab lists sent Resend broadcasts, flags ones
  tagged "New Episode", and publishes them with one click (pulls the HTML
  straight from Resend's API)
- Public /newsletter archive index and /newsletter/:slug issue pages,
  server-rendered with per-issue Open Graph tags for social previews
- Unsubscribe merge-tag stripped from the web copy; archive + subscribe
  links appended
- Issues added to sitemap.xml and the on-site search index

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-28 12:17:13 -04:00

131 lines
4.0 KiB
JavaScript

import {
EMPTY_HIT_STATS,
EMPTY_VISITOR_STATS,
DEFAULT_PUBLISH_STATE,
DEFAULT_REPLY_TEMPLATES,
buildDefaultPodcastChecklist,
} from './config.js'
export const state = {
serverStartedAt: new Date().toISOString(),
cachedSiteContent: null,
cachedDraftSiteContent: null,
publishState: { ...DEFAULT_PUBLISH_STATE },
hitStats: { ...EMPTY_HIT_STATS },
hitStatsWritePromise: Promise.resolve(),
lastHitStatsWrite: { ok: true, at: null, error: null },
visitorStats: { ...EMPTY_VISITOR_STATS },
visitorStatsWritePromise: Promise.resolve(),
lastVisitorStatsWrite: { ok: true, at: null, error: null },
contactSubmissions: [],
contactSubmissionsWritePromise: Promise.resolve(),
questions: [],
questionsWritePromise: Promise.resolve(),
draftQuestions: null,
draftQuestionsWritePromise: Promise.resolve(),
replyTemplates: [...DEFAULT_REPLY_TEMPLATES],
replyTemplatesWritePromise: Promise.resolve(),
replyHistory: [],
replyHistoryWritePromise: Promise.resolve(),
podcastChecklist: buildDefaultPodcastChecklist(),
podcastChecklistWritePromise: Promise.resolve(),
studyUsers: [],
studyUsersWritePromise: Promise.resolve(),
studyCommunityPosts: [],
studyCommunityWritePromise: Promise.resolve(),
studyReminders: { users: {}, updatedAt: new Date().toISOString() },
studyRemindersWritePromise: Promise.resolve(),
studyComments: [],
studyCommentsWritePromise: Promise.resolve(),
studyCertificates: [],
studyCertificatesWritePromise: Promise.resolve(),
// episodeScripts: { [episodeNumber]: { text, title, filename, season, uploadedAt } }
episodeScripts: {},
episodeScriptsWritePromise: Promise.resolve(),
downloadCounts: {},
downloadCountsWritePromise: Promise.resolve(),
// episodePlays: { [title]: { total: number, byDay: { [YYYY-MM-DD]: number } } }
episodePlays: {},
episodePlaysWritePromise: Promise.resolve(),
// analyticsEvents: aggregated engagement data from frontend events
// {
// scrollDepth: { [path]: { 25: n, 50: n, 75: n, 90: n } }
// timeOnPage: { [path]: { totalSeconds: n, count: n } }
// outboundClicks: { [url]: n }
// utmSources: { [utm_source]: n }
// searchQueries: { [query]: n }
// notFound: { [path]: n }
// audioEvents: { [title]: { pauses: n, completions: n, totalListenSeconds: n } }
// }
analyticsEvents: {
scrollDepth: {},
timeOnPage: {},
outboundClicks: {},
utmSources: {},
searchQueries: {},
notFound: {},
audioEvents: {},
linkClicks: {},
},
analyticsEventsWritePromise: Promise.resolve(),
// qrCodes: Array<{ id, slug, label, destination, createdAt }>
// qrScans: Array<{ id, qrId, slug, scannedAt, ip, userAgent }>
qrCodes: [],
qrScans: [],
qrCodesWritePromise: Promise.resolve(),
emailSettings: { signature: 'Grace and peace,\nVerse by Verse with Nate' },
emailSettingsWritePromise: Promise.resolve(),
// newsletterIssues: Array<{ id, resendBroadcastId, slug, title, subject, description, html, sentAt, publishedAt, public }>
newsletterIssues: [],
newsletterIssuesWritePromise: Promise.resolve(),
calendarEvents: [],
calendarEventsWritePromise: Promise.resolve(),
auditLog: [],
auditLogWritePromise: Promise.resolve(),
webhooks: [],
webhooksWritePromise: Promise.resolve(),
lastBackupStatus: { ok: true, at: null, error: null, file: null },
lastCachePurgeStatus: { ok: true, at: null, error: null },
lastDeployHookStatus: { ok: true, at: null, error: null },
// In-memory caches (not persisted between restarts)
studyNotesCache: new Map(), // userId -> { [sectionId]: string }
studyNotesWriteQueues: new Map(), // userId -> Promise
studyProgressCache: new Map(), // userId -> { byStudy: ... }
studyProgressWriteQueues: new Map(), // userId -> Promise
studySessions: new Map(),
studySessionsWritePromise: Promise.resolve(),
studyTotpPendingTokens: new Map(),
emailOtpStore: new Map(),
titusDownloadTokens: new Map(),
contactSubmitCooldownByEmail: new Map(),
resendEmailSubmissionIndex: new Map(),
}