@anthusai/papyrus 5.117.1-next.1 → 5.118.0-next.2

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.
@@ -4,5 +4,5 @@ anthus-markus==0.7.0
4
4
  latex2mathml>=3.78,<4
5
5
  Pillow>=11.3,<12
6
6
  awscrt>=0.23,<1
7
- humanus>=0.37,<0.38
7
+ humanus>=0.38.2,<0.39
8
8
  pypdf>=6.12.1,<7
@@ -7,7 +7,7 @@ import { fileURLToPath } from "node:url";
7
7
  import { pythonLambdaCode } from "../shared/python-bundle.js";
8
8
  const dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
  const projectRoot = path.resolve(dirname, "../../..");
10
- export const contentActionsRequirements = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "latex2mathml>=3.78,<4", "Pillow>=11.3,<12", "awscrt>=0.23,<1", "humanus>=0.37,<0.38", "pypdf>=6.12.1,<7"];
10
+ export const contentActionsRequirements = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "latex2mathml>=3.78,<4", "Pillow>=11.3,<12", "awscrt>=0.23,<1", "humanus>=0.38.2,<0.39", "pypdf>=6.12.1,<7"];
11
11
  function installCheckoutRequirements(outputDir) {
12
12
  const requirementsPath = path.join(projectRoot, "amplify/functions/content-actions/requirements.txt");
13
13
  execSync(`python3 -m pip install -r "${requirementsPath}" -t "${outputDir}" --no-cache-dir --platform manylinux2014_aarch64 --implementation cp --python-version 3.12 --only-binary=:all: --ignore-requires-python`, { cwd: projectRoot, stdio: "inherit" });
@@ -10,7 +10,7 @@ import { pythonLambdaCode, type SiteBundleFile } from "../shared/python-bundle";
10
10
  const dirname = path.dirname(fileURLToPath(import.meta.url));
11
11
  const projectRoot = path.resolve(dirname, "../../..");
12
12
 
13
- export const contentActionsRequirements = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "latex2mathml>=3.78,<4", "Pillow>=11.3,<12", "awscrt>=0.23,<1", "humanus>=0.37,<0.38", "pypdf>=6.12.1,<7"];
13
+ export const contentActionsRequirements = ["PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "latex2mathml>=3.78,<4", "Pillow>=11.3,<12", "awscrt>=0.23,<1", "humanus>=0.38.2,<0.39", "pypdf>=6.12.1,<7"];
14
14
 
15
15
  function installCheckoutRequirements(outputDir: string): void {
16
16
  const requirementsPath = path.join(projectRoot, "amplify/functions/content-actions/requirements.txt");
@@ -1 +1 @@
1
- humanus[jev]>=0.37,<0.38
1
+ humanus[jev]>=0.38.2,<0.39
@@ -211,6 +211,10 @@ export class AmplifyAppShellStack extends Stack {
211
211
  target: `https://${resolveCmsHostName(config)}`,
212
212
  status: String(redirect.status),
213
213
  })),
214
+ // An apex production host: www is permanent-redirected to it (path and query are kept by Amplify's host redirect).
215
+ ...(config.cms.wwwRedirect && config.cms.domainName
216
+ ? [{ source: `https://www.${config.cms.domainName}`, target: `https://${config.cms.domainName}`, status: "301" }]
217
+ : []),
214
218
  { source: "/<*>", target: "/index.html", status: "404-200" },
215
219
  ],
216
220
  });
@@ -324,7 +328,10 @@ export class AmplifyAppShellStack extends Stack {
324
328
  })),
325
329
  ...(stagingBranch ? [{ branchName: "staging", prefix: config.cms.stagingDomainPrefix }] : []),
326
330
  ]
327
- : [{ branchName: "main", prefix: "" }];
331
+ : [
332
+ { branchName: "main", prefix: "" },
333
+ ...(config.cms.wwwRedirect ? [{ branchName: "main", prefix: "www" }] : []),
334
+ ];
328
335
  const productionDomain = new amplify.CfnDomain(this, "Domain", {
329
336
  appId: cmsApp.attrAppId,
330
337
  domainName: config.cms.domainName,
@@ -232,6 +232,10 @@ export class AmplifyAppShellStack extends Stack {
232
232
  target: `https://${resolveCmsHostName(config)}`,
233
233
  status: String(redirect.status),
234
234
  })),
