@anthusai/papyrus 5.135.0-next.2 → 5.135.0-next.4
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/amplify/functions/announcements/schema.js +5 -1
- package/amplify/functions/announcements/schema.ts +5 -1
- package/amplify/functions/content-actions/handler.py +34 -10
- package/amplify/plugins/newsletter/papyrus.plugin.js +1 -12
- package/amplify/plugins/newsletter/papyrus.plugin.ts +1 -15
- package/amplify/plugins/notifications/papyrus.plugin.js +2 -13
- package/amplify/plugins/notifications/papyrus.plugin.ts +2 -15
- package/components/newsroom-article-editor.tsx +3 -1
- package/components/story-schedule-panel.tsx +43 -7
- package/components/story-schedule.css +1 -0
- package/lib/content-actions-client.ts +21 -3
- package/lib/content-actions-demo.ts +17 -4
- package/lib/images/operations.generated.ts +136 -2
- package/lib/local-preview-seed.ts +22 -1
- package/lib/newsroom-articles.ts +4 -1
- package/lib/story-schedule.ts +17 -4
- package/package.json +1 -1
- package/routes.manifest.json +1 -1
|
@@ -90,7 +90,8 @@ export const announcementsSchemaDefinitions = {
|
|
|
90
90
|
/**
|
|
91
91
|
* A Delivery: one channel's version of an Announcement (docs/announcement-records.md). The words and any picture are files in S3 (textKey, imageKey, contentHash);
|
|
92
92
|
* the row never holds text. id is `<announcement>#<channel>#<account>#g<generation>`, created with a condition: one live Delivery for each Announcement, channel and
|
|
93
|
-
* account, and a correction is the next generation, written with `supersedes`.
|
|
93
|
+
* account, and a correction is the next generation, written with `supersedes`. Every edit is a new version: `versions` is the log (each version's file, key, hash, who saved it and which
|
|
94
|
+
* version it replaced; the words themselves are files in S3) and `candidates` the texts and pictures kept beside the draft. Approval lives here, per Delivery. Every wait is a named time (releaseAt, lockAt,
|
|
94
95
|
* nextAttemptAt with waitingFor); dueAt is the earliest of them and, with dueKey, is present only while one is pending, so the due index is sparse.
|
|
95
96
|
*/
|
|
96
97
|
Delivery: a
|
|
@@ -112,6 +113,8 @@ export const announcementsSchemaDefinitions = {
|
|
|
112
113
|
contentHash: a.string(),
|
|
113
114
|
draftedBy: a.string(),
|
|
114
115
|
checks: a.json(),
|
|
116
|
+
versions: a.json(),
|
|
117
|
+
candidates: a.json(),
|
|
115
118
|
approval: a.string().required(),
|
|
116
119
|
approvalPolicy: a.string().required(),
|
|
117
120
|
approvedVersion: a.integer(),
|
|
@@ -121,6 +124,7 @@ export const announcementsSchemaDefinitions = {
|
|
|
121
124
|
lockAt: a.datetime().required(),
|
|
122
125
|
lockedAt: a.datetime(),
|
|
123
126
|
lockedVersion: a.integer(),
|
|
127
|
+
preferredVersion: a.integer(),
|
|
124
128
|
nextAttemptAt: a.datetime(),
|
|
125
129
|
waitingFor: a.string(),
|
|
126
130
|
dueAt: a.datetime(),
|
|
@@ -93,7 +93,8 @@ export const announcementsSchemaDefinitions = {
|
|
|
93
93
|
/**
|
|
94
94
|
* A Delivery: one channel's version of an Announcement (docs/announcement-records.md). The words and any picture are files in S3 (textKey, imageKey, contentHash);
|
|
95
95
|
* the row never holds text. id is `<announcement>#<channel>#<account>#g<generation>`, created with a condition: one live Delivery for each Announcement, channel and
|
|
96
|
-
* account, and a correction is the next generation, written with `supersedes`.
|
|
96
|
+
* account, and a correction is the next generation, written with `supersedes`. Every edit is a new version: `versions` is the log (each version's file, key, hash, who saved it and which
|
|
97
|
+
* version it replaced; the words themselves are files in S3) and `candidates` the texts and pictures kept beside the draft. Approval lives here, per Delivery. Every wait is a named time (releaseAt, lockAt,
|
|
97
98
|
* nextAttemptAt with waitingFor); dueAt is the earliest of them and, with dueKey, is present only while one is pending, so the due index is sparse.
|
|
98
99
|
*/
|
|
99
100
|
Delivery: a
|
|
@@ -115,6 +116,8 @@ export const announcementsSchemaDefinitions = {
|
|
|
115
116
|
contentHash: a.string(),
|
|
116
117
|
draftedBy: a.string(),
|
|
117
118
|
checks: a.json(),
|
|
119
|
+
versions: a.json(),
|
|
120
|
+
candidates: a.json(),
|
|
118
121
|
approval: a.string().required(),
|
|
119
122
|
approvalPolicy: a.string().required(),
|
|
120
123
|
approvedVersion: a.integer(),
|
|
@@ -124,6 +127,7 @@ export const announcementsSchemaDefinitions = {
|
|
|
124
127
|
lockAt: a.datetime().required(),
|
|
125
128
|
lockedAt: a.datetime(),
|
|
126
129
|
lockedVersion: a.integer(),
|
|
130
|
+
preferredVersion: a.integer(),
|
|
127
131
|
nextAttemptAt: a.datetime(),
|
|
128
132
|
waitingFor: a.string(),
|
|
129
133
|
dueAt: a.datetime(),
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
5
|
+
from datetime import datetime
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
from papyrus_content import request_meter
|
|
@@ -39,6 +40,7 @@ from papyrus_content.rebuild_trigger import (
|
|
|
39
40
|
trigger_rebuild,
|
|
40
41
|
trigger_staging_build,
|
|
41
42
|
)
|
|
43
|
+
from papyrus_content.publication_cadence import cadence_from_environment
|
|
42
44
|
from papyrus_content.story_reporting import save_story_version
|
|
43
45
|
from papyrus_content.story_schedule import TASK_NAME as PUBLISH_SCHEDULED_TASK, Caller, ScheduleError, ScheduleService, run_operation as run_schedule_operation, scheduler_from_environment, ZONE_ENV as PUBLICATION_ZONE_ENV
|
|
44
46
|
from papyrus_content.live_schema import wait_for_live_schema
|
|
@@ -47,7 +49,7 @@ from papyrus_content.editorial_checks import GraphQLEditorialStore, ensure_defau
|
|
|
47
49
|
from papyrus_content.item_deck_backfill import ensure_item_decks
|
|
48
50
|
from papyrus_content.item_language_backfill import ensure_item_languages
|
|
49
51
|
from papyrus_content.reference_intake import IntakeError, intake_email_submission_references, intake_references
|
|
50
|
-
from papyrus_content.
|
|
52
|
+
from papyrus_content.publishing import PUBLISHED_TASK_KEY
|
|
51
53
|
from papyrus_content.localize.dispatch import PUBLISH_TASK as PUBLISH_LOCALIZATION_TASK
|
|
52
54
|
from papyrus_content.publishing import (
|
|
53
55
|
ItemFields,
|
|
@@ -133,7 +135,28 @@ INVOKED_FUNCTION_ARN: str | None = None # this function's own ARN, from the in
|
|
|
133
135
|
|
|
134
136
|
def schedule_service(client) -> ScheduleService:
|
|
135
137
|
"""The site's scheduled-publishing service: the publication's time zone and its Scheduler come from the environment the deploy set."""
|
|
136
|
-
|
|
138
|
+
zone_name = os.environ.get(PUBLICATION_ZONE_ENV)
|
|
139
|
+
return ScheduleService(client, zone_name=zone_name, scheduler=scheduler_from_environment(invoked_function_arn=INVOKED_FUNCTION_ARN), cadence=cadence_from_environment(zone_name))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def count_first_publication(client, item: dict, item_id: str) -> dict:
|
|
143
|
+
"""A Story went live for the first time: add it to the publication's rhythm (the hours of the week it publishes in), which "Suggest a time" learns from. The publish
|
|
144
|
+
has already happened, so a failure is reported in the answer and never undoes it; a site with no time zone or no lock table keeps no rhythm. A new version of a Story
|
|
145
|
+
that is already out, a translation and anything that is not a Story are not first publications."""
|
|
146
|
+
from papyrus_content.content_item_lifecycle import is_story_item_type
|
|
147
|
+
from papyrus_content.localization_publish import original_of
|
|
148
|
+
|
|
149
|
+
if item.get("publishedAt") or not is_story_item_type(item.get("type")) or original_of(None, item) is not None:
|
|
150
|
+
return {}
|
|
151
|
+
try:
|
|
152
|
+
store = cadence_from_environment(os.environ.get(PUBLICATION_ZONE_ENV))
|
|
153
|
+
if store is None:
|
|
154
|
+
return {}
|
|
155
|
+
published = client.get_record("Item", item_id) or {} # the first publication time the publish just wrote
|
|
156
|
+
store.record_first_publication(datetime.fromisoformat(str(published["publishedAt"]).replace("Z", "+00:00")))
|
|
157
|
+
except Exception as error: # noqa: BLE001 - reported to the caller in the answer
|
|
158
|
+
return {"cadence": {"error": f"{type(error).__name__}: {error}"}}
|
|
159
|
+
return {}
|
|
137
160
|
|
|
138
161
|
|
|
139
162
|
class ProjectionTaskFailed(Exception):
|
|
@@ -202,7 +225,7 @@ def project_item_action(client, item_id: str, *, unpublished: bool, published_it
|
|
|
202
225
|
is live, here when the projection succeeds, or by the scheduled retry (which carries the same marker) when it did not."""
|
|
203
226
|
if not projection_configured():
|
|
204
227
|
if published_item_id:
|
|
205
|
-
|
|
228
|
+
story_is_live(client, item_id, published_item_id)
|
|
206
229
|
return {}
|
|
207
230
|
liveness = {} if unpublished else {"live": False}
|
|
208
231
|
task = {"task": "item", "itemId": item_id, "unpublished": unpublished}
|
|
@@ -239,7 +262,7 @@ def project_item_action(client, item_id: str, *, unpublished: bool, published_it
|
|
|
239
262
|
if report.follow_up_item_pages:
|
|
240
263
|
schedule_item_pages(item_id)
|
|
241
264
|
if report.ok and published_item_id:
|
|
242
|
-
|
|
265
|
+
story_is_live(client, item_id, published_item_id)
|
|
243
266
|
return response
|
|
244
267
|
|
|
245
268
|
|
|
@@ -478,7 +501,7 @@ def build_item_job(client, context, jobs, item_id: str, job_id: str | None, *, u
|
|
|
478
501
|
jobs.finish(item_id, job_id, ok=report.ok, outcome=outcome)
|
|
479
502
|
if report.ok and not unpublished and isinstance(published, dict):
|
|
480
503
|
# A real publish (the CLI marks it, as does the newsroom's retry): the page is live, so tell the newsletter.
|
|
481
|
-
|
|
504
|
+
story_is_live(client, item_id, published.get("publishedItemId"))
|
|
482
505
|
return report
|
|
483
506
|
|
|
484
507
|
|
|
@@ -874,6 +897,7 @@ def publish_item_action(arguments: dict, actor: str, approved_by: str | None = N
|
|
|
874
897
|
"publishedId": result.published_item_id,
|
|
875
898
|
"versionNumber": result.version_number,
|
|
876
899
|
**remove_schedules(client, candidate, int(candidate["versionNumber"]) if candidate.get("versionNumber") else None), # publishing now ends the schedule
|
|
900
|
+
**(count_first_publication(client, candidate, arguments["id"]) if result.changed else {}),
|
|
877
901
|
}
|
|
878
902
|
if result.changed and live is not None and live.get("type") and live.get("type") != candidate.get("type"):
|
|
879
903
|
# The type decides the address (urls.types), so the live page moves; the projection leaves a redirect from the old address.
|
|
@@ -938,11 +962,11 @@ def schedule_item_action(arguments: dict, event: dict) -> dict:
|
|
|
938
962
|
return run_schedule_operation(str(arguments.get("operation") or ""), arguments.get("arguments") or {}, service, caller_from_event(event))
|
|
939
963
|
|
|
940
964
|
|
|
941
|
-
def
|
|
942
|
-
"""A Story is live:
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
965
|
+
def story_is_live(client, item_id: str, published_item_id: str | None) -> None:
|
|
966
|
+
"""A Story's page is live: ask for its translations when the site translates on publish (``languages.auto``; docs/story-translation-procedure.md). It cannot fail
|
|
967
|
+
the publish, which is already done. A translation request that could not be written is logged and left for ``papyrus stories localize --all``, which finds every
|
|
968
|
+
Story with no up-to-date translation. Nothing here tells the newsletter, the notifications function or any announcement: the Story's own record entering the
|
|
969
|
+
published stage reaches the announce agent through the Item change feed (docs/announcement-records.md), so a publish writes only its own records."""
|
|
946
970
|
try:
|
|
947
971
|
from papyrus_content.localize.auto import request_translations
|
|
948
972
|
|
|
@@ -15,11 +15,9 @@ import { pythonLambdaCode } from "../../functions/shared/python-bundle.js";
|
|
|
15
15
|
import { resolveNewsletterConfig } from "./config.js";
|
|
16
16
|
import { newsletterOps } from "./ops/resource.js";
|
|
17
17
|
import { NEWSLETTER_MUTATIONS, NEWSLETTER_QUERIES, newsletterSchemaDefinitions } from "./schema.js";
|
|
18
|
-
import {
|
|
18
|
+
import { newsletterFunctionName, wireSending } from "./sending.js";
|
|
19
19
|
export { resolveNewsletterConfig };
|
|
20
20
|
export const NEWSLETTER_OUTPUT_KEY = "newsletter";
|
|
21
|
-
/** Set on the site's content-actions function: it invokes this function (`item-published`) after a real publish. Unset: no alerts. */
|
|
22
|
-
export const NEWSLETTER_FUNCTION_ENV = "PAPYRUS_NEWSLETTER_FUNCTION";
|
|
23
21
|
export const NEWSLETTER_HANDLER = "papyrus_content.newsletter.handler.handler";
|
|
24
22
|
/** `boto3` is bundled because the runtime's copy may predate SESv2 `Simple.Headers` (List-Unsubscribe). */
|
|
25
23
|
export const NEWSLETTER_REQUIREMENTS = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "Pillow>=11.3,<12", "boto3>=1.35.8,<2"];
|
|
@@ -237,15 +235,6 @@ export const newsletterPlugin = {
|
|
|
237
235
|
});
|
|
238
236
|
alarm.addAlarmAction(new SnsAction(alarmTopic));
|
|
239
237
|
}
|
|
240
|
-
// The publish path tells this function about a real publish. The ARN is spelled out (not referenced) so the content-actions
|
|
241
|
-
// stack does not depend on this one, and the grant is for this one function only.
|
|
242
|
-
const contentActions = context.contentActionsLambda;
|
|
243
|
-
contentActions.addEnvironment(NEWSLETTER_FUNCTION_ENV, newsletterFunctionName(config.siteId));
|
|
244
|
-
contentActions.addToRolePolicy(new PolicyStatement({
|
|
245
|
-
effect: Effect.ALLOW,
|
|
246
|
-
actions: ["lambda:InvokeFunction"],
|
|
247
|
-
resources: [functionArn(Stack.of(contentActions), newsletterFunctionName(config.siteId))],
|
|
248
|
-
}));
|
|
249
238
|
lambda.addPermission("InvokeFromCmsCompute", {
|
|
250
239
|
principal: new ArnPrincipal(config.computeRoleArn),
|
|
251
240
|
action: "lambda:InvokeFunction",
|
|
@@ -16,14 +16,12 @@ import type { PapyrusPlugin, PluginManifest, PluginWiringContext } from "../type
|
|
|
16
16
|
import { resolveNewsletterConfig, type NewsletterConfig } from "./config";
|
|
17
17
|
import { newsletterOps } from "./ops/resource";
|
|
18
18
|
import { NEWSLETTER_MUTATIONS, NEWSLETTER_QUERIES, newsletterSchemaDefinitions } from "./schema";
|
|
19
|
-
import {
|
|
19
|
+
import { newsletterFunctionName, wireSending } from "./sending";
|
|
20
20
|
|
|
21
21
|
export { resolveNewsletterConfig };
|
|
22
22
|
export type { NewsletterConfig };
|
|
23
23
|
|
|
24
24
|
export const NEWSLETTER_OUTPUT_KEY = "newsletter";
|
|
25
|
-
/** Set on the site's content-actions function: it invokes this function (`item-published`) after a real publish. Unset: no alerts. */
|
|
26
|
-
export const NEWSLETTER_FUNCTION_ENV = "PAPYRUS_NEWSLETTER_FUNCTION";
|
|
27
25
|
export const NEWSLETTER_HANDLER = "papyrus_content.newsletter.handler.handler";
|
|
28
26
|
/** `boto3` is bundled because the runtime's copy may predate SESv2 `Simple.Headers` (List-Unsubscribe). */
|
|
29
27
|
export const NEWSLETTER_REQUIREMENTS = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "Pillow>=11.3,<12", "boto3>=1.35.8,<2"];
|
|
@@ -276,18 +274,6 @@ export const newsletterPlugin: PapyrusPlugin<NewsletterConfig, { newsletterOps:
|
|
|
276
274
|
alarm.addAlarmAction(new SnsAction(alarmTopic));
|
|
277
275
|
}
|
|
278
276
|
|
|
279
|
-
// The publish path tells this function about a real publish. The ARN is spelled out (not referenced) so the content-actions
|
|
280
|
-
// stack does not depend on this one, and the grant is for this one function only.
|
|
281
|
-
const contentActions = context.contentActionsLambda;
|
|
282
|
-
contentActions.addEnvironment(NEWSLETTER_FUNCTION_ENV, newsletterFunctionName(config.siteId));
|
|
283
|
-
contentActions.addToRolePolicy(
|
|
284
|
-
new PolicyStatement({
|
|
285
|
-
effect: Effect.ALLOW,
|
|
286
|
-
actions: ["lambda:InvokeFunction"],
|
|
287
|
-
resources: [functionArn(Stack.of(contentActions), newsletterFunctionName(config.siteId))],
|
|
288
|
-
}),
|
|
289
|
-
);
|
|
290
|
-
|
|
291
277
|
lambda.addPermission("InvokeFromCmsCompute", {
|
|
292
278
|
principal: new ArnPrincipal(config.computeRoleArn),
|
|
293
279
|
action: "lambda:InvokeFunction",
|
|
@@ -14,13 +14,11 @@ import { fileURLToPath } from "node:url";
|
|
|
14
14
|
import { pythonLambdaCode } from "../../functions/shared/python-bundle.js";
|
|
15
15
|
import { SecureStringParameter } from "../newsletter/secure-string-parameter.js";
|
|
16
16
|
import { ALARM_MINIMUM_SENDS, BOUNCE_RATE_THRESHOLD, COMPLAINT_RATE_THRESHOLD } from "../newsletter/papyrus.plugin.js";
|
|
17
|
-
import {
|
|
17
|
+
import { postalAddressParameterArns } from "../newsletter/sending.js";
|
|
18
18
|
import { resolveNotificationsConfig } from "./config.js";
|
|
19
19
|
import { siteApiEnvironment } from "../../site-api-access.js";
|
|
20
20
|
export { resolveNotificationsConfig };
|
|
21
21
|
export const NOTIFICATIONS_OUTPUT_KEY = "notifications";
|
|
22
|
-
/** Set on the site's content-actions function: it invokes the router function (`story-published`) after a real publish. Unset: no notices. */
|
|
23
|
-
export const NOTIFICATIONS_FUNCTION_ENV = "PAPYRUS_NOTIFICATIONS_FUNCTION";
|
|
24
22
|
export const HANDLERS = {
|
|
25
23
|
router: "papyrus_content.notifications.handler.router",
|
|
26
24
|
email: "papyrus_content.notifications.handler.email",
|
|
@@ -352,16 +350,7 @@ export const notificationsPlugin = {
|
|
|
352
350
|
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
353
351
|
});
|
|
354
352
|
}
|
|
355
|
-
// The
|
|
356
|
-
// stack does not depend on this one, and the grant is for this one function only.
|
|
357
|
-
const contentActions = context.contentActionsLambda;
|
|
358
|
-
contentActions.addEnvironment(NOTIFICATIONS_FUNCTION_ENV, notificationsFunctionName(config.siteId));
|
|
359
|
-
contentActions.addToRolePolicy(new PolicyStatement({
|
|
360
|
-
effect: Effect.ALLOW,
|
|
361
|
-
actions: ["lambda:InvokeFunction"],
|
|
362
|
-
resources: [functionArn(Stack.of(contentActions), notificationsFunctionName(config.siteId))],
|
|
363
|
-
}));
|
|
364
|
-
// The CMS routes are the only other caller.
|
|
353
|
+
// The CMS routes are the only caller: a publish tells this function nothing (the announce agent is woken by the Item change feed).
|
|
365
354
|
router.addPermission("InvokeFromCmsCompute", { principal: new ArnPrincipal(config.computeRoleArn), action: "lambda:InvokeFunction" });
|
|
366
355
|
backend.addOutput({ custom: { [NOTIFICATIONS_OUTPUT_KEY]: { actionsFunction: router.functionName } } });
|
|
367
356
|
},
|
|
@@ -14,7 +14,7 @@ import { fileURLToPath } from "node:url";
|
|
|
14
14
|
import { pythonLambdaCode } from "../../functions/shared/python-bundle";
|
|
15
15
|
import { SecureStringParameter } from "../newsletter/secure-string-parameter";
|
|
16
16
|
import { ALARM_MINIMUM_SENDS, BOUNCE_RATE_THRESHOLD, COMPLAINT_RATE_THRESHOLD } from "../newsletter/papyrus.plugin";
|
|
17
|
-
import {
|
|
17
|
+
import { postalAddressParameterArns } from "../newsletter/sending";
|
|
18
18
|
import type { PapyrusPlugin, PluginManifest, PluginWiringContext } from "../types";
|
|
19
19
|
import { resolveNotificationsConfig, type NotificationsConfig } from "./config";
|
|
20
20
|
import { siteApiEnvironment } from "../../site-api-access";
|
|
@@ -23,8 +23,6 @@ export { resolveNotificationsConfig };
|
|
|
23
23
|
export type { NotificationsConfig };
|
|
24
24
|
|
|
25
25
|
export const NOTIFICATIONS_OUTPUT_KEY = "notifications";
|
|
26
|
-
/** Set on the site's content-actions function: it invokes the router function (`story-published`) after a real publish. Unset: no notices. */
|
|
27
|
-
export const NOTIFICATIONS_FUNCTION_ENV = "PAPYRUS_NOTIFICATIONS_FUNCTION";
|
|
28
26
|
export const HANDLERS = {
|
|
29
27
|
router: "papyrus_content.notifications.handler.router",
|
|
30
28
|
email: "papyrus_content.notifications.handler.email",
|
|
@@ -383,18 +381,7 @@ export const notificationsPlugin: PapyrusPlugin<NotificationsConfig, Record<stri
|
|
|
383
381
|
});
|
|
384
382
|
}
|
|
385
383
|
|
|
386
|
-
// The
|
|
387
|
-
// stack does not depend on this one, and the grant is for this one function only.
|
|
388
|
-
const contentActions = context.contentActionsLambda;
|
|
389
|
-
contentActions.addEnvironment(NOTIFICATIONS_FUNCTION_ENV, notificationsFunctionName(config.siteId));
|
|
390
|
-
contentActions.addToRolePolicy(
|
|
391
|
-
new PolicyStatement({
|
|
392
|
-
effect: Effect.ALLOW,
|
|
393
|
-
actions: ["lambda:InvokeFunction"],
|
|
394
|
-
resources: [functionArn(Stack.of(contentActions), notificationsFunctionName(config.siteId))],
|
|
395
|
-
}),
|
|
396
|
-
);
|
|
397
|
-
// The CMS routes are the only other caller.
|
|
384
|
+
// The CMS routes are the only caller: a publish tells this function nothing (the announce agent is woken by the Item change feed).
|
|
398
385
|
router.addPermission("InvokeFromCmsCompute", { principal: new ArnPrincipal(config.computeRoleArn), action: "lambda:InvokeFunction" });
|
|
399
386
|
|
|
400
387
|
backend.addOutput({ custom: { [NOTIFICATIONS_OUTPUT_KEY]: { actionsFunction: router.functionName } } });
|
|
@@ -218,6 +218,7 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false, stars
|
|
|
218
218
|
};
|
|
219
219
|
}, [activeArticleId, backend, blocked, isNew, reloadToken]);
|
|
220
220
|
|
|
221
|
+
const loadedVersionNumber = editor?.versionNumber ?? null; // a version saved from this drawer changes what "newer than the scheduled one" means, so the schedule is read again
|
|
221
222
|
useEffect(() => {
|
|
222
223
|
setScheduleKnown(false);
|
|
223
224
|
if (!scheduleZone || !lineageId) { setSchedule(undefined); return; }
|
|
@@ -227,7 +228,7 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false, stars
|
|
|
227
228
|
.then((result) => { if (!cancelled) { setSchedule(scheduleFromEntries(result.schedules)); setScheduleKnown(true); } })
|
|
228
229
|
.catch((error: unknown) => { if (!cancelled) setNotice({ tone: "error", text: `The schedule could not be read. ${failureMessage(error)}` }); });
|
|
229
230
|
return () => { cancelled = true; };
|
|
230
|
-
}, [backend, lineageId, scheduleZone, reloadToken]);
|
|
231
|
+
}, [backend, lineageId, scheduleZone, reloadToken, loadedVersionNumber]);
|
|
231
232
|
|
|
232
233
|
const savedItemId = editor?.id ?? null;
|
|
233
234
|
useEffect(() => {
|
|
@@ -768,6 +769,7 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false, stars
|
|
|
768
769
|
zone={scheduleZone}
|
|
769
770
|
schedule={schedule}
|
|
770
771
|
blockedReason={editor.dirty ? "Save your changes first: a schedule publishes the saved version." : isOlderVersion ? "This is an older version of the Story." : null}
|
|
772
|
+
suggest={() => backend.actions.scheduleSuggest({ storyLineageId: lineageId })}
|
|
771
773
|
save={async (scheduledPublishAt) => {
|
|
772
774
|
const saved = scheduleFromResult(await backend.actions.scheduleStory({ itemId: editor.id!, lineageId, scheduledPublishAt }));
|
|
773
775
|
setSchedule(saved);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useEffect, useId, useState } from "react";
|
|
4
|
-
import { CalendarClock, CalendarX2, Pencil } from "lucide-react";
|
|
4
|
+
import { CalendarClock, CalendarSearch, CalendarX2, Pencil } from "lucide-react";
|
|
5
|
+
import type { ScheduleSuggestResult } from "../lib/content-actions-client";
|
|
5
6
|
import {
|
|
7
|
+
NEWER_VERSION_NOTE,
|
|
6
8
|
PAST_TIME_MESSAGE,
|
|
9
|
+
SUGGESTION_BASIS,
|
|
7
10
|
ownZoneTime,
|
|
8
11
|
resolveWallTime,
|
|
9
12
|
scheduleSentence,
|
|
@@ -25,7 +28,7 @@ function failureText(reason: unknown): string {
|
|
|
25
28
|
* refuses it; what the editor typed stays in the form so nothing has to be typed again. A wall-clock time that does not exist (the spring-forward gap) is refused
|
|
26
29
|
* here with a plain message; one that happens twice (fall back) asks which one. Publish now is the editor's own button and is not touched.
|
|
27
30
|
*/
|
|
28
|
-
export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChanged }: {
|
|
31
|
+
export function StorySchedulePanel({ zone, schedule, blockedReason, save, suggest, onChanged }: {
|
|
29
32
|
zone: string;
|
|
30
33
|
/** What was last saved. */
|
|
31
34
|
schedule: StorySchedule | undefined;
|
|
@@ -33,6 +36,8 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
33
36
|
blockedReason: string | null;
|
|
34
37
|
/** Saves a UTC instant, or clears with null, and returns the schedule the backend recorded. */
|
|
35
38
|
save: (scheduledPublishAt: string | null) => Promise<StorySchedule | undefined>;
|
|
39
|
+
/** Asks for the time the publication's own rhythm suggests (the backend's `schedule_suggest`), or why there is none. */
|
|
40
|
+
suggest: () => Promise<ScheduleSuggestResult>;
|
|
36
41
|
onChanged?: (schedule: StorySchedule | undefined) => void;
|
|
37
42
|
}) {
|
|
38
43
|
const ids = useId();
|
|
@@ -44,6 +49,9 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
44
49
|
const [chosen, setChosen] = useState<string | null>(null);
|
|
45
50
|
const [problem, setProblem] = useState<string | null>(null);
|
|
46
51
|
const [saving, setSaving] = useState(false);
|
|
52
|
+
/** What the picker says about the suggested time: its basis, or why there is none. Cleared as soon as the editor types a time of their own. */
|
|
53
|
+
const [suggestionNote, setSuggestionNote] = useState<string | null>(null);
|
|
54
|
+
const [asking, setAsking] = useState(false);
|
|
47
55
|
const shown = optimistic ? optimistic.schedule : schedule;
|
|
48
56
|
const now = new Date();
|
|
49
57
|
const kind = shown ? scheduleKind(shown, now) : null;
|
|
@@ -52,7 +60,28 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
52
60
|
|
|
53
61
|
const open = () => {
|
|
54
62
|
const start = shown ? wallTimeOf(shown.at, zone) : wallTimeOf(new Date(Date.now() + 24 * 3_600_000).toISOString(), zone);
|
|
55
|
-
setDate(start.date); setTime(shown ? start.time : "09:00"); setChoices(null); setChosen(null); setProblem(null); setEditing(true);
|
|
63
|
+
setDate(start.date); setTime(shown ? start.time : "09:00"); setChoices(null); setChosen(null); setProblem(null); setSuggestionNote(null); setEditing(true);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Opens the picker on the suggested time, or on the time it already had with the reason there is no suggestion. The editor may pick any other time. */
|
|
67
|
+
const askForSuggestion = async () => {
|
|
68
|
+
setProblem(null); setAsking(true);
|
|
69
|
+
try {
|
|
70
|
+
const answer = await suggest();
|
|
71
|
+
if (!editing) open();
|
|
72
|
+
setChoices(null); setChosen(null);
|
|
73
|
+
if (answer.suggestion) {
|
|
74
|
+
const picked = wallTimeOf(answer.suggestion.at, zone);
|
|
75
|
+
setDate(picked.date); setTime(picked.time);
|
|
76
|
+
setSuggestionNote(SUGGESTION_BASIS);
|
|
77
|
+
} else {
|
|
78
|
+
setSuggestionNote(answer.reason ?? "No suggestion yet: this publication has no publishing history.");
|
|
79
|
+
}
|
|
80
|
+
} catch (reason) {
|
|
81
|
+
setProblem(failureText(reason));
|
|
82
|
+
} finally {
|
|
83
|
+
setAsking(false);
|
|
84
|
+
}
|
|
56
85
|
};
|
|
57
86
|
|
|
58
87
|
const apply = async (scheduledPublishAt: string | null) => {
|
|
@@ -89,7 +118,7 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
89
118
|
};
|
|
90
119
|
|
|
91
120
|
const own = shown ? ownZoneTime(shown.at, zone) : null;
|
|
92
|
-
const controlsOff = blockedReason !== null || saving;
|
|
121
|
+
const controlsOff = blockedReason !== null || saving || asking;
|
|
93
122
|
|
|
94
123
|
return <section className="story-schedule" data-story-schedule-panel aria-labelledby={`${ids}-heading`}>
|
|
95
124
|
<h3 className="story-schedule-heading" id={`${ids}-heading`}><CalendarClock aria-hidden size={15} />Schedule</h3>
|
|
@@ -100,16 +129,19 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
100
129
|
</p>
|
|
101
130
|
{own ? <p className="story-schedule-own" data-story-schedule-own>{own}</p> : null}
|
|
102
131
|
{kind === "superseded" ? <p className="story-schedule-note">A newer version was saved after this was scheduled. Schedule it again.</p> : null}
|
|
132
|
+
{shown.newerVersion && kind !== "superseded" ? <p className="story-schedule-note" data-story-schedule-newer-version>{NEWER_VERSION_NOTE}</p> : null}
|
|
133
|
+
{shown.notes?.map(note => <p className="story-schedule-note" key={note} data-story-schedule-rating-note>{note}</p>)}
|
|
103
134
|
{kind === "overdue" ? <p className="story-schedule-note">It was not published at its time. Publish it now, or pick a new time.</p> : null}
|
|
104
135
|
</div> : <p className="story-schedule-note" data-story-schedule-none>Not scheduled. Use Publish to publish now, or pick a time. Times are in {zoneCity(zone)} time.</p>}
|
|
105
136
|
{problem && !editing ? <p className="story-schedule-problem" role="alert" data-story-schedule-problem>{problem}</p> : null}
|
|
106
137
|
{editing ? <form className="story-schedule-form" data-story-schedule-form onSubmit={event => { event.preventDefault(); submit(); }}>
|
|
107
138
|
<div className="story-schedule-fields">
|
|
108
139
|
<label htmlFor={`${ids}-date`}>Date</label>
|
|
109
|
-
<input id={`${ids}-date`} type="date" value={date} onChange={event => { setDate(event.target.value); setChoices(null); setChosen(null); }} data-story-schedule-date />
|
|
140
|
+
<input id={`${ids}-date`} type="date" value={date} onChange={event => { setDate(event.target.value); setChoices(null); setChosen(null); setSuggestionNote(null); }} data-story-schedule-date />
|
|
110
141
|
<label htmlFor={`${ids}-time`}>Time ({zoneCity(zone)})</label>
|
|
111
|
-
<input id={`${ids}-time`} type="time" value={time} onChange={event => { setTime(event.target.value); setChoices(null); setChosen(null); }} data-story-schedule-time />
|
|
142
|
+
<input id={`${ids}-time`} type="time" value={time} onChange={event => { setTime(event.target.value); setChoices(null); setChosen(null); setSuggestionNote(null); }} data-story-schedule-time />
|
|
112
143
|
</div>
|
|
144
|
+
{suggestionNote ? <p className="story-schedule-note" data-story-schedule-suggestion><CalendarSearch aria-hidden size={14} />{suggestionNote}</p> : null}
|
|
113
145
|
{choices ? <fieldset className="story-schedule-choices" data-story-schedule-choices>
|
|
114
146
|
<legend>Which one?</legend>
|
|
115
147
|
{choices.map(option => <label key={option.utc}>
|
|
@@ -120,12 +152,16 @@ export function StorySchedulePanel({ zone, schedule, blockedReason, save, onChan
|
|
|
120
152
|
{problem ? <p className="story-schedule-problem" role="alert" data-story-schedule-problem>{problem}</p> : null}
|
|
121
153
|
<div className="story-schedule-buttons">
|
|
122
154
|
<button type="submit" className="story-schedule-button" disabled={saving} data-story-schedule-save><CalendarClock aria-hidden size={14} />Save schedule</button>
|
|
123
|
-
<button type="button" className="story-schedule-button" onClick={() =>
|
|
155
|
+
<button type="button" className="story-schedule-button" disabled={asking} onClick={() => void askForSuggestion()} data-story-schedule-suggest><CalendarSearch aria-hidden size={14} />Suggest a time</button>
|
|
156
|
+
<button type="button" className="story-schedule-button" onClick={() => { setEditing(false); setProblem(null); setSuggestionNote(null); }} data-story-schedule-cancel>Cancel</button>
|
|
124
157
|
</div>
|
|
125
158
|
</form> : <div className="story-schedule-buttons">
|
|
126
159
|
<button type="button" className="story-schedule-button" disabled={controlsOff} onClick={open} data-story-schedule-open>
|
|
127
160
|
{shown ? <Pencil aria-hidden size={14} /> : <CalendarClock aria-hidden size={14} />}{shown ? "Change time" : "Schedule…"}
|
|
128
161
|
</button>
|
|
162
|
+
<button type="button" className="story-schedule-button" disabled={controlsOff} onClick={() => void askForSuggestion()} data-story-schedule-suggest>
|
|
163
|
+
<CalendarSearch aria-hidden size={14} />Suggest a time
|
|
164
|
+
</button>
|
|
129
165
|
{shown ? <button type="button" className="story-schedule-button" disabled={controlsOff} onClick={() => void apply(null)} data-story-schedule-clear>
|
|
130
166
|
<CalendarX2 aria-hidden size={14} />Unschedule
|
|
131
167
|
</button> : null}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
.story-schedule-sentence{margin:0;font-size:13px}
|
|
24
24
|
.story-schedule-own{margin:0;font-size:11px;color:var(--org-muted)}
|
|
25
25
|
.story-schedule-note{margin:0;font-size:12px;color:var(--org-muted)}
|
|
26
|
+
.story-schedule-note svg{display:inline-block;vertical-align:-2px;margin-right:6px}
|
|
26
27
|
.story-schedule-problem{margin:0;padding:8px 10px;border-radius:8px;background:color-mix(in oklab,var(--org-ink) 14%,var(--org-paper));font-size:12px;font-weight:600}
|
|
27
28
|
.story-schedule-form{display:grid;gap:8px}
|
|
28
29
|
.story-schedule-fields{display:grid;grid-template-columns:auto minmax(0,1fr);gap:6px 10px;align-items:center}
|
|
@@ -48,7 +48,11 @@ export type MoveStoryStageResult = { ok: true; changed: boolean; stage: string }
|
|
|
48
48
|
* instant is UTC: the console turns the publication-zone time an editor picked into it (lib/story-schedule.ts), so the backend never has to read a wall-clock time.
|
|
49
49
|
*/
|
|
50
50
|
export type ScheduleStoryInput = { itemId: string; lineageId: string; scheduledPublishAt: string | null };
|
|
51
|
-
export type ScheduleStoryResult = {
|
|
51
|
+
export type ScheduleStoryResult = {
|
|
52
|
+
ok: true; scheduledPublishAt: string | null; scheduledBy: string | null;
|
|
53
|
+
/** What scheduling will and will not do for this Story (the backend's own words, for example for an unrated Story). */
|
|
54
|
+
notes: string[];
|
|
55
|
+
};
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* One scheduled version in the `schedule_list` answer (`story_schedule.ScheduleService.entry`). `state` is the effective state (overdue when the time passed and it
|
|
@@ -59,10 +63,19 @@ export type ScheduleEntry = {
|
|
|
59
63
|
state: "scheduled" | "publishing" | "blocked" | "overdue"; storedState: "scheduled" | "publishing" | "blocked";
|
|
60
64
|
scheduledPublishAt: string; scheduledBy: string | null; scheduledAt: string | null;
|
|
61
65
|
headItemId?: string; headVersionNumber?: number | null; newerVersionExists?: boolean;
|
|
66
|
+
/** One-Story reads only: what scheduling will and will not do for the Story's rating, in the backend's words. */
|
|
67
|
+
notes?: string[];
|
|
62
68
|
};
|
|
63
69
|
/** The `schedule_list` operation of `scheduleItem`: the schedules of one Story (`storyLineageId`), soonest first. */
|
|
64
70
|
export type ScheduleListResult = { ok: true; timeZone: string | null; schedules: ScheduleEntry[] };
|
|
65
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The `schedule_suggest` operation of `scheduleItem`: the next time to schedule a Story, learned from the publication's own history of first publications
|
|
74
|
+
* (`publication_cadence.py`), or `suggestion: null` with the reason when the publication has no history yet. `storyLineageId` leaves that Story's own schedule out.
|
|
75
|
+
*/
|
|
76
|
+
export type ScheduleSuggestion = { at: string; local: string; label: string; zone: string; publications: number; meanGapHours: number; latestScheduledAt: string | null };
|
|
77
|
+
export type ScheduleSuggestResult = { ok: true; suggestion: ScheduleSuggestion | null; reason: string | null; timeZone: string | null };
|
|
78
|
+
|
|
66
79
|
/** The `schedule_settings` operation of `scheduleItem`: whether scheduling is on and the publication's time zone, which the backend owns (docs/scheduled-publishing.md). */
|
|
67
80
|
export type ScheduleZoneResult = { ok: true; enabled: boolean; timeZone: string | null };
|
|
68
81
|
|
|
@@ -175,13 +188,17 @@ export function createContentActionsClient(transport: ContentActionsTransport) {
|
|
|
175
188
|
const operation = input.scheduledPublishAt === null
|
|
176
189
|
? { operation: "schedule", arguments: { storyLineageId: input.lineageId, clear: true } }
|
|
177
190
|
: { operation: "schedule", arguments: { itemId: input.itemId, at: input.scheduledPublishAt } };
|
|
178
|
-
const result = parseActionResponse<{ scheduledPublishAt?: string; scheduledBy?: string }>(await transport.mutations.scheduleItem({ input: JSON.stringify(operation) }, USER_POOL));
|
|
179
|
-
return { ok: true, scheduledPublishAt: result.scheduledPublishAt ?? null, scheduledBy: result.scheduledBy ?? null };
|
|
191
|
+
const result = parseActionResponse<{ scheduledPublishAt?: string; scheduledBy?: string; notes?: string[] }>(await transport.mutations.scheduleItem({ input: JSON.stringify(operation) }, USER_POOL));
|
|
192
|
+
return { ok: true, scheduledPublishAt: result.scheduledPublishAt ?? null, scheduledBy: result.scheduledBy ?? null, notes: result.notes ?? [] };
|
|
180
193
|
},
|
|
181
194
|
async scheduleList(input: { storyLineageId: string }): Promise<ScheduleListResult> {
|
|
182
195
|
const result = parseActionResponse<{ timeZone?: string | null; schedules?: ScheduleEntry[] }>(await transport.mutations.scheduleItem({ input: JSON.stringify({ operation: "schedule_list", arguments: { storyLineageId: input.storyLineageId } }) }, USER_POOL));
|
|
183
196
|
return { ok: true, timeZone: result.timeZone ?? null, schedules: result.schedules ?? [] };
|
|
184
197
|
},
|
|
198
|
+
async scheduleSuggest(input: { storyLineageId?: string }): Promise<ScheduleSuggestResult> {
|
|
199
|
+
const result = parseActionResponse<{ suggestion?: ScheduleSuggestion | null; reason?: string | null; timeZone?: string | null }>(await transport.mutations.scheduleItem({ input: JSON.stringify({ operation: "schedule_suggest", arguments: input.storyLineageId ? { storyLineageId: input.storyLineageId } : {} }) }, USER_POOL));
|
|
200
|
+
return { ok: true, suggestion: result.suggestion ?? null, reason: result.reason ?? null, timeZone: result.timeZone ?? null };
|
|
201
|
+
},
|
|
185
202
|
async scheduleZone(): Promise<ScheduleZoneResult> {
|
|
186
203
|
const result = parseActionResponse<{ enabled: boolean; timeZone?: string | null }>(await transport.mutations.scheduleItem({ input: JSON.stringify({ operation: "schedule_settings", arguments: {} }) }, USER_POOL));
|
|
187
204
|
return { ok: true, enabled: result.enabled, timeZone: result.timeZone ?? null };
|
|
@@ -215,6 +232,7 @@ export const createStoryFromReference = (input: CreateStoryFromReferenceInput) =
|
|
|
215
232
|
export const moveStoryStage = (input: MoveStoryStageInput) => contentActionsClient().moveStoryStage(input);
|
|
216
233
|
export const scheduleStory = (input: ScheduleStoryInput) => contentActionsClient().scheduleStory(input);
|
|
217
234
|
export const scheduleList = (input: { storyLineageId: string }) => contentActionsClient().scheduleList(input);
|
|
235
|
+
export const scheduleSuggest = (input: { storyLineageId?: string }) => contentActionsClient().scheduleSuggest(input);
|
|
218
236
|
export const scheduleZone = () => contentActionsClient().scheduleZone();
|
|
219
237
|
export const setStoryStep = (input: SetStoryStepInput) => contentActionsClient().setStoryStep(input);
|
|
220
238
|
export const unpublishItem = (id: string) => contentActionsClient().unpublishItem(id);
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
ScheduleStoryInput,
|
|
14
14
|
ScheduleListResult,
|
|
15
15
|
ScheduleStoryResult,
|
|
16
|
+
ScheduleSuggestResult,
|
|
16
17
|
CreateStoryFromReferenceInput,
|
|
17
18
|
CreateStoryFromReferenceResult,
|
|
18
19
|
} from "./content-actions-client";
|
|
@@ -22,9 +23,9 @@ import {
|
|
|
22
23
|
demoContentHash,
|
|
23
24
|
type DemoArticleRecord,
|
|
24
25
|
} from "./newsroom-demo-articles";
|
|
25
|
-
import { createLocalPreviewEditableArticle, lineageForPreviewVersion, localPreviewScheduleFields, recordLocalPreviewDesk, recordLocalPreviewVersion, setLocalPreviewSchedule } from "./local-preview-seed";
|
|
26
|
+
import { createLocalPreviewEditableArticle, lineageForPreviewVersion, localPreviewScheduleFields, localPreviewSuggestedTime, recordLocalPreviewDesk, recordLocalPreviewVersion, setLocalPreviewSchedule } from "./local-preview-seed";
|
|
26
27
|
import { createDemoAnnouncementsDoor } from "./announcements-demo";
|
|
27
|
-
import { scheduleFromFields } from "./story-schedule";
|
|
28
|
+
import { UNRATED_NOTE, scheduleFromFields } from "./story-schedule";
|
|
28
29
|
import { LOCAL_PREVIEW_TIME_ZONE } from "./schedule-zone";
|
|
29
30
|
import { sourceLineOffset, type ArticlesBackend, type EditableArticle, type NewsroomArticleRow } from "./newsroom-articles";
|
|
30
31
|
|
|
@@ -112,6 +113,13 @@ export function createDemoArticlesBackend(): ArticlesBackend {
|
|
|
112
113
|
return record;
|
|
113
114
|
};
|
|
114
115
|
|
|
116
|
+
/** What scheduling will and will not do for a Story with no rating, as the backend words it: the preview reads the sample Story's rating. */
|
|
117
|
+
const unratedNotes = (itemId: string): string[] => {
|
|
118
|
+
loadPreviewRecord(itemId);
|
|
119
|
+
const record = records.get(itemId);
|
|
120
|
+
return record && !record.starRating ? [UNRATED_NOTE] : [];
|
|
121
|
+
};
|
|
122
|
+
|
|
115
123
|
return {
|
|
116
124
|
actions: {
|
|
117
125
|
async deriveMarkus(input: DeriveMarkusInput): Promise<DeriveMarkusResult> {
|
|
@@ -235,7 +243,7 @@ export function createDemoArticlesBackend(): ArticlesBackend {
|
|
|
235
243
|
async scheduleStory(input: ScheduleStoryInput): Promise<ScheduleStoryResult> {
|
|
236
244
|
try {
|
|
237
245
|
const fields = setLocalPreviewSchedule(input.lineageId, input.scheduledPublishAt);
|
|
238
|
-
return { ok: true, scheduledPublishAt: fields.scheduledPublishAt ?? null, scheduledBy: fields.scheduledBy ?? null };
|
|
246
|
+
return { ok: true, scheduledPublishAt: fields.scheduledPublishAt ?? null, scheduledBy: fields.scheduledBy ?? null, notes: fields.scheduledPublishAt ? unratedNotes(input.itemId) : [] };
|
|
239
247
|
} catch (error) {
|
|
240
248
|
throw new ContentActionFailure([{ code: "schedule-refused", message: error instanceof Error ? error.message : String(error), line: null }]);
|
|
241
249
|
}
|
|
@@ -247,10 +255,15 @@ export function createDemoArticlesBackend(): ArticlesBackend {
|
|
|
247
255
|
ok: true, timeZone: LOCAL_PREVIEW_TIME_ZONE,
|
|
248
256
|
schedules: schedule ? [{
|
|
249
257
|
itemId: input.storyLineageId, lineageId: input.storyLineageId, versionNumber: null, title: "", state: schedule.state, storedState: schedule.state,
|
|
250
|
-
scheduledPublishAt: schedule.at, scheduledBy: schedule.by, scheduledAt: schedule.scheduledAt,
|
|
258
|
+
scheduledPublishAt: schedule.at, scheduledBy: schedule.by, scheduledAt: schedule.scheduledAt, notes: unratedNotes(input.storyLineageId.replace("-lineage-", "-version-")),
|
|
251
259
|
}] : [],
|
|
252
260
|
};
|
|
253
261
|
},
|
|
262
|
+
async scheduleSuggest(input: { storyLineageId?: string }): Promise<ScheduleSuggestResult> {
|
|
263
|
+
// The preview has no publishing history to learn from: it stands in for a publication that publishes on weekday mornings.
|
|
264
|
+
const picked = localPreviewSuggestedTime(LOCAL_PREVIEW_TIME_ZONE, input.storyLineageId);
|
|
265
|
+
return { ok: true, suggestion: { at: picked, local: picked, label: picked, zone: LOCAL_PREVIEW_TIME_ZONE, publications: 0, meanGapHours: 0, latestScheduledAt: null }, reason: null, timeZone: LOCAL_PREVIEW_TIME_ZONE };
|
|
266
|
+
},
|
|
254
267
|
async moveStoryStage(input: MoveStoryStageInput): Promise<MoveStoryStageResult> {
|
|
255
268
|
return { ok: true, changed: true, stage: input.stage };
|
|
256
269
|
},
|
|
@@ -45,6 +45,8 @@ export type ImageOperationName =
|
|
|
45
45
|
| "announcements_review_set"
|
|
46
46
|
| "announcements_delivery_review_set"
|
|
47
47
|
| "announcements_draft"
|
|
48
|
+
| "announcements_candidate_choose"
|
|
49
|
+
| "announcements_versions"
|
|
48
50
|
| "announcements_pinned_change"
|
|
49
51
|
| "announcements_release"
|
|
50
52
|
| "announcements_unlock"
|
|
@@ -78,6 +80,7 @@ export type ImageErrorCode =
|
|
|
78
80
|
| "spend_ceiling_exceeded"
|
|
79
81
|
| "batch_expired"
|
|
80
82
|
| "stale_version"
|
|
83
|
+
| "locked"
|
|
81
84
|
| "candidate_not_ready"
|
|
82
85
|
| "candidate_closed"
|
|
83
86
|
| "settings_refused"
|
|
@@ -1135,6 +1138,16 @@ export type AnnouncementsSettingsShowResult = {
|
|
|
1135
1138
|
spacing?: Record<string, unknown>;
|
|
1136
1139
|
/** paused, reason (budget, disconnected or manual), detail, by and at. */
|
|
1137
1140
|
pause?: Record<string, unknown>;
|
|
1141
|
+
editWindows?: {
|
|
1142
|
+
/** The kind of Announcement, such as story_published or roundup. Absent: every kind. */
|
|
1143
|
+
kind?: string;
|
|
1144
|
+
/** The channel, such as x or email. Absent: every channel. */
|
|
1145
|
+
channel?: string;
|
|
1146
|
+
/** Minutes from the Delivery's creation to its release: how long it stays a draft that people edit. */
|
|
1147
|
+
windowMinutes: number;
|
|
1148
|
+
/** Minutes before the release that the Delivery locks for the send job. At most the window; 0 is no separate lock. */
|
|
1149
|
+
lockLeadMinutes?: number;
|
|
1150
|
+
}[];
|
|
1138
1151
|
};
|
|
1139
1152
|
/** The X connection's status: connection, handle, accountId and refresh health. Never a secret. */
|
|
1140
1153
|
connection: Record<string, unknown>;
|
|
@@ -1162,6 +1175,17 @@ export type AnnouncementsSettingsSetInput = {
|
|
|
1162
1175
|
labelConfirmed?: boolean;
|
|
1163
1176
|
/** Minutes between one post and the next on a channel account, by account (<channel>#<account>, such as x#handle). A number sets it, null takes it away; an account that is not named keeps what it has. Empty by default: no spacing. */
|
|
1164
1177
|
spacing?: Record<string, unknown>;
|
|
1178
|
+
/** How long a Delivery stays a draft that people edit, and how long before its release it locks, for each kind of Announcement and channel. The narrowest entry that fits wins. This replaces the whole list; an empty list means no window. */
|
|
1179
|
+
editWindows?: {
|
|
1180
|
+
/** The kind of Announcement, such as story_published or roundup. Absent: every kind. */
|
|
1181
|
+
kind?: string;
|
|
1182
|
+
/** The channel, such as x or email. Absent: every channel. */
|
|
1183
|
+
channel?: string;
|
|
1184
|
+
/** Minutes from the Delivery's creation to its release: how long it stays a draft that people edit. */
|
|
1185
|
+
windowMinutes: number;
|
|
1186
|
+
/** Minutes before the release that the Delivery locks for the send job. At most the window; 0 is no separate lock. */
|
|
1187
|
+
lockLeadMinutes?: number;
|
|
1188
|
+
}[];
|
|
1165
1189
|
};
|
|
1166
1190
|
|
|
1167
1191
|
export type AnnouncementsSettingsSetResult = {
|
|
@@ -1179,6 +1203,16 @@ export type AnnouncementsSettingsSetResult = {
|
|
|
1179
1203
|
spacing?: Record<string, unknown>;
|
|
1180
1204
|
/** paused, reason (budget, disconnected or manual), detail, by and at. */
|
|
1181
1205
|
pause?: Record<string, unknown>;
|
|
1206
|
+
editWindows?: {
|
|
1207
|
+
/** The kind of Announcement, such as story_published or roundup. Absent: every kind. */
|
|
1208
|
+
kind?: string;
|
|
1209
|
+
/** The channel, such as x or email. Absent: every channel. */
|
|
1210
|
+
channel?: string;
|
|
1211
|
+
/** Minutes from the Delivery's creation to its release: how long it stays a draft that people edit. */
|
|
1212
|
+
windowMinutes: number;
|
|
1213
|
+
/** Minutes before the release that the Delivery locks for the send job. At most the window; 0 is no separate lock. */
|
|
1214
|
+
lockLeadMinutes?: number;
|
|
1215
|
+
}[];
|
|
1182
1216
|
};
|
|
1183
1217
|
released: Record<string, unknown>[];
|
|
1184
1218
|
};
|
|
@@ -1253,24 +1287,113 @@ export type AnnouncementsDeliveryReviewSetResult = {
|
|
|
1253
1287
|
approvedBy?: string | null;
|
|
1254
1288
|
};
|
|
1255
1289
|
|
|
1256
|
-
/**
|
|
1290
|
+
/** Save a Delivery's words as the next version, or keep a text or picture beside the draft as a candidate. */
|
|
1257
1291
|
export type AnnouncementsDraftInput = {
|
|
1258
1292
|
/** The Delivery's id. */
|
|
1259
1293
|
delivery: string;
|
|
1294
|
+
/** The version of the Delivery you read. Refused as stale_version, naming the version that replaced it, when the Delivery has moved on. */
|
|
1295
|
+
replaces?: number;
|
|
1296
|
+
/** The words. A person's save marks the blocks it changed as theirs and pinned; an agent's redraft keeps every pinned block as it is. */
|
|
1297
|
+
text?: string;
|
|
1298
|
+
/** The picture of the version, or of the candidate. */
|
|
1299
|
+
imageKey?: string;
|
|
1300
|
+
/** Keep this text or picture beside the draft as a candidate (nothing goes out differently) instead of saving a version. No replaces is needed. */
|
|
1301
|
+
candidate?: boolean;
|
|
1260
1302
|
};
|
|
1261
1303
|
|
|
1262
1304
|
export type AnnouncementsDraftResult = {
|
|
1263
1305
|
id: string;
|
|
1306
|
+
/** saved: a new version. preferred: saved while an attempt is open, so it never changes that attempt. unchanged: the words are the ones you read. dropped: a machine's redraft that the person's newer version outranks. candidate: kept beside the draft. */
|
|
1307
|
+
status: "saved" | "preferred" | "unchanged" | "dropped" | "candidate";
|
|
1308
|
+
version?: number;
|
|
1309
|
+
replaces?: number | null;
|
|
1310
|
+
reason?: string;
|
|
1311
|
+
/** The candidate's id, when one was kept. */
|
|
1312
|
+
candidate?: string;
|
|
1313
|
+
approvedVersion?: number | null;
|
|
1314
|
+
lockedVersion?: number | null;
|
|
1315
|
+
preferredVersion?: number | null;
|
|
1316
|
+
/** Each block's owner (human or machine) and whether it is pinned. */
|
|
1317
|
+
blocks?: Record<string, unknown>[];
|
|
1264
1318
|
};
|
|
1265
1319
|
|
|
1266
|
-
/**
|
|
1320
|
+
/** Choose one candidate as the Delivery's words: a new version. The other candidates are kept. */
|
|
1321
|
+
export type AnnouncementsCandidateChooseInput = {
|
|
1322
|
+
/** The Delivery's id. */
|
|
1323
|
+
delivery: string;
|
|
1324
|
+
/** The candidate's id, such as c1. */
|
|
1325
|
+
candidate: string;
|
|
1326
|
+
/** The version of the Delivery you read. */
|
|
1327
|
+
replaces: number;
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
export type AnnouncementsCandidateChooseResult = {
|
|
1331
|
+
id: string;
|
|
1332
|
+
/** saved: a new version. preferred: saved while an attempt is open, so it never changes that attempt. unchanged: the words are the ones you read. dropped: a machine's redraft that the person's newer version outranks. candidate: kept beside the draft. */
|
|
1333
|
+
status: "saved" | "preferred" | "unchanged" | "dropped" | "candidate";
|
|
1334
|
+
version?: number;
|
|
1335
|
+
replaces?: number | null;
|
|
1336
|
+
reason?: string;
|
|
1337
|
+
/** The candidate's id, when one was kept. */
|
|
1338
|
+
candidate?: string;
|
|
1339
|
+
approvedVersion?: number | null;
|
|
1340
|
+
lockedVersion?: number | null;
|
|
1341
|
+
preferredVersion?: number | null;
|
|
1342
|
+
/** Each block's owner (human or machine) and whether it is pinned. */
|
|
1343
|
+
blocks?: Record<string, unknown>[];
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
/** List a Delivery's versions and candidates: who saved each, when, what it replaced and which blocks are pinned. With a version or a candidate, its words. */
|
|
1347
|
+
export type AnnouncementsVersionsInput = {
|
|
1348
|
+
/** The Delivery's id. */
|
|
1349
|
+
delivery: string;
|
|
1350
|
+
/** Show the words of this version. */
|
|
1351
|
+
version?: number;
|
|
1352
|
+
/** Show the words of this candidate. */
|
|
1353
|
+
candidate?: string;
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
export type AnnouncementsVersionsResult = {
|
|
1357
|
+
id: string;
|
|
1358
|
+
version: number;
|
|
1359
|
+
approvedVersion?: number | null;
|
|
1360
|
+
lockedVersion?: number | null;
|
|
1361
|
+
lockedAt?: string | null;
|
|
1362
|
+
preferredVersion?: number | null;
|
|
1363
|
+
versions: Record<string, unknown>[];
|
|
1364
|
+
candidates: Record<string, unknown>[];
|
|
1365
|
+
/** The words asked for. */
|
|
1366
|
+
text?: string;
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1369
|
+
/** Change or unpin a block a person pinned, as the next version. */
|
|
1267
1370
|
export type AnnouncementsPinnedChangeInput = {
|
|
1268
1371
|
/** The Delivery's id. */
|
|
1269
1372
|
delivery: string;
|
|
1373
|
+
/** The version of the Delivery you read. */
|
|
1374
|
+
replaces: number;
|
|
1375
|
+
/** The block, counting from 1. */
|
|
1376
|
+
block: number;
|
|
1377
|
+
/** The block's new words, one paragraph. It stays pinned. */
|
|
1378
|
+
text?: string;
|
|
1379
|
+
/** Unpin the block, so a later redraft may rewrite it. */
|
|
1380
|
+
unpin?: boolean;
|
|
1270
1381
|
};
|
|
1271
1382
|
|
|
1272
1383
|
export type AnnouncementsPinnedChangeResult = {
|
|
1273
1384
|
id: string;
|
|
1385
|
+
/** saved: a new version. preferred: saved while an attempt is open, so it never changes that attempt. unchanged: the words are the ones you read. dropped: a machine's redraft that the person's newer version outranks. candidate: kept beside the draft. */
|
|
1386
|
+
status: "saved" | "preferred" | "unchanged" | "dropped" | "candidate";
|
|
1387
|
+
version?: number;
|
|
1388
|
+
replaces?: number | null;
|
|
1389
|
+
reason?: string;
|
|
1390
|
+
/** The candidate's id, when one was kept. */
|
|
1391
|
+
candidate?: string;
|
|
1392
|
+
approvedVersion?: number | null;
|
|
1393
|
+
lockedVersion?: number | null;
|
|
1394
|
+
preferredVersion?: number | null;
|
|
1395
|
+
/** Each block's owner (human or machine) and whether it is pinned. */
|
|
1396
|
+
blocks?: Record<string, unknown>[];
|
|
1274
1397
|
};
|
|
1275
1398
|
|
|
1276
1399
|
/** Release a Delivery: hand it to its channel now. */
|
|
@@ -1287,10 +1410,17 @@ export type AnnouncementsReleaseResult = {
|
|
|
1287
1410
|
export type AnnouncementsUnlockInput = {
|
|
1288
1411
|
/** The Delivery's id. */
|
|
1289
1412
|
delivery: string;
|
|
1413
|
+
/** When it locks again (UTC), after now and no later than the release. By default the release time. */
|
|
1414
|
+
lockAt?: string;
|
|
1415
|
+
/** A new release time (UTC), when the old one has passed. */
|
|
1416
|
+
releaseAt?: string;
|
|
1290
1417
|
};
|
|
1291
1418
|
|
|
1292
1419
|
export type AnnouncementsUnlockResult = {
|
|
1293
1420
|
id: string;
|
|
1421
|
+
lockAt: string;
|
|
1422
|
+
releaseAt: string;
|
|
1423
|
+
lockedVersion?: number | null;
|
|
1294
1424
|
};
|
|
1295
1425
|
|
|
1296
1426
|
/** Correct a Delivery that went with a new public text: the next generation, which supersedes the one that went. */
|
|
@@ -1586,6 +1716,8 @@ export interface ImageOperations {
|
|
|
1586
1716
|
announcements_review_set: { input: AnnouncementsReviewSetInput; result: AnnouncementsReviewSetResult };
|
|
1587
1717
|
announcements_delivery_review_set: { input: AnnouncementsDeliveryReviewSetInput; result: AnnouncementsDeliveryReviewSetResult };
|
|
1588
1718
|
announcements_draft: { input: AnnouncementsDraftInput; result: AnnouncementsDraftResult };
|
|
1719
|
+
announcements_candidate_choose: { input: AnnouncementsCandidateChooseInput; result: AnnouncementsCandidateChooseResult };
|
|
1720
|
+
announcements_versions: { input: AnnouncementsVersionsInput; result: AnnouncementsVersionsResult };
|
|
1589
1721
|
announcements_pinned_change: { input: AnnouncementsPinnedChangeInput; result: AnnouncementsPinnedChangeResult };
|
|
1590
1722
|
announcements_release: { input: AnnouncementsReleaseInput; result: AnnouncementsReleaseResult };
|
|
1591
1723
|
announcements_unlock: { input: AnnouncementsUnlockInput; result: AnnouncementsUnlockResult };
|
|
@@ -1642,6 +1774,8 @@ export const IMAGE_OPERATIONS = {
|
|
|
1642
1774
|
announcements_review_set: { effect: "write", agentAllowed: false, agentRung: "person", agentRefusal: "blocked", group: "announcements", command: "papyrus announcements review set" },
|
|
1643
1775
|
announcements_delivery_review_set: { effect: "write", agentAllowed: false, agentRung: "person", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements delivery review" },
|
|
1644
1776
|
announcements_draft: { effect: "write", agentAllowed: true, agentRung: "draft", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements draft" },
|
|
1777
|
+
announcements_candidate_choose: { effect: "write", agentAllowed: true, agentRung: "draft", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements candidate choose" },
|
|
1778
|
+
announcements_versions: { effect: "read", agentAllowed: true, agentRung: "observe", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements versions" },
|
|
1645
1779
|
announcements_pinned_change: { effect: "write", agentAllowed: false, agentRung: "person", agentRefusal: "blocked", group: "announcements", command: "papyrus announcements pinned" },
|
|
1646
1780
|
announcements_release: { effect: "write", agentAllowed: true, agentRung: "publish_auto", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements release" },
|
|
1647
1781
|
announcements_unlock: { effect: "write", agentAllowed: false, agentRung: "person", agentRefusal: "human_required", group: "announcements", command: "papyrus announcements unlock" },
|
|
@@ -9,7 +9,7 @@ import { contentItemHeadStageKey, contentItemStageKeys, type ContentItemVersionR
|
|
|
9
9
|
import { getContentItemStageDefinitions } from "./site-brand";
|
|
10
10
|
import { noteProblem, stepChangeProblem, summarizeStoryChecklist, type StoryStepNote, type StoryStepRecord } from "./story-checklist";
|
|
11
11
|
import { LOCAL_PREVIEW_TENANTS, getLocalPreviewTenantId } from "./local-preview-tenant";
|
|
12
|
-
import type
|
|
12
|
+
import { resolveWallTime, wallTimeOf, type ScheduleFields } from "./story-schedule";
|
|
13
13
|
import type { PublishedStoryRow } from "./story-schedule-query";
|
|
14
14
|
|
|
15
15
|
const SEED_TIMESTAMP_BASE = Date.parse("2026-10-01T12:00:00.000Z");
|
|
@@ -206,6 +206,27 @@ export function setLocalPreviewSchedule(lineageId: string, scheduledPublishAt: s
|
|
|
206
206
|
return fields ?? {};
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* What the preview says when an editor asks for a suggested time. The preview has no history to learn from, so it stands in for a publication that publishes on weekday
|
|
211
|
+
* mornings: 9:00 in the publication's zone on the first weekday after now and after the latest scheduled sample Story plus a day. (The real backend learns the hours
|
|
212
|
+
* and the gap from the publication's own first publications: src/papyrus_content/publication_cadence.py.)
|
|
213
|
+
*/
|
|
214
|
+
export function localPreviewSuggestedTime(zone: string, ownLineageId: string | undefined, now: Date = new Date()): string {
|
|
215
|
+
const latest = createLocalPreviewContentItemVersions()
|
|
216
|
+
.filter(version => version.lineageId !== ownLineageId && version.scheduledPublishAt && (version.scheduleState === "scheduled" || version.scheduleState === "publishing"))
|
|
217
|
+
.map(version => Date.parse(version.scheduledPublishAt!))
|
|
218
|
+
.reduce((most, at) => Math.max(most, at), 0);
|
|
219
|
+
const after = Math.max(now.getTime(), latest ? latest + DAY : 0);
|
|
220
|
+
for (let offset = 0; offset < 14; offset += 1) {
|
|
221
|
+
const day = wallTimeOf(new Date(now.getTime() + offset * DAY).toISOString(), zone).date;
|
|
222
|
+
const weekday = new Date(`${day}T12:00:00Z`).getUTCDay();
|
|
223
|
+
if (weekday === 0 || weekday === 6) continue;
|
|
224
|
+
const resolved = resolveWallTime(day, "09:00", zone);
|
|
225
|
+
if (resolved.kind === "ok" && Date.parse(resolved.utc) > after) return resolved.utc;
|
|
226
|
+
}
|
|
227
|
+
throw new Error("The preview found no weekday morning in the next two weeks.");
|
|
228
|
+
}
|
|
229
|
+
|
|
209
230
|
export function resetLocalPreviewSchedules(): void {
|
|
210
231
|
previewScheduleChanges.clear();
|
|
211
232
|
previewScheduleTouchedAt.clear();
|
package/lib/newsroom-articles.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
moveStoryStage,
|
|
9
9
|
scheduleStory,
|
|
10
10
|
scheduleList,
|
|
11
|
+
scheduleSuggest,
|
|
11
12
|
createStoryFromReference,
|
|
12
13
|
type ContentActionError,
|
|
13
14
|
} from "./content-actions-client";
|
|
@@ -107,6 +108,8 @@ export type ArticlesBackend = {
|
|
|
107
108
|
scheduleStory: typeof scheduleStory;
|
|
108
109
|
/** The Story's schedules (the `schedule_list` operation): the drawer shows what the backend says, not what the loaded row happens to hold. */
|
|
109
110
|
scheduleList: typeof scheduleList;
|
|
111
|
+
/** The next time the publication's own rhythm suggests for a Story (the `schedule_suggest` operation), or why there is none. */
|
|
112
|
+
scheduleSuggest: typeof scheduleSuggest;
|
|
110
113
|
createStoryFromReference: typeof createStoryFromReference;
|
|
111
114
|
/** Saves an editor's rating of a Story (any version id of it; null clears it). A plain update: no new version, nothing republished. */
|
|
112
115
|
setItemStars: (itemId: string, stars: number | null) => Promise<void>;
|
|
@@ -351,7 +354,7 @@ export function createLiveArticlesBackend(): ArticlesBackend {
|
|
|
351
354
|
return client;
|
|
352
355
|
};
|
|
353
356
|
return {
|
|
354
|
-
actions: { deriveMarkus, saveItemDraft, publishItem, unpublishItem, moveStoryStage, scheduleStory, scheduleList, createStoryFromReference, setItemStars },
|
|
357
|
+
actions: { deriveMarkus, saveItemDraft, publishItem, unpublishItem, moveStoryStage, scheduleStory, scheduleList, scheduleSuggest, createStoryFromReference, setItemStars },
|
|
355
358
|
listRows: () => loadArticleRows(dataClient()),
|
|
356
359
|
loadArticle: (id) => loadEditableArticle(dataClient(), id),
|
|
357
360
|
announcementsDoor,
|
package/lib/story-schedule.ts
CHANGED
|
@@ -27,6 +27,10 @@ export type StorySchedule = {
|
|
|
27
27
|
state: ScheduleState;
|
|
28
28
|
by: string | null;
|
|
29
29
|
scheduledAt: string | null;
|
|
30
|
+
/** What scheduling will and will not do for the Story's rating, in the backend's words (an unrated Story is not listed or announced until it is rated). */
|
|
31
|
+
notes?: string[];
|
|
32
|
+
/** A newer version of the Story exists than the one that is scheduled: the schedule will not publish, and the editor is told as soon as the version is saved. */
|
|
33
|
+
newerVersion?: boolean;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
export function scheduleFromFields(fields: ScheduleFields): StorySchedule | undefined {
|
|
@@ -40,16 +44,25 @@ export function scheduleFromFields(fields: ScheduleFields): StorySchedule | unde
|
|
|
40
44
|
* The schedule the drawer shows for a Story, from its `schedule_list` answer: the newest scheduled version, since a schedule that sits on an earlier version
|
|
41
45
|
* is the one a newer save superseded. The state is the stored one; Overdue is derived from the time (`scheduleKind`), as the backend derives it.
|
|
42
46
|
*/
|
|
43
|
-
export function scheduleFromEntries(entries: readonly { versionNumber: number | null; storedState: string; scheduledPublishAt: string; scheduledBy: string | null; scheduledAt: string | null }[]): StorySchedule | undefined {
|
|
47
|
+
export function scheduleFromEntries(entries: readonly { versionNumber: number | null; storedState: string; scheduledPublishAt: string; scheduledBy: string | null; scheduledAt: string | null; newerVersionExists?: boolean; notes?: string[] }[]): StorySchedule | undefined {
|
|
44
48
|
const newest = [...entries].sort((left, right) => (right.versionNumber ?? 0) - (left.versionNumber ?? 0))[0];
|
|
45
|
-
|
|
49
|
+
const found = newest ? scheduleFromFields({ scheduledPublishAt: newest.scheduledPublishAt, scheduleState: newest.storedState, scheduledBy: newest.scheduledBy, scheduledAt: newest.scheduledAt }) : undefined;
|
|
50
|
+
return found ? { ...found, notes: newest.notes ?? [], newerVersion: newest.newerVersionExists === true } : undefined;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/** The schedule a successful `schedule` call recorded: none after a clear, else scheduled for the instant that was sent. */
|
|
49
|
-
export function scheduleFromResult(result: { scheduledPublishAt: string | null; scheduledBy: string | null }, at: Date = new Date()): StorySchedule | undefined {
|
|
50
|
-
return result.scheduledPublishAt ? { at: result.scheduledPublishAt, state: "scheduled", by: result.scheduledBy, scheduledAt: at.toISOString() } : undefined;
|
|
54
|
+
export function scheduleFromResult(result: { scheduledPublishAt: string | null; scheduledBy: string | null; notes?: string[] }, at: Date = new Date()): StorySchedule | undefined {
|
|
55
|
+
return result.scheduledPublishAt ? { at: result.scheduledPublishAt, state: "scheduled", by: result.scheduledBy, scheduledAt: at.toISOString(), notes: result.notes ?? [], newerVersion: false } : undefined;
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
/** What scheduling does for a Story with no rating: the backend's sentence (`story_schedule.UNRATED_NOTE`), which the local preview repeats for its sample Stories. */
|
|
59
|
+
export const UNRATED_NOTE = "Unrated: it will publish but will not be listed or announced until it is rated.";
|
|
60
|
+
|
|
61
|
+
/** Said under the schedule when a newer version of the Story exists than the one that is scheduled. */
|
|
62
|
+
export const NEWER_VERSION_NOTE = "A newer version exists than the one scheduled";
|
|
63
|
+
/** Said in the form beside a suggested time. A publication with no history to suggest from is told why in the backend's own sentence (`publication_cadence.NO_HISTORY`). */
|
|
64
|
+
export const SUGGESTION_BASIS = "Suggested from this publication's usual publishing times. Pick any other time if you prefer.";
|
|
65
|
+
|
|
53
66
|
/**
|
|
54
67
|
* What a reader sees. A time that has passed while the version is still scheduled or being published is Overdue (derived, as the backend derives it); a blocked
|
|
55
68
|
* schedule is Superseded: a newer version was saved after it was scheduled.
|
package/package.json
CHANGED
package/routes.manifest.json
CHANGED