@anthusai/papyrus 1.0.0-next.2 → 1.0.0-next.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.
Files changed (139) hide show
  1. package/amplify/auth/resource.js +17 -4
  2. package/amplify/auth/resource.ts +21 -4
  3. package/amplify/data/resource.js +52 -70
  4. package/amplify/data/resource.ts +57 -70
  5. package/amplify/data/schema.js +52 -58
  6. package/amplify/data/schema.ts +57 -58
  7. package/amplify/functions/console-chat-responder/py/execute_tactus_runner.py +0 -10
  8. package/amplify/functions/console-chat-responder/resource.js +0 -7
  9. package/amplify/functions/console-chat-responder/resource.ts +0 -8
  10. package/amplify/functions/console-chat-responder/src/main.rs +0 -9
  11. package/amplify/functions/content-actions/handler.py +149 -0
  12. package/amplify/functions/content-actions/requirements.txt +4 -0
  13. package/amplify/functions/content-actions/resource.js +40 -0
  14. package/amplify/functions/content-actions/resource.ts +54 -0
  15. package/amplify/functions/shared/python-bundle.js +17 -2
  16. package/amplify/functions/shared/python-bundle.ts +23 -2
  17. package/amplify/rebuild-trigger-settings.js +22 -0
  18. package/amplify/rebuild-trigger-settings.ts +42 -0
  19. package/amplify/site-backend-config.ts +12 -1
  20. package/amplify/site-backend.js +51 -27
  21. package/amplify/site-backend.ts +66 -34
  22. package/amplify/storage/resource.js +3 -0
  23. package/amplify/storage/resource.ts +3 -0
  24. package/app/%5F_preview/[[...path]]/route.ts +8 -0
  25. package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +4 -2
  26. package/app/[year]/[month]/[day]/edition-route-page.tsx +2 -0
  27. package/app/api/revalidate/route.ts +8 -7
  28. package/app/articles/[slug]/page.tsx +3 -1
  29. package/app/blog-rhythm.css +278 -0
  30. package/app/globals.css +22 -4
  31. package/app/layout.tsx +24 -12
  32. package/app/newsroom/articles/[id]/page.tsx +15 -0
  33. package/app/newsroom/articles/page.tsx +13 -0
  34. package/app/page.tsx +12 -4
  35. package/app/robots.ts +11 -0
  36. package/bin/papyrus-app.mjs +12 -2
  37. package/bin/papyrus-infra.mjs +74 -18
  38. package/components/archive-shell.tsx +2 -22
  39. package/components/article-video.tsx +247 -3
  40. package/components/blog-page-background.tsx +23 -6
  41. package/components/markus-ir-preview.tsx +300 -0
  42. package/components/news-desk-page.tsx +1 -4
  43. package/components/newspaper.tsx +2 -1
  44. package/components/newsroom-access-gate.tsx +66 -0
  45. package/components/newsroom-article-editor.tsx +741 -0
  46. package/components/newsroom-articles-view.tsx +129 -0
  47. package/components/newsroom-ops-overview.tsx +28 -11
  48. package/components/newsroom-ops-shell.tsx +3 -1
  49. package/components/pictogram-figure.tsx +9 -2
  50. package/components/presentation-header.tsx +135 -0
  51. package/components/presentation-rhythm-hrule.tsx +17 -0
  52. package/components/settings-page.tsx +2 -1
  53. package/components/staging-banner.tsx +11 -0
  54. package/components/topic-steering-workspace.tsx +1 -59
  55. package/components/use-blog-header-obstacles.ts +81 -0
  56. package/components/use-brand-fonts-ready.ts +31 -0
  57. package/components/use-rhythm-overlay.ts +29 -0
  58. package/infra/amplify-app-shell.js +285 -80
  59. package/infra/amplify-app-shell.ts +326 -113
  60. package/infra/build-specs.js +94 -0
  61. package/infra/build-specs.ts +141 -0
  62. package/infra/github-oidc-provider.js +24 -0
  63. package/infra/github-oidc-provider.ts +30 -0
  64. package/infra/index.js +3 -0
  65. package/infra/site-config.js +273 -0
  66. package/infra/site-config.ts +336 -0
  67. package/lib/blog-feature-solver.ts +459 -0
  68. package/lib/blog-rhythm.ts +134 -0
  69. package/lib/brand-fonts.ts +112 -0
  70. package/lib/cached-content-repository.ts +2 -1
  71. package/lib/category-repository.ts +1 -93
  72. package/lib/content-actions-client.ts +98 -0
  73. package/lib/content-actions-demo.ts +190 -0
  74. package/lib/content-repository.ts +3 -0
  75. package/lib/content-source-context.ts +26 -0
  76. package/lib/content-types.ts +3 -0
  77. package/lib/edition-routes.ts +31 -29
  78. package/lib/empty-theme.css +1 -0
  79. package/lib/graphql-content-repository.ts +201 -42
  80. package/lib/layout-scenarios.ts +8 -8
  81. package/lib/newspaper-layout.ts +3 -2
  82. package/lib/newsroom-articles.ts +325 -0
  83. package/lib/newsroom-demo-articles.ts +90 -0
  84. package/lib/newsroom-media-backend.ts +142 -0
  85. package/lib/newsroom-media.ts +182 -0
  86. package/lib/newsroom-nav.ts +3 -0
  87. package/lib/papyrus-web-locations.ts +7 -6
  88. package/lib/presentation-footer.ts +3 -2
  89. package/lib/pretext-layout.ts +7 -3
  90. package/lib/reader-base-path.ts +24 -0
  91. package/lib/reader-static-params.ts +8 -0
  92. package/lib/renderer.ts +7 -0
  93. package/lib/revalidate-secret.ts +59 -0
  94. package/lib/root-route-redirect.ts +16 -0
  95. package/lib/site-brand-tenant.ts +3 -22
  96. package/lib/site-brand.ts +95 -42
  97. package/lib/site-env.ts +52 -0
  98. package/lib/staging-gate.ts +37 -0
  99. package/lib/staging-gated-path.ts +22 -0
  100. package/lib/staging-preview-object.ts +98 -0
  101. package/lib/video-mode.ts +42 -0
  102. package/lib/video-script.ts +63 -0
  103. package/middleware.ts +56 -42
  104. package/package.json +39 -1
  105. package/renderers/pretext/article-page.tsx +40 -9
  106. package/renderers/pretext/presentation-shared.tsx +113 -0
  107. package/renderers/pretext/presentation-shell.tsx +18 -112
  108. package/renderers/pretext/rhythm-article-page.tsx +165 -0
  109. package/renderers/pretext/rhythm-blog-presentation.tsx +280 -0
  110. package/renderers/pretext/rhythm-shell-style.ts +35 -0
  111. package/routes.manifest.json +37 -2
  112. package/scripts/videoml/build-browser-bundle.mjs +22 -0
  113. package/scripts/videoml/build-preview-bundle.mjs +50 -0
  114. package/scripts/videoml/bundle-common.mjs +129 -0
  115. package/scripts/videoml/preview/preview-entry.tsx +381 -0
  116. package/scripts/videoml/preview/preview-stage-fit.ts +28 -0
  117. package/scripts/videoml/preview/preview-timing.ts +42 -0
  118. package/scripts/videoml/preview.html +77 -0
  119. package/scripts/videoml/standard-entry.tsx +46 -0
  120. package/src/sync.mjs +30 -6
  121. package/src/with-papyrus.mjs +15 -2
  122. package/amplify/functions/graphql-jwt-authorizer/handler.ts +0 -193
  123. package/amplify/functions/graphql-jwt-authorizer/resource.js +0 -14
  124. package/amplify/functions/graphql-jwt-authorizer/resource.ts +0 -15
  125. package/publications/anth_us/brand.ts +0 -68
  126. package/publications/anth_us/theme.css +0 -66
  127. package/publications/pilobol_us/brand.ts +0 -37
  128. package/publications/pilobol_us/theme.css +0 -140
  129. package/publications/threat_intelligence/blog-defense/graph.ts +0 -636
  130. package/publications/threat_intelligence/blog-defense/layout.ts +0 -934
  131. package/publications/threat_intelligence/blog-defense/page-background.tsx +0 -590
  132. package/publications/threat_intelligence/brand.ts +0 -40
  133. package/publications/threat_intelligence/pictograms/art.tsx +0 -608
  134. package/publications/threat_intelligence/pictograms/figure.tsx +0 -82
  135. package/publications/threat_intelligence/pictograms/registry.ts +0 -30
  136. package/publications/threat_intelligence/pictograms/system.tsx +0 -305
  137. package/publications/threat_intelligence/seed/seed-edition-content.json +0 -629
  138. package/publications/threat_intelligence/theme.css +0 -1440
  139. /package/{publications/papyrus/theme.css → app/papyrus-theme.css} +0 -0