235
+ // An apex production host: www is permanent-redirected to it (path and query are kept by Amplify's host redirect).
236
+ ...(config.cms.wwwRedirect && config.cms.domainName
237
+ ? [{ source: `https://www.${config.cms.domainName}`, target: `https://${config.cms.domainName}`, status: "301" }]
238
+ : []),
235
239
  { source: "/<*>", target: "/index.html", status: "404-200" },
236
240
  ],
237
241
  });
@@ -352,7 +356,10 @@ export class AmplifyAppShellStack extends Stack {
352
356
  })),
353
357
  ...(stagingBranch ? [{ branchName: "staging", prefix: config.cms.stagingDomainPrefix as string }] : []),
354
358
  ]
355
- : [{ branchName: "main", prefix: "" }];
359
+ : [
360
+ { branchName: "main", prefix: "" },
361
+ ...(config.cms.wwwRedirect ? [{ branchName: "main", prefix: "www" }] : []),
362
+ ];
356
363
  const productionDomain = new amplify.CfnDomain(this, "Domain", {
357
364
  appId: cmsApp.attrAppId,
358
365
  domainName: config.cms.domainName,
@@ -296,7 +296,7 @@ export function resolveBuildTimeoutMinutes(cms) {
296
296
  }
297
297
  function parseCms(value, environment) {
298
298
  const cmsRecord = requireObject(value, "cms");
299
- rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "buildTimeoutMinutes", "environment", "stagingDomainName", "domainPrefix", "siteOrigin", "consoleOrigin", "stagingDomainPrefix", "redirects", "stagingPreview", "prospectusAccountsApiStageArn", "readerRetirementPoll", "cliRemoteLogin", "deployStackInBuild", "cms", "alarmTopicArn", "cms", "cliOnFederationClient"], "cms");
299
+ rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "buildTimeoutMinutes", "environment", "stagingDomainName", "domainPrefix", "siteOrigin", "consoleOrigin", "stagingDomainPrefix", "redirects", "wwwRedirect", "stagingPreview", "prospectusAccountsApiStageArn", "readerRetirementPoll", "cliRemoteLogin", "deployStackInBuild", "cms", "alarmTopicArn", "cms", "cliOnFederationClient"], "cms");
300
300
  const buildComputeType = cmsRecord.buildComputeType;
301
301
  if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
302
302
  fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
