Hub 2.26.1: devotionals two years ahead; Apps fetch 2 weeks
Devotionals can be written, edited and imported up to two years ahead (was 3 months), and a CSV holds two years in one file (800 rows, 8 MB). GET /api/v2/devotionals answers 2 weeks (from and the 13 days after it) instead of 3 months. Contracts 1.24.0 vendored. No migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -8,9 +8,9 @@ app.disable('x-powered-by');
|
||||
// Installs call the Hub server-to-server; only the dashboard needs CORS.
|
||||
app.use(cors({ origin: (process.env.FRONTEND_URL || 'http://localhost:3200').replace(/\/$/, '') }));
|
||||
|
||||
// 2.26.0: a devotionals CSV is up to 2 MB (contracts DEVOTIONAL_CSV_MAX_BYTES), sent as JSON text.
|
||||
// 2.26.0: a devotionals CSV, sent as JSON text (2.26.1: up to 8 MB, contracts DEVOTIONAL_CSV_MAX_BYTES).
|
||||
// Parsed here first; the parser below skips a body already read.
|
||||
app.use('/api/admin/devotionals/import', express.json({ limit: '4mb' }));
|
||||
app.use('/api/admin/devotionals/import', express.json({ limit: '12mb' }));
|
||||
|
||||
// Keep the exact bytes: heartbeat signatures are over the raw body. 300 KB fits the largest AI
|
||||
// request the Hub accepts (utils/ai.js MAX_INPUT_TOKENS).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Cross Code's devotionals (Hub 2.26.0, APP-1.0-PLAN §6): write and schedule them up to 3 months
|
||||
* ahead, the calendar, Import CSV with its preview, and the template. Admin login required.
|
||||
* Cross Code's devotionals (Hub 2.26.0, APP-1.0-PLAN §6): write and schedule them up to two years
|
||||
* ahead (2.26.1; 3 months before), the calendar, Import CSV with its preview, and the template. Admin login required.
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
@@ -30,7 +30,7 @@ router.get('/template.csv', (req, res) => {
|
||||
res.send(DEVOTIONAL_CSV_TEMPLATE);
|
||||
});
|
||||
|
||||
// A CSV comes as text in JSON ({ csv }), up to 2 MB (app.js parses these two with a larger limit).
|
||||
// A CSV comes as text in JSON ({ csv }), up to 8 MB (app.js parses these two with a larger limit).
|
||||
router.post('/import/preview', wrap(async (req, res) => {
|
||||
res.json(await devotionals.previewCsv(req.body?.csv));
|
||||
}));
|
||||
|
||||
@@ -409,7 +409,7 @@ router.post('/installs/update-request/cancel', updateRequestLimiter, async (req,
|
||||
// ─── Cross Code's devotionals (Hub 2.26.0, contracts hub.DEVOTIONALS_PATH) ─────
|
||||
|
||||
/**
|
||||
* GET /api/v2/devotionals?from=YYYY-MM-DD: the next 3 months of Cross Code's devotionals for an App
|
||||
* GET /api/v2/devotionals?from=YYYY-MM-DD: the next 2 weeks of Cross Code's devotionals for an App
|
||||
* set to "From Cross Code" (once a night, and on "Sync now"). `Authorization: Bearer <licence
|
||||
* token>`: App licences only, active or in their grace days.
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/**
|
||||
* Cross Code's devotionals (Hub 2.26.0, crosscode-platform docs/APP-1.0-PLAN.md §6, decisions 1, 5
|
||||
* and 14; contracts crosscode.devotional/1). Written here, or imported from CSV, up to 3 months
|
||||
* ahead, one per day, in the free translations only (KJV and BSB). An App set to "From Cross Code"
|
||||
* fetches the next 3 months once a night (`GET /api/v2/devotionals`) and keeps its copy.
|
||||
* and 14; contracts crosscode.devotional/1). Written here, or imported from CSV, up to two years
|
||||
* ahead (2.26.1, contracts CROSSCODE_DEVOTIONALS_SCHEDULE_MONTHS; 3 months in 2.26.0), one per day, in the free translations only (KJV and BSB). An App set to "From Cross Code"
|
||||
* fetches the next 2 weeks once a night (`GET /api/v2/devotionals`, 2.26.1; 3 months before) and keeps its copy.
|
||||
*
|
||||
* No AI touches a devotional's passage (Crossway and Biblica forbid it), and nothing here sends
|
||||
* one: the Apps show and send them.
|
||||
*/
|
||||
|
||||
const {
|
||||
BIBLE_TRANSLATIONS, FREE_BIBLE_TRANSLATION_IDS, DEVOTIONAL_CSV_TEMPLATE, DEVOTIONAL_CSV_COLUMNS, CROSSCODE_DEVOTIONALS_AHEAD_MONTHS, DEVOTIONAL_SCHEMA, PASSAGE_WARN_VERSES,
|
||||
BIBLE_TRANSLATIONS, FREE_BIBLE_TRANSLATION_IDS, DEVOTIONAL_CSV_TEMPLATE, DEVOTIONAL_CSV_COLUMNS, CROSSCODE_DEVOTIONALS_FETCH_DAYS, CROSSCODE_DEVOTIONALS_SCHEDULE_MONTHS, DEVOTIONAL_SCHEMA, PASSAGE_WARN_VERSES,
|
||||
checkDevotionalCsv, devotionalContentSchema, devotionalsReplySchema, parseBibleReference, formatBibleReference, passageVerseCount,
|
||||
youVersionUrl, bibleTranslation,
|
||||
} = require('@crosscode/contracts');
|
||||
@@ -30,8 +30,11 @@ function addMonths(date, months) {
|
||||
return new Date(Date.UTC(y, m - 1 + months, Math.min(d, last))).toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
/** The last day a devotional can be scheduled for: 3 months from today. */
|
||||
const latestDate = (now = new Date()) => addMonths(today(now), CROSSCODE_DEVOTIONALS_AHEAD_MONTHS);
|
||||
/** The last day a devotional can be scheduled for: two years from today (2.26.1). */
|
||||
const latestDate = (now = new Date()) => addMonths(today(now), CROSSCODE_DEVOTIONALS_SCHEDULE_MONTHS);
|
||||
|
||||
/** "two years", "3 months": how far ahead, in words. */
|
||||
const aheadWords = (m = CROSSCODE_DEVOTIONALS_SCHEDULE_MONTHS) => (m % 12 === 0 ? (m === 12 ? 'a year' : m === 24 ? 'two years' : `${m / 12} years`) : `${m} months`);
|
||||
|
||||
/** The translations the Hub offers (the free ones), for the form. */
|
||||
function translations() {
|
||||
@@ -49,7 +52,7 @@ function shape(row) {
|
||||
|
||||
/**
|
||||
* The form's fields as devotional content: the passage parsed and written out in the
|
||||
* translation's language, the free translations only, the date within 3 months.
|
||||
* translation's language, the free translations only, the date within two years.
|
||||
* Returns { devotional, warnings }.
|
||||
*/
|
||||
function contentFrom(input, now = new Date()) {
|
||||
@@ -57,7 +60,7 @@ function contentFrom(input, now = new Date()) {
|
||||
const date = String(b.date || '').trim();
|
||||
if (!DATE.test(date)) throw fail(400, 'BAD_REQUEST', 'Give the date as YYYY-MM-DD.');
|
||||
const latest = latestDate(now);
|
||||
if (date > latest) throw fail(400, 'TOO_FAR_AHEAD', `Devotionals are scheduled up to ${CROSSCODE_DEVOTIONALS_AHEAD_MONTHS} months ahead (the last day is ${latest}).`);
|
||||
if (date > latest) throw fail(400, 'TOO_FAR_AHEAD', `Devotionals are scheduled up to ${aheadWords()} ahead (the last day is ${latest}).`);
|
||||
const translation = String(b.translation || '').trim().toUpperCase();
|
||||
if (!FREE_BIBLE_TRANSLATION_IDS.includes(translation)) {
|
||||
const t = BIBLE_TRANSLATIONS.find(x => x.id === translation);
|
||||
@@ -109,7 +112,7 @@ async function overview(now = new Date()) {
|
||||
const filled = new Set(rows.map(r => r.date));
|
||||
const empty = [];
|
||||
for (let d = from; d <= to; d = addDays(d, 1)) if (!filled.has(d)) empty.push(d);
|
||||
return { today: from, latest: to, aheadMonths: CROSSCODE_DEVOTIONALS_AHEAD_MONTHS, devotionals: rows, empty, translations: translations(),
|
||||
return { today: from, latest: to, aheadMonths: CROSSCODE_DEVOTIONALS_SCHEDULE_MONTHS, ahead: aheadWords(), appFetchDays: CROSSCODE_DEVOTIONALS_FETCH_DAYS, devotionals: rows, empty, translations: translations(),
|
||||
csv: { columns: DEVOTIONAL_CSV_COLUMNS, template: DEVOTIONAL_CSV_TEMPLATE } };
|
||||
}
|
||||
|
||||
@@ -136,7 +139,7 @@ async function create(input, admin, now = new Date()) {
|
||||
async function update(id, input, now = new Date()) {
|
||||
const existing = await prisma.devotional.findUnique({ where: { id } });
|
||||
if (!existing) throw fail(404, 'NOT_FOUND', 'Devotional not found.');
|
||||
// An old one keeps its date even when that's now in the past; a new date must be within 3 months.
|
||||
// An old one keeps its date even when that's now in the past; a new date must be within two years.
|
||||
const { devotional, warnings } = contentFrom(input, now);
|
||||
if (devotional.date !== existing.date) {
|
||||
const taken = await prisma.devotional.findUnique({ where: { date: devotional.date } });
|
||||
@@ -187,11 +190,12 @@ async function importCsv(text, { replace = false } = {}, admin, now = new Date()
|
||||
|
||||
/**
|
||||
* `GET /api/v2/devotionals?from=YYYY-MM-DD` (contracts hub.DEVOTIONALS_PATH): the devotionals
|
||||
* from `from` (today by default) to 3 months on, for an App install.
|
||||
* from `from` (today by default), for an App install: 2 weeks, `from` included (2.26.1,
|
||||
* contracts CROSSCODE_DEVOTIONALS_FETCH_DAYS; 3 months before).
|
||||
*/
|
||||
async function reply(from, now = new Date()) {
|
||||
const start = from || today(now);
|
||||
const to = addMonths(start, CROSSCODE_DEVOTIONALS_AHEAD_MONTHS);
|
||||
const to = addDays(start, CROSSCODE_DEVOTIONALS_FETCH_DAYS - 1);
|
||||
const rows = (await list({ from: start, to })).slice(0, 100);
|
||||
return devotionalsReplySchema.parse({
|
||||
schema: DEVOTIONAL_SCHEMA, from: start, to,
|
||||
@@ -203,4 +207,4 @@ async function reply(from, now = new Date()) {
|
||||
/** The YouVersion link for a devotional's passage (the page's "Read in YouVersion"). */
|
||||
const youVersionLink = d => youVersionUrl(d.passage.location, d.passage.translation);
|
||||
|
||||
module.exports = { today, addMonths, latestDate, translations, contentFrom, list, overview, get, create, update, remove, previewCsv, importCsv, reply, youVersionLink, DATE };
|
||||
module.exports = { today, addMonths, addDays, latestDate, translations, contentFrom, list, overview, get, create, update, remove, previewCsv, importCsv, reply, youVersionLink, DATE };
|
||||
|
||||
Reference in New Issue
Block a user