@@ -0,0 +1,300 @@
1
+ import type { ReactNode } from "react";
2
+ import {
3
+ parseMarkusDocument,
4
+ type MarkusBlock,
5
+ type MarkusDirective,
6
+ type MarkusInline,
7
+ type MarkusNode,
8
+ } from "../lib/markus-ir";
9
+
10
+ const TOKEN_PATTERN = /PAPYRUSMARKUP\d{5}END/g;
11
+ const WHOLE_TOKEN_PATTERN = /^PAPYRUSMARKUP\d{5}END$/;
12
+
13
+ type PreviewSidecar = {
14
+ images: Record<string, Record<string, unknown>>;
15
+ citations: Record<string, string[]>;
16
+ citationLists: Record<string, unknown>;
17
+ bibliography: string[];
18
+ };
19
+
20
+ type PreviewContext = {
21
+ sidecar: PreviewSidecar;
22
+ citationNumbers: Map<string, number>;
23
+ imageUrls: Record<string, string>;
24
+ };
25
+
26
+ function isRecord(value: unknown): value is Record<string, unknown> {
27
+ return typeof value === "object" && value !== null && !Array.isArray(value);
28
+ }
29
+
30
+ function readSidecar(envelope: Record<string, unknown>): PreviewSidecar {
31
+ const sidecar = envelope.papyrus;
32
+ if (!isRecord(sidecar)) throw new Error("bodyIr.papyrus is missing");
33
+ const { images, citations, citationLists, bibliography } = sidecar;
34
+ if (!isRecord(images) || !isRecord(citations) || !isRecord(citationLists) || !Array.isArray(bibliography)) {
35
+ throw new Error("bodyIr.papyrus must contain images, citations, citationLists and bibliography");
36
+ }
37
+ return {
38
+ images: images as PreviewSidecar["images"],
39
+ citations: citations as PreviewSidecar["citations"],
40
+ citationLists,
41
+ bibliography: bibliography.map(String),
42
+ };
43
+ }
44
+
45
+ function numberCitationsByFirstAppearance(document: unknown, sidecar: PreviewSidecar): Map<string, number> {
46
+ const numbers = new Map<string, number>();
47
+ for (const token of JSON.stringify(document).match(TOKEN_PATTERN) ?? []) {
48
+ for (const key of sidecar.citations[token] ?? []) {
49
+ if (!numbers.has(key)) numbers.set(key, numbers.size + 1);
50
+ }
51
+ }
52
+ return numbers;
53
+ }
54
+
55
+ function imagePlaceholder(token: string, context: PreviewContext): ReactNode {
56
+ const entry = context.sidecar.images[token];
57
+ const src = typeof entry?.src === "string" ? entry.src : "";
58
+ const alt = typeof entry?.alt === "string" ? entry.alt : "";
59
+ const url = context.imageUrls[src];
60
+ if (url) {
61
+ return (
62
+ // eslint-disable-next-line @next/next/no-img-element
63
+ <img
64
+ alt={alt}
65
+ className="my-3 h-auto max-w-full rounded-lg"
66
+ data-markus-preview-image-loaded
67
+ loading="lazy"
68
+ src={url}
69
+ />
70
+ );
71
+ }
72
+ return (
73
+ <div
74
+ className="my-3 rounded-lg border border-dashed border-border bg-muted/30 px-3 py-6 text-center text-xs text-muted-foreground"
75
+ data-markus-preview-image
76
+ >
77
+ {`Image: ${src} (${alt})`}
78
+ </div>
79
+ );
80
+ }
81
+
82
+ function renderText(text: string, context: PreviewContext): ReactNode {
83
+ const parts: ReactNode[] = [];
84
+ let cursor = 0;
85
+ for (const match of text.matchAll(TOKEN_PATTERN)) {
86
+ const token = match[0];
87
+ const index = match.index ?? 0;
88
+ const keys = context.sidecar.citations[token];
89
+ if (!keys) continue;
90
+ if (index > cursor) parts.push(text.slice(cursor, index));
91
+ parts.push(
92
+ <sup className="text-primary" key={`${index}-${token}`}>
93
+ {keys.map((key) => `[${context.citationNumbers.get(key)}]`).join("")}
94
+ </sup>,
95
+ );
96
+ cursor = index + token.length;
97
+ }
98
+ if (cursor < text.length) parts.push(text.slice(cursor));
99
+ return parts;
100
+ }
101
+
102
+ function renderInlines(inlines: MarkusInline[], context: PreviewContext): ReactNode[] {
103
+ return inlines.map((node, index) => {
104
+ switch (node.type) {
105
+ case "text":
106
+ return <span key={index}>{renderText(node.text, context)}</span>;
107
+ case "emphasis":
108
+ return <em key={index}>{renderInlines(node.children, context)}</em>;
109
+ case "strong":
110
+ return <strong key={index}>{renderInlines(node.children, context)}</strong>;
111
+ case "strikethrough":
112
+ return <s key={index}>{renderInlines(node.children, context)}</s>;
113
+ case "code_span":
114
+ return <code className="rounded bg-muted px-1 py-0.5 font-mono text-[0.85em]" key={index}>{node.code}</code>;
115
+ case "link":
116
+ return node.href ? (
117
+ <a className="text-primary underline" href={node.href} key={index} rel="noopener noreferrer" target="_blank">
118
+ {renderInlines(node.children, context)}
119
+ </a>
120
+ ) : (
121
+ <span key={index}>{renderInlines(node.children, context)}</span>
122
+ );
123
+ case "image":
124
+ return (
125
+ <span className="rounded border border-dashed border-border px-1 text-xs text-muted-foreground" key={index}>
126
+ {`Image: ${node.src ?? ""} (${node.alt})`}
127
+ </span>
128
+ );
129
+ case "soft_break":
130
+ return <span key={index}>{" "}</span>;
131
+ case "hard_break":
132
+ return <br key={index} />;
133
+ case "html_inline":
134
+ return <code className="font-mono text-xs" key={index}>{node.value}</code>;
135
+ }
136
+ });
137
+ }
138
+
139
+ function soleToken(inlines: MarkusInline[]): string | null {
140
+ if (inlines.length !== 1 || inlines[0].type !== "text") return null;
141
+ const text = inlines[0].text.trim();
142
+ return WHOLE_TOKEN_PATTERN.test(text) ? text : null;
143
+ }
144
+
145
+ const HEADING_CLASSES = [
146
+ "mt-5 mb-2 text-2xl font-semibold tracking-tight",
147
+ "mt-5 mb-2 text-xl font-semibold tracking-tight",
148
+ "mt-4 mb-2 text-lg font-semibold",
149
+ "mt-4 mb-1 text-base font-semibold",
150
+ "mt-3 mb-1 text-sm font-semibold",
151
+ "mt-3 mb-1 text-sm font-medium",
152
+ ];
153
+
154
+ function renderBlock(block: MarkusBlock, index: number, context: PreviewContext): ReactNode {
155
+ switch (block.type) {
156
+ case "paragraph": {
157
+ const token = soleToken(block.inline);
158
+ if (token && token in context.sidecar.images) return <div key={index}>{imagePlaceholder(token, context)}</div>;
159
+ if (token && token in context.sidecar.citationLists) {
160
+ return (
161
+ <ol className="my-3 list-decimal space-y-1 pl-6 text-sm" data-markus-preview-bibliography key={index}>
162
+ {context.sidecar.bibliography.map((entry, entryIndex) => (
163
+ <li key={entryIndex}>{entry}</li>
164
+ ))}
165
+ </ol>
166
+ );
167
+ }
168
+ return <p className="my-3 leading-relaxed" key={index}>{renderInlines(block.inline, context)}</p>;
169
+ }
170
+ case "heading": {
171
+ const level = Math.min(Math.max(block.level, 1), 6);
172
+ const Tag = `h${level}` as "h1";
173
+ return <Tag className={HEADING_CLASSES[level - 1]} key={index}>{renderInlines(block.inline, context)}</Tag>;
174
+ }
175
+ case "list": {
176
+ const items = block.items.map((item, itemIndex) => (
177
+ <li key={itemIndex}>{renderBlocks(item.children, context)}</li>
178
+ ));
179
+ return block.ordered ? (
180
+ <ol className="my-3 list-decimal space-y-1 pl-6" key={index} start={block.start ?? undefined}>{items}</ol>
181
+ ) : (
182
+ <ul className="my-3 list-disc space-y-1 pl-6" key={index}>{items}</ul>
183
+ );
184
+ }
185
+ case "blockquote":
186
+ return (
187
+ <blockquote className="my-3 border-l-4 border-border pl-4 italic text-muted-foreground" key={index}>
188
+ {renderBlocks(block.children, context)}
189
+ </blockquote>
190
+ );
191
+ case "code":
192
+ return (
193
+ <pre className="my-3 overflow-x-auto rounded-lg bg-muted p-3 font-mono text-xs" key={index}>
194
+ <code>{block.value}</code>
195
+ </pre>
196
+ );
197
+ case "thematic_break":
198
+ return <hr className="my-4 border-border" key={index} />;
199
+ case "table":
200
+ return (
201
+ <div className="my-3 overflow-x-auto" key={index}>
202
+ <table className="w-full border-collapse text-sm">
203
+ <thead>
204
+ <tr>
205
+ {block.header.map((cell, cellIndex) => (
206
+ <th className="border border-border bg-muted/40 px-2 py-1 text-left" key={cellIndex}>
207
+ {renderInlines(cell, context)}
208
+ </th>
209
+ ))}
210
+ </tr>
211
+ </thead>
212
+ <tbody>
213
+ {block.rows.map((row, rowIndex) => (
214
+ <tr key={rowIndex}>
215
+ {row.map((cell, cellIndex) => (
216
+ <td className="border border-border px-2 py-1" key={cellIndex}>{renderInlines(cell, context)}</td>
217
+ ))}
218
+ </tr>
219
+ ))}
220
+ </tbody>
221
+ </table>
222
+ </div>
223
+ );
224
+ case "html":
225
+ return (
226
+ <pre className="my-3 overflow-x-auto rounded-lg bg-muted p-3 font-mono text-xs" key={index}>{block.value}</pre>
227
+ );
228
+ }
229
+ }
230
+
231
+ function renderDirective(directive: MarkusDirective, index: number, context: PreviewContext): ReactNode {
232
+ if (directive.name === "pull-quote") {
233
+ const attribution = directive.attributes.attribution;
234
+ return (
235
+ <blockquote
236
+ className="my-4 border-y border-border px-4 py-3 text-lg font-medium italic"
237
+ data-markus-preview-directive="pull-quote"
238
+ key={index}
239
+ >
240
+ {renderBlocks(directive.children, context)}
241
+ {typeof attribution === "string" && attribution ? (
242
+ <footer className="mt-1 text-sm not-italic text-muted-foreground">{`— ${attribution}`}</footer>
243
+ ) : null}
244
+ </blockquote>
245
+ );
246
+ }
247
+ const attributeEntries = Object.entries(directive.attributes).filter(([, value]) => value !== null && value !== "");
248
+ return (
249
+ <section
250
+ className="my-3 rounded-lg border border-border"
251
+ data-markus-preview-directive={directive.name}
252
+ key={index}
253
+ >
254
+ <header className="border-b border-border bg-muted/40 px-3 py-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
255
+ {directive.name}
256
+ </header>
257
+ <div className="px-3 py-1">
258
+ {directive.leaf && attributeEntries.length > 0 ? (
259
+ <p className="my-2 font-mono text-xs text-muted-foreground">
260
+ {attributeEntries.map(([key, value]) => `${key}=${String(value)}`).join(" ")}
261
+ </p>
262
+ ) : null}
263
+ {renderBlocks(directive.children, context)}
264
+ </div>
265
+ </section>
266
+ );
267
+ }
268
+
269
+ function renderBlocks(nodes: MarkusNode[], context: PreviewContext): ReactNode[] {
270
+ return nodes.map((node, index) =>
271
+ node.type === "directive" ? renderDirective(node, index, context) : renderBlock(node, index, context),
272
+ );
273
+ }
274
+
275
+ export function MarkusIrPreview({
276
+ bodyIr,
277
+ imageUrls = {},
278
+ }: {
279
+ bodyIr: unknown;
280
+ imageUrls?: Record<string, string>;
281
+ }) {
282
+ try {
283
+ const envelope = typeof bodyIr === "string" ? JSON.parse(bodyIr) : bodyIr;
284
+ if (!isRecord(envelope)) throw new Error("bodyIr must be a JSON object");
285
+ const document = parseMarkusDocument(envelope.document);
286
+ const sidecar = readSidecar(envelope);
287
+ const context: PreviewContext = {
288
+ sidecar,
289
+ citationNumbers: numberCitationsByFirstAppearance(envelope.document, sidecar),
290
+ imageUrls,
291
+ };
292
+ return <div data-markus-preview>{renderBlocks(document.children, context)}</div>;
293
+ } catch (error) {
294
+ return (
295
+ <p className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive" data-markus-preview-error role="alert">
296
+ {`The preview could not be rendered: ${error instanceof Error ? error.message : "unknown error"}`}
297
+ </p>
298
+ );
299
+ }
300
+ }
@@ -1,4 +1,3 @@
1
- import { cookies } from "next/headers";
2
1
  import { NewsDeskWorkspace, type NewsDeskTab } from "./topic-steering-workspace";