@@ -320,6 +320,9 @@ function parseCms(value, environment) {
320
320
  if (cmsRecord.readerRetirementPoll === true && prospectusAccountsApiStageArn === undefined) {
321
321
  fail("cms.readerRetirementPoll", "requires cms.prospectusAccountsApiStageArn: the poll calls Prospectus as the site");
322
322
  }
323
+ if (cmsRecord.wwwRedirect !== undefined && typeof cmsRecord.wwwRedirect !== "boolean") {
324
+ fail("cms.wwwRedirect", `must be a boolean, got ${JSON.stringify(cmsRecord.wwwRedirect)}`);
325
+ }
323
326
  if (cmsRecord.cliRemoteLogin !== undefined && typeof cmsRecord.cliRemoteLogin !== "boolean") {
324
327
  fail("cms.cliRemoteLogin", `must be a boolean, got ${JSON.stringify(cmsRecord.cliRemoteLogin)}`);
325
328
  }
@@ -347,6 +350,7 @@ function parseCms(value, environment) {
347
350
  stagingDomainName: optionalString(cmsRecord.stagingDomainName, "cms.stagingDomainName", HOST_NAME_PATTERN, "host name"),
348
351
  stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
349
352
  redirects: parseRedirects(cmsRecord.redirects),
353
+ wwwRedirect: cmsRecord.wwwRedirect,
350
354
  deployStackInBuild: cmsRecord.deployStackInBuild,
351
355
  readerRetirementPoll: cmsRecord.readerRetirementPoll,
352
356
  cliRemoteLogin: cmsRecord.cliRemoteLogin,
@@ -402,6 +406,12 @@ function parseCms(value, environment) {
402
406
  if (cms.domainPrefix && cms.stagingDomainPrefix === cms.domainPrefix) {
403
407
  fail("cms.stagingDomainPrefix", "must differ from cms.domainPrefix");
404
408
  }
409
+ if (cms.wwwRedirect) {
410
+ if (!cms.domainName)
411
+ fail("cms.wwwRedirect", "requires cms.domainName: it redirects www.<domainName> to the apex");
412
+ if (cms.domainPrefix)
413
+ fail("cms.wwwRedirect", "is for an apex production host; with cms.domainPrefix (a shared root domain) use cms.redirects");
414
+ }
405
415
  if (cms.redirects) {
406
416
  if (!cms.domainPrefix)
407
417
  fail("cms.redirects", "requires cms.domainPrefix (redirects target the primary host under a shared root domain)");
@@ -71,6 +71,11 @@ export type CmsConfig = {
71
71
  stagingDomainName?: string;
72
72
  stagingDomainPrefix?: string;
73
73
  redirects?: CmsRedirect[];
74
+ /**
75
+ * The production host is an apex domain (`domainName` with no `domainPrefix`): also serve `www.<domainName>` and redirect it
76
+ * permanently (301) to the apex, keeping path and query. Off unless set; a site under a shared root domain uses `redirects`.
77
+ */
78
+ wwwRedirect?: boolean;
74
79
  prospectusAccountsApiStageArn?: string;
75
80
  /**
76
81
  * The site is a public-reader site that polls Prospectus for retired reader subjects. The template then generates a
@@ -497,7 +502,7 @@ export function resolveBuildTimeoutMinutes(cms: Pick<CmsConfig, "buildTimeoutMin
497
502
 
498
503
  function parseCms(value: unknown, environment: Record<string, string | undefined>): CmsConfig {
499
504
  const cmsRecord = requireObject(value, "cms");
500
- rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "buildTimeoutMinutes", "environment", "stagingDomainName", "domainPrefix", "siteOrigin", "consoleOrigin", "stagingDomainPrefix", "redirects", "stagingPreview", "prospectusAccountsApiStageArn", "readerRetirementPoll", "cliRemoteLogin", "deployStackInBuild", "cms", "alarmTopicArn", "cms", "cliOnFederationClient"], "cms");
505
+ rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "buildTimeoutMinutes", "environment", "stagingDomainName", "domainPrefix", "siteOrigin", "consoleOrigin", "stagingDomainPrefix", "redirects", "wwwRedirect", "stagingPreview", "prospectusAccountsApiStageArn", "readerRetirementPoll", "cliRemoteLogin", "deployStackInBuild", "cms", "alarmTopicArn", "cms", "cliOnFederationClient"], "cms");
501
506
  const buildComputeType = cmsRecord.buildComputeType;
502
507
  if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
503
508
  fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
@@ -521,6 +526,9 @@ function parseCms(value: unknown, environment: Record<string, string | undefined
521
526
  if (cmsRecord.readerRetirementPoll === true && prospectusAccountsApiStageArn === undefined) {
522
527
  fail("cms.readerRetirementPoll", "requires cms.prospectusAccountsApiStageArn: the poll calls Prospectus as the site");
523
528
  }
529
+ if (cmsRecord.wwwRedirect !== undefined && typeof cmsRecord.wwwRedirect !== "boolean") {
530
+ fail("cms.wwwRedirect", `must be a boolean, got ${JSON.stringify(cmsRecord.wwwRedirect)}`);
531
+ }
524
532
  if (cmsRecord.cliRemoteLogin !== undefined && typeof cmsRecord.cliRemoteLogin !== "boolean") {
525
533
  fail("cms.cliRemoteLogin", `must be a boolean, got ${JSON.stringify(cmsRecord.cliRemoteLogin)}`);
526
534
  }
@@ -553,6 +561,7 @@ function parseCms(value: unknown, environment: Record<string, string | undefined
553
561
  stagingDomainName: optionalString(cmsRecord.stagingDomainName, "cms.stagingDomainName", HOST_NAME_PATTERN, "host name"),
554
562
  stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
555
563
  redirects: parseRedirects(cmsRecord.redirects),
564
+ wwwRedirect: cmsRecord.wwwRedirect as boolean | undefined,
556
565
  deployStackInBuild: cmsRecord.deployStackInBuild as boolean | undefined,
557
566
  readerRetirementPoll: cmsRecord.readerRetirementPoll as boolean | undefined,
558
567
  cliRemoteLogin: cmsRecord.cliRemoteLogin as boolean | undefined,
@@ -616,6 +625,11 @@ function parseCms(value: unknown, environment: Record<string, string | undefined
616
625
  fail("cms.stagingDomainPrefix", "must differ from cms.domainPrefix");
617
626
  }
618
627
 
628
+ if (cms.wwwRedirect) {
629
+ if (!cms.domainName) fail("cms.wwwRedirect", "requires cms.domainName: it redirects www.<domainName> to the apex");
630
+ if (cms.domainPrefix) fail("cms.wwwRedirect", "is for an apex production host; with cms.domainPrefix (a shared root domain) use cms.redirects");
631
+ }
632
+
619
633
  if (cms.redirects) {
620
634
  if (!cms.domainPrefix) fail("cms.redirects", "requires cms.domainPrefix (redirects target the primary host under a shared root domain)");
621
635
  cms.redirects.forEach((redirect, index) => {
@@ -0,0 +1,52 @@
1
+ // Executes infra/amplify-app-shell/features/www-redirect.feature: cms.wwwRedirect adds a www sub-domain and a 301 rule to an apex production host.
2
+ // Run by scripts/test-www-redirect.ts, which starts it inside the infrastructure package (one copy of aws-cdk-lib).
3
+ import assert from "node:assert/strict";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { test } from "node:test";
7
+ import { App } from "aws-cdk-lib";
8
+ import { Template } from "aws-cdk-lib/assertions";
9
+ import { AmplifyAppShellStack } from "./amplify-app-shell.js";
10
+ import { parseSiteConfig } from "./site-config.js";
11
+ const repo = path.resolve(__dirname, "../../..");
12
+ const env = { account: "111122223333", region: "us-east-1" };
13
+ const apex = (change = () => { }) => {
14
+ const config = JSON.parse(fs.readFileSync(path.join(repo, "infra/amplify-app-shell/examples/shipped.site.json"), "utf8"));
15
+ delete config.cms.domainPrefix;
16
+ delete config.cms.redirects;
17
+ delete config.cms.stagingDomainPrefix;
18
+ delete config.cms.stagingDomainName;
19
+ delete config.cms.siteOrigin;
20
+ delete config.cms.consoleOrigin;
21
+ config.cms.staging = false;
22
+ config.cms.domainName = "example.test";
23
+ config.hostedZoneId = "Z0000000EXAMPLE";
24
+ config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS = "http://localhost:3001/,https://example.test/";
25
+ change(config);
26
+ return config;
27
+ };
28
+ const synth = (config) => Template.fromStack(new AmplifyAppShellStack(new App(), "Shell", parseSiteConfig(config), { env })).toJSON();
29
+ const resources = (template, type) => Object.values(template.Resources).filter((resource) => resource.Type === type);
30
+ test("an apex production host with cms.wwwRedirect gets the www sub-domain and a 301 rule, 404-200 last", () => {
31
+ const template = synth(apex((c) => (c.cms.wwwRedirect = true)));
32
+ const domains = resources(template, "AWS::Amplify::Domain");
33
+ assert.equal(domains.length, 1);
34
+ assert.deepEqual(domains[0].Properties.SubDomainSettings.map((s) => s.Prefix).sort(), ["", "www"]);
35
+ assert.ok(domains[0].Properties.SubDomainSettings.every((s) => s.BranchName === "main"));
36
+ const app = resources(template, "AWS::Amplify::App").find((a) => a.Properties.Platform === "WEB_COMPUTE");
37
+ const rules = app.Properties.CustomRules;
38
+ assert.ok(rules.some((r) => r.Source === "https://www.example.test" && r.Target === "https://example.test" && r.Status === "301"));
39
+ assert.equal(rules[rules.length - 1].Status, "404-200");
40
+ });
41
+ test("without the flag the template has only the apex sub-domain and no www rule", () => {
42
+ const template = synth(apex());
43
+ const domains = resources(template, "AWS::Amplify::Domain");
44
+ assert.deepEqual(domains[0].Properties.SubDomainSettings.map((s) => s.Prefix), [""]);
45
+ const app = resources(template, "AWS::Amplify::App").find((a) => a.Properties.Platform === "WEB_COMPUTE");
46
+ assert.ok(!app.Properties.CustomRules.some((r) => String(r.Source).includes("www.")));
47
+ });
48
+ test("the flag needs an apex production host and a boolean", () => {
49
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = "yes"; })), /cms\.wwwRedirect/);
50
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = true; delete c.cms.domainName; })), /cms\.wwwRedirect/);
51
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = true; c.cms.domainPrefix = "p"; })), /cms\.wwwRedirect/);
52
+ });
@@ -0,0 +1,56 @@
1
+ // Executes infra/amplify-app-shell/features/www-redirect.feature: cms.wwwRedirect adds a www sub-domain and a 301 rule to an apex production host.
2
+ // Run by scripts/test-www-redirect.ts, which starts it inside the infrastructure package (one copy of aws-cdk-lib).
3
+ import assert from "node:assert/strict";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { test } from "node:test";
7
+ import { App } from "aws-cdk-lib";
8
+ import { Template } from "aws-cdk-lib/assertions";
9
+ import { AmplifyAppShellStack } from "./amplify-app-shell";
10
+ import { parseSiteConfig } from "./site-config";
11
+
12
+ const repo = path.resolve(__dirname, "../../..");
13
+ const env = { account: "111122223333", region: "us-east-1" };
14
+ const apex = (change: (config: any) => void = () => {}) => {
15
+ const config = JSON.parse(fs.readFileSync(path.join(repo, "infra/amplify-app-shell/examples/shipped.site.json"), "utf8"));
16
+ delete config.cms.domainPrefix;
17
+ delete config.cms.redirects;
18
+ delete config.cms.stagingDomainPrefix;
19
+ delete config.cms.stagingDomainName;
20
+ delete config.cms.siteOrigin;
21
+ delete config.cms.consoleOrigin;
22
+ config.cms.staging = false;
23
+ config.cms.domainName = "example.test";
24
+ config.hostedZoneId = "Z0000000EXAMPLE";
25
+ config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS = "http://localhost:3001/,https://example.test/";
26
+ change(config);
27
+ return config;
28
+ };
29
+ const synth = (config: unknown) => Template.fromStack(new AmplifyAppShellStack(new App(), "Shell", parseSiteConfig(config), { env })).toJSON();
30
+ const resources = (template: any, type: string) => Object.values<any>(template.Resources).filter((resource) => resource.Type === type);
31
+
32
+ test("an apex production host with cms.wwwRedirect gets the www sub-domain and a 301 rule, 404-200 last", () => {
33
+ const template = synth(apex((c) => (c.cms.wwwRedirect = true)));
34
+ const domains = resources(template, "AWS::Amplify::Domain");
35
+ assert.equal(domains.length, 1);
36
+ assert.deepEqual(domains[0].Properties.SubDomainSettings.map((s: any) => s.Prefix).sort(), ["", "www"]);
37
+ assert.ok(domains[0].Properties.SubDomainSettings.every((s: any) => s.BranchName === "main"));
38
+ const app = resources(template, "AWS::Amplify::App").find((a) => a.Properties.Platform === "WEB_COMPUTE");
39
+ const rules = app.Properties.CustomRules;
40
+ assert.ok(rules.some((r: any) => r.Source === "https://www.example.test" && r.Target === "https://example.test" && r.Status === "301"));
41
+ assert.equal(rules[rules.length - 1].Status, "404-200");
42
+ });
43
+
44
+ test("without the flag the template has only the apex sub-domain and no www rule", () => {
45
+ const template = synth(apex());
46
+ const domains = resources(template, "AWS::Amplify::Domain");
47
+ assert.deepEqual(domains[0].Properties.SubDomainSettings.map((s: any) => s.Prefix), [""]);
48
+ const app = resources(template, "AWS::Amplify::App").find((a) => a.Properties.Platform === "WEB_COMPUTE");
49
+ assert.ok(!app.Properties.CustomRules.some((r: any) => String(r.Source).includes("www.")));
50
+ });
51
+
52
+ test("the flag needs an apex production host and a boolean", () => {
53
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = "yes"; })), /cms\.wwwRedirect/);
54
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = true; delete c.cms.domainName; })), /cms\.wwwRedirect/);
55
+ assert.throws(() => parseSiteConfig(apex((c) => { c.cms.wwwRedirect = true; c.cms.domainPrefix = "p"; })), /cms\.wwwRedirect/);
56
+ });
package/package.json CHANGED
@@ -640,7 +640,7 @@
640
640
  "optional": true
641
641
  }
642
642
  },
643
- "version": "5.117.1-next.1",
643
+ "version": "5.118.0-next.2",
644
644
  "dependencies": {
645
645
  "@aws-amplify/adapter-nextjs": "^1.7.3",
646
646
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.117.1-next.1",
2
+ "version": "5.118.0-next.2",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",