@anthusai/papyrus 5.34.0 → 5.35.0

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.
@@ -1,6 +1,6 @@
1
1
  import { defineAuth, secret } from "@aws-amplify/backend";
2
2
  import { manageUserRole } from "../functions/manage-user-role/resource.js";
3
- import { CfnUserPoolDomain } from "aws-cdk-lib/aws-cognito";
3
+ import { CfnUserPoolDomain, CfnUserPoolIdentityProvider } from "aws-cdk-lib/aws-cognito";
4
4
  import { expandNewsroomRedirectUrls } from "./redirect-urls.js";
5
5
  // Default OAuth redirect URLs for the p.apyr.us app. Other publications pass
6
6
  // `auth.redirectUrls` to `defineSiteBackend` (or, for Papyrus's own backend,
@@ -35,6 +35,21 @@ export function authConfigFromEnv() {
35
35
  export function siteAuthRedirectUrls(config) {
36
36
  return config.redirectUrls ?? DEFAULT_AUTH_REDIRECT_URLS;
37
37
  }
38
+ /** Keep Cognito's federated email verification state in sync with Google's verified claim. */
39
+ export function applyGoogleEmailVerifiedMapping(authStack) {
40
+ const googleProviders = authStack.node
41
+ .findAll()
42
+ .filter((construct) => construct instanceof CfnUserPoolIdentityProvider && construct.providerName === "Google");
43
+ if (googleProviders.length !== 1) {
44
+ throw new Error(`Expected exactly one Google identity provider to map email_verified, found ${googleProviders.length}`);
45
+ }
46
+ const [provider] = googleProviders;
47
+ const mapping = provider.attributeMapping;
48
+ if (mapping !== undefined && (typeof mapping !== "object" || Array.isArray(mapping))) {
49
+ throw new Error("Expected Google identity provider attribute mappings to be a plain object");
50
+ }
51
+ provider.attributeMapping = { ...(mapping ?? {}), email_verified: "email_verified" };
52
+ }
38
53
  export function defineSiteAuth(config) {
39
54
  const authRedirectUrls = expandNewsroomRedirectUrls(siteAuthRedirectUrls(config), config.newsroomBasePath);
40
55
  const disableGoogleOAuth = config.disableGoogleOAuth === true;
@@ -1,7 +1,7 @@
1
1
  import { defineAuth, secret } from "@aws-amplify/backend";
2
2
  import { manageUserRole } from "../functions/manage-user-role/resource";
3
3
  import { Stack } from "aws-cdk-lib";
4
- import { CfnUserPoolDomain } from "aws-cdk-lib/aws-cognito";
4
+ import { CfnUserPoolDomain, CfnUserPoolIdentityProvider } from "aws-cdk-lib/aws-cognito";
5
5
  import type { PapyrusAuthConfig } from "../site-backend-config";
6
6
  import { expandNewsroomRedirectUrls } from "./redirect-urls";
7
7
 
@@ -41,6 +41,24 @@ export function siteAuthRedirectUrls(config: PapyrusAuthConfig): string[] {
41
41
  return config.redirectUrls ?? DEFAULT_AUTH_REDIRECT_URLS;
42
42
  }
43
43
 
44
+ /** Keep Cognito's federated email verification state in sync with Google's verified claim. */
45
+ export function applyGoogleEmailVerifiedMapping(authStack: Stack): void {
46
+ const googleProviders = authStack.node
47
+ .findAll()
48
+ .filter((construct): construct is CfnUserPoolIdentityProvider =>
49
+ construct instanceof CfnUserPoolIdentityProvider && construct.providerName === "Google");
50
+ if (googleProviders.length !== 1) {
51
+ throw new Error(`Expected exactly one Google identity provider to map email_verified, found ${googleProviders.length}`);
52
+ }
53
+
54
+ const [provider] = googleProviders;
55
+ const mapping = provider.attributeMapping;
56
+ if (mapping !== undefined && (typeof mapping !== "object" || Array.isArray(mapping))) {
57
+ throw new Error("Expected Google identity provider attribute mappings to be a plain object");
58
+ }
59
+ provider.attributeMapping = { ...(mapping ?? {}), email_verified: "email_verified" };
60
+ }
61
+
44
62
  export function defineSiteAuth(config: PapyrusAuthConfig) {
45
63
  const authRedirectUrls = expandNewsroomRedirectUrls(
46
64
  siteAuthRedirectUrls(config),
@@ -18,7 +18,7 @@ import { assertValidPublicationConfig } from "./site-backend-config.js";
18
18
  import { revalidateSecretReadStatement } from "./revalidate-secret-policy.js";
19
19
  import { revalidateDistributionEnvironment, revalidateInvalidationStatement, validateRevalidateDistributionIds, } from "./revalidate-invalidation-settings.js";
20
20
  import { addInvalidationPathAlarm } from "./publication/invalidation-alarm.js";
21
- import { applyCognitoDomainPrefix, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource.js";
21
+ import { applyCognitoDomainPrefix, applyGoogleEmailVerifiedMapping, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource.js";
22
22
  import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, addProspectusGoogleOnlyClient } from "./auth/prospectus-google-client.js";
23
23
  import { defineSiteData } from "./data/resource.js";
24
24
  import { editorialChecks } from "./functions/editorial-checks/resource.js";
@@ -116,6 +116,9 @@ export function defineSiteBackend(papyrusSite) {
116
116
  slackDelivery,
117
117
  storage,
118
118
  });
119
+ if (authConfig.disableGoogleOAuth !== true) {
120
+ applyGoogleEmailVerifiedMapping(backend.auth.stack);
121
+ }
119
122
  orderModelStacksInWaves(backend.data.resources.graphqlApi.node.scope, Object.keys(backend.data.resources.tables), site.resolverWaveSize ?? DEFAULT_RESOLVER_WAVE_SIZE);
120
123
  const requestedCognitoDomainPrefix = (authConfig.cognitoDomainPrefix ?? "").trim();
121
124
  if (authConfig.applyCognitoDomainPrefix === true
@@ -25,7 +25,7 @@ import {
25
25
  validateRevalidateDistributionIds,
26
26
  } from "./revalidate-invalidation-settings";
27
27
  import { addInvalidationPathAlarm } from "./publication/invalidation-alarm";
28
- import { applyCognitoDomainPrefix, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource";
28
+ import { applyCognitoDomainPrefix, applyGoogleEmailVerifiedMapping, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource";
29
29
  import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, addProspectusGoogleOnlyClient } from "./auth/prospectus-google-client";
30
30
  import { defineSiteData } from "./data/resource";
31
31
  import { editorialChecks } from "./functions/editorial-checks/resource";
@@ -138,6 +138,10 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
138
138
  storage,
139
139
  });
140
140
 
141
+ if (authConfig.disableGoogleOAuth !== true) {
142
+ applyGoogleEmailVerifiedMapping(backend.auth.stack);
143
+ }
144
+
141
145
  orderModelStacksInWaves(
142
146
  backend.data.resources.graphqlApi.node.scope as Construct,
143
147
  Object.keys(backend.data.resources.tables),
package/package.json CHANGED
@@ -448,7 +448,7 @@
448
448
  "optional": true
449
449
  }
450
450
  },
451
- "version": "5.34.0",
451
+ "version": "5.35.0",
452
452
  "dependencies": {
453
453
  "@aws-amplify/adapter-nextjs": "^1.7.3",
454
454
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.34.0",
2
+ "version": "5.35.0",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",