3
2
  import {
4
3
  createDemoCategorySteeringDashboard,
@@ -7,7 +6,6 @@ import {
7
6
  loadConfiguredCorpusSummaries,
8
7
  } from "../lib/category-repository";
9
8
  import {
10
- BRAND_OVERRIDE_COOKIE,
11
9
  getBrandAnalysisProfilesPath,
12
10
  getBrandNewsroomSectionsConfigPath,
13
11
  getBrandSteeringConfigPath,
@@ -65,8 +63,7 @@ export async function NewsDeskPage({ section: routeSection, sectionPageId, selec
65
63
  proposal: getFirstSearchParam(resolvedSearchParams, "proposal"),
66
64
  };
67
65
  const useDemoDashboard = getFirstSearchParam(resolvedSearchParams, "demo") === "1";
68
- const brandOverride = (await cookies()).get(BRAND_OVERRIDE_COOKIE)?.value ?? null;
69
- const brand = resolveActiveSiteBrand(brandOverride);
66
+ const brand = resolveActiveSiteBrand();
70
67
  const analysisProfiles = await loadAnalysisProfileSummaries(getBrandAnalysisProfilesPath(brand));
71
68
  const configuredCorpora = await loadConfiguredCorpusSummaries(getBrandSteeringConfigPath(brand));
72
69
  const dashboard = useDemoDashboard
@@ -12,6 +12,7 @@ import { ARCHIVE_PREVIEW_HEIGHT, ARCHIVE_PREVIEW_WIDTH } from "../lib/archive-ty
12
12
  import type { EditionContent, NewsDeskAppendix, NewsDeskCategoryTreeNode } from "../lib/content-types";
13
13
  import { shouldBypassImageOptimization } from "../lib/image-url";
14
14
  import type { PublicationItem } from "../lib/publication-items";
15
+ import { toPublicReaderPath } from "../lib/reader-base-path";
15
16
  import { SITE_BRAND } from "../lib/site-brand";
16
17
  import { resolveThemedImageSrc, type ResolvedTheme } from "../lib/themed-image";
17
18
  import { loadEditorCategoryTreeState } from "./news-desk-taxonomy-client";
@@ -1877,7 +1878,7 @@ function getPageHref(pageNumber: number, editionBasePath?: string): string {
1877
1878
  }
1878
1879
 
1879
1880
  function getArticleHref(articleSlug: string, editionBasePath?: string): string {
1880
- return editionBasePath ? `${normalizePath(editionBasePath)}/${encodeURIComponent(articleSlug)}` : `/articles/${articleSlug}`;
1881
+ return editionBasePath ? `${normalizePath(editionBasePath)}/${encodeURIComponent(articleSlug)}` : toPublicReaderPath(`/articles/${articleSlug}`);
1881
1882
  }
1882
1883
 
1883
1884
  function getItemAnchorHref(articleSlug: string, pageNumber: number, editionBasePath?: string): string {
@@ -0,0 +1,66 @@
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { SITE_BRAND } from "../lib/site-brand";
5
+ import type { NewsDeskShellState } from "../lib/news-desk-session";
6
+ import { cn } from "../lib/utils";
7
+ import { NewsroomOpsShell } from "./newsroom-ops-shell";
8
+ import { ReaderAuthControl } from "./reader-auth-control";
9
+ import { buttonVariants } from "./ui/button";
10
+
11
+ export function NewsDeskAccessGate({ shell, showSectionTabs = false }: { shell: NewsDeskShellState | null; showSectionTabs?: boolean }) {
12
+ const accessPhase = shell?.phase ?? "checkingAccess";
13
+
14
+ return (
15
+ <NewsroomOpsShell
16
+ activeTab="overview"
17
+ appTitle={SITE_BRAND.appTitle}
18
+ backHref="/"
19
+ backLabel={SITE_BRAND.backToHomeLabel}
20
+ headerActions={(
21
+ <Link className={cn(buttonVariants({ variant: "ghost", size: "sm" }))} href="/settings">Settings</Link>
22
+ )}
23
+ pageTitle="Newsroom"
24
+ showNavigation={showSectionTabs}
25
+ >
26
+ <section aria-live="polite" data-news-desk-access={accessPhase} data-news-desk-access-phase={accessPhase}>
27
+ <div className="space-y-3 rounded-xl border border-border bg-card p-6">
28
+ <p className="m-0 text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-muted-foreground">Access</p>
29
+ <h2 className="m-0 font-sans text-xl font-semibold tracking-tight">{formatAccessTitle(shell)}</h2>
30
+ <p className="m-0 text-sm text-muted-foreground">{formatAccessDetail(shell)}</p>
31
+ {shell?.error ? <p className="text-sm text-destructive">{shell.error}</p> : null}
32
+ <p className="m-0 text-sm text-foreground">{formatAccessActionDetail(shell)}</p>
33
+ {shell?.phase === "signedOut" || shell?.phase === "error" ? (
34
+ <div className="news-desk-access-panel__auth">
35
+ <ReaderAuthControl postAuthPath="/newsroom" showIdentity />
36
+ </div>
37
+ ) : null}
38
+ </div>
39
+ </section>
40
+ </NewsroomOpsShell>
41
+ );
42
+ }
43
+
44
+ function formatAccessTitle(state: NewsDeskShellState | null): string {
45
+ if (!state || state.phase === "checkingAccess") return "Checking Desk Credentials";
46
+ if (state.phase === "loadingDesk") return "Loading Newsroom Records";
47
+ if (state.phase === "forbidden") return "Editor Role Required";
48
+ if (state.phase === "error") return "Newsroom Unavailable";
49
+ return "Editor Sign-In Required";
50
+ }
51
+
52
+ function formatAccessDetail(state: NewsDeskShellState | null): string {
53
+ if (!state || state.phase === "checkingAccess") return `${SITE_BRAND.appTitle} is checking the current browser session before loading steering state.`;
54
+ if (state.phase === "loadingDesk") return `${SITE_BRAND.appTitle} verified the browser session and is loading private Newsroom records.`;
55
+ if (state.phase === "forbidden") return "This account is signed in, but the Cognito session does not include the editor or admin group.";
56
+ if (state.phase === "error") return `${SITE_BRAND.appTitle} could not verify this editor session or load the private Newsroom data.`;
57
+ return "Sign in with an editor or admin account to inspect category, category tree, ontology, and graph steering.";
58
+ }
59
+
60
+ function formatAccessActionDetail(state: NewsDeskShellState | null): string {
61
+ if (!state || state.phase === "checkingAccess") return "This should only take a moment. If it hangs, reload the page.";
62
+ if (state.phase === "loadingDesk") return "Private records are loading from GraphQL. Large reference queues may take several seconds.";
63
+ if (state.phase === "forbidden") return "Ask an admin to add this account to the editor or admin group, then sign out and back in.";
64
+ if (state.phase === "error") return "Reload the page or check the local development console for the GraphQL error.";
65
+ return "Use the login button above to authenticate with an editor or admin account.";
66
+ }