@anthusai/papyrus 5.110.0 → 5.112.0-next.1
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/auth/resource.js +3 -0
- package/amplify/auth/resource.ts +3 -0
- package/amplify/auth/tenant-session-claims.js +27 -0
- package/amplify/auth/tenant-session-claims.ts +31 -0
- package/amplify/cost-attribution.js +12 -0
- package/amplify/cost-attribution.ts +12 -0
- package/amplify/data/resource.js +79 -0
- package/amplify/data/resource.ts +82 -0
- package/amplify/data/schema.js +82 -1
- package/amplify/data/schema.ts +85 -1
- package/amplify/functions/assignment-action/handler.ts +14 -9
- package/amplify/functions/automation-view/wire.js +2 -1
- package/amplify/functions/automation-view/wire.ts +2 -1
- package/amplify/functions/category-action/handler.ts +24 -18
- package/amplify/functions/category-action/message-hashtags.js +2 -1
- package/amplify/functions/category-action/message-hashtags.ts +2 -1
- package/amplify/functions/category-action/reference-links.js +3 -2
- package/amplify/functions/category-action/reference-links.ts +3 -2
- package/amplify/functions/console-chat-responder/resource.js +2 -1
- package/amplify/functions/console-chat-responder/resource.ts +2 -1
- package/amplify/functions/content-actions/handler.py +54 -22
- package/amplify/functions/content-actions/resource.js +4 -0
- package/amplify/functions/content-actions/resource.ts +5 -0
- package/amplify/functions/editorial-checks/handler.py +5 -1
- package/amplify/functions/editorial-checks/schema.js +10 -2
- package/amplify/functions/editorial-checks/schema.ts +10 -2
- package/amplify/functions/editorial-checks/wire.js +2 -1
- package/amplify/functions/editorial-checks/wire.ts +2 -1
- package/amplify/functions/image-service/wire.js +2 -1
- package/amplify/functions/image-service/wire.ts +2 -1
- package/amplify/functions/monitoring-view/wire.js +2 -1
- package/amplify/functions/monitoring-view/wire.ts +2 -1
- package/amplify/functions/newsroom-summary/handler.ts +16 -12
- package/amplify/functions/shared/tenant-context.js +98 -0
- package/amplify/functions/shared/tenant-context.ts +33 -0
- package/amplify/functions/shared/tenant-scoped-client.ts +80 -0
- package/amplify/functions/tenant-claims/claims.ts +90 -0
- package/amplify/functions/tenant-claims/environment.js +7 -0
- package/amplify/functions/tenant-claims/environment.ts +7 -0
- package/amplify/functions/tenant-claims/handler.ts +56 -0
- package/amplify/functions/tenant-claims/resource.js +12 -0
- package/amplify/functions/tenant-claims/resource.ts +13 -0
- package/amplify/plugins/newsletter/sending.js +2 -1
- package/amplify/plugins/newsletter/sending.ts +2 -1
- package/amplify/plugins/notifications/papyrus.plugin.js +2 -1
- package/amplify/plugins/notifications/papyrus.plugin.ts +2 -1
- package/amplify/plugins/reader-steering/schema.js +15 -3
- package/amplify/plugins/reader-steering/schema.ts +15 -3
- package/amplify/plugins/signup/papyrus.plugin.js +2 -1
- package/amplify/plugins/signup/papyrus.plugin.ts +2 -1
- package/amplify/plugins/signup/schema.js +1 -0
- package/amplify/plugins/signup/schema.ts +1 -0
- package/amplify/shared-stack/alarms.js +53 -0
- package/amplify/shared-stack/alarms.ts +109 -0
- package/amplify/shared-stack/define.js +15 -0
- package/amplify/shared-stack/define.ts +17 -0
- package/amplify/shared-stack/deny.js +27 -0
- package/amplify/shared-stack/deny.ts +28 -0
- package/amplify/shared-stack/inline-policy.js +53 -0
- package/amplify/shared-stack/inline-policy.ts +65 -0
- package/amplify/shared-stack/isolation.js +161 -0
- package/amplify/shared-stack/isolation.ts +204 -0
- package/amplify/shared-stack/names.js +95 -0
- package/amplify/shared-stack/names.ts +133 -0
- package/amplify/shared-stack/settings.js +70 -0
- package/amplify/shared-stack/settings.ts +95 -0
- package/amplify/site-api-access.js +13 -0
- package/amplify/site-api-access.ts +14 -0
- package/amplify/site-backend-config.js +7 -1
- package/amplify/site-backend-config.ts +8 -2
- package/amplify/site-backend.js +65 -13
- package/amplify/site-backend.ts +75 -19
- package/components/news-desk-taxonomy-client.ts +5 -0
- package/components/newsroom-article-editor.tsx +7 -3
- package/components/newsroom-board-view.tsx +4 -2
- package/components/newsroom-organizer.css +2 -2
- package/components/use-newsroom-desk-sections.ts +31 -0
- package/infra/amplify-app-shell.js +4 -1
- package/infra/amplify-app-shell.ts +4 -1
- package/infra/build-specs.js +4 -1
- package/infra/build-specs.ts +5 -1
- package/infra/cost-tags.test.js +1 -1
- package/infra/cost-tags.test.ts +1 -1
- package/infra/shared-stack-deny.js +80 -0
- package/infra/shared-stack-deny.test.js +56 -0
- package/infra/shared-stack-deny.test.ts +66 -0
- package/infra/shared-stack-deny.ts +86 -0
- package/lib/newsroom-sections.ts +14 -0
- package/lib/tenant-keys.js +16 -0
- package/lib/tenant-keys.ts +19 -0
- package/package.json +2 -1
- package/routes.manifest.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { SHARED_TIERS, type SharedTier } from "./names";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The numbers the shared stacks need. They live here, in one reviewed file, and never in a template or an aspect (the standing rule
|
|
5
|
+
* against arbitrary limits). A tier with `null` has not been measured yet and cannot be synthesised.
|
|
6
|
+
*/
|
|
7
|
+
export type SharedStackSettings = {
|
|
8
|
+
reservedConcurrency: { perFunction: number; overrides: Record<string, number>; tierLimit: number };
|
|
9
|
+
alarms: {
|
|
10
|
+
periodMinutes: number;
|
|
11
|
+
functionErrors: number;
|
|
12
|
+
functionThrottles: number;
|
|
13
|
+
/** An alarm fires when a function's concurrency reaches this share of its reserved concurrency. */
|
|
14
|
+
concurrencyShareOfReserved: number;
|
|
15
|
+
appSyncServerErrors: number;
|
|
16
|
+
appSyncClientErrors: number;
|
|
17
|
+
dynamoDbThrottledRequests: number;
|
|
18
|
+
projectionDeadLetterMessages: number;
|
|
19
|
+
/** Paths a stack's edge purges in a week before the alarm fires. */
|
|
20
|
+
purgedPathsPerWeek: number;
|
|
21
|
+
};
|
|
22
|
+
logRetentionDays: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type SettingsFile = { tiers: Record<SharedTier, SharedStackSettings | null> };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The settings of each shared stack (PPY-daf673, PPY-f40a02).
|
|
29
|
+
*
|
|
30
|
+
* - The staging values are a documented starting point so the first create can happen; they MUST be replaced from staging traffic
|
|
31
|
+
* (measured peak concurrent executions per function, alarm history) before shared production is created.
|
|
32
|
+
* - Production has no values on purpose: its synthesis refuses until the reserved concurrency, the tier limit and the alarm
|
|
33
|
+
* thresholds are set from staging traffic.
|
|
34
|
+
* - `perFunction` is the reserved concurrency of every function the stack owns; `overrides` sets one function (the key is the
|
|
35
|
+
* function's construct id). `tierLimit` is the most the stack may reserve in total, so unreserved headroom stays with the
|
|
36
|
+
* dedicated sites (AWS also requires 100 unreserved).
|
|
37
|
+
*/
|
|
38
|
+
export const SHARED_STACK_SETTINGS: SettingsFile = {
|
|
39
|
+
tiers: {
|
|
40
|
+
staging: {
|
|
41
|
+
reservedConcurrency: { perFunction: 2, overrides: {}, tierLimit: 120 },
|
|
42
|
+
alarms: {
|
|
43
|
+
periodMinutes: 5,
|
|
44
|
+
functionErrors: 1,
|
|
45
|
+
functionThrottles: 1,
|
|
46
|
+
concurrencyShareOfReserved: 0.8,
|
|
47
|
+
appSyncServerErrors: 1,
|
|
48
|
+
appSyncClientErrors: 50,
|
|
49
|
+
dynamoDbThrottledRequests: 1,
|
|
50
|
+
projectionDeadLetterMessages: 1,
|
|
51
|
+
purgedPathsPerWeek: 25,
|
|
52
|
+
},
|
|
53
|
+
logRetentionDays: 30,
|
|
54
|
+
},
|
|
55
|
+
production: null,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const POSITIVE_INTEGER_FIELDS = [
|
|
60
|
+
["reservedConcurrency", "perFunction"],
|
|
61
|
+
["reservedConcurrency", "tierLimit"],
|
|
62
|
+
["alarms", "periodMinutes"],
|
|
63
|
+
["alarms", "functionErrors"],
|
|
64
|
+
["alarms", "functionThrottles"],
|
|
65
|
+
["alarms", "appSyncServerErrors"],
|
|
66
|
+
["alarms", "appSyncClientErrors"],
|
|
67
|
+
["alarms", "dynamoDbThrottledRequests"],
|
|
68
|
+
["alarms", "projectionDeadLetterMessages"],
|
|
69
|
+
["alarms", "purgedPathsPerWeek"],
|
|
70
|
+
] as const;
|
|
71
|
+
|
|
72
|
+
/** Refuses a missing or malformed value naming the setting, so a bad number never reaches a template. */
|
|
73
|
+
export function validateSharedStackSettings(tier: SharedTier, value: SharedStackSettings | null | undefined): SharedStackSettings {
|
|
74
|
+
if (value === null || value === undefined) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`The ${tier} shared stack has no settings in amplify/shared-stack/settings.ts: its reserved concurrency (PPY-f40a02), tier limit and alarm thresholds must be set from staging traffic before it can be synthesised.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
for (const [group, field] of POSITIVE_INTEGER_FIELDS) {
|
|
80
|
+
const number = (value as unknown as Record<string, Record<string, unknown>>)[group]?.[field];
|
|
81
|
+
if (!Number.isInteger(number) || (number as number) < 1) throw new Error(`Shared ${tier} settings: ${group}.${field} must be a positive integer.`);
|
|
82
|
+
}
|
|
83
|
+
const share = value.alarms.concurrencyShareOfReserved;
|
|
84
|
+
if (typeof share !== "number" || !(share > 0 && share <= 1)) throw new Error(`Shared ${tier} settings: alarms.concurrencyShareOfReserved must be above 0 and at most 1.`);
|
|
85
|
+
if (!Number.isInteger(value.logRetentionDays) || value.logRetentionDays < 1) throw new Error(`Shared ${tier} settings: logRetentionDays must be a positive integer.`);
|
|
86
|
+
for (const [name, number] of Object.entries(value.reservedConcurrency.overrides ?? {})) {
|
|
87
|
+
if (!Number.isInteger(number) || number < 1) throw new Error(`Shared ${tier} settings: reservedConcurrency.overrides.${name} must be a positive integer.`);
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function sharedStackSettings(tier: SharedTier, file: SettingsFile = SHARED_STACK_SETTINGS): SharedStackSettings {
|
|
93
|
+
if (!SHARED_TIERS.includes(tier)) throw new Error(`Unknown shared tier ${JSON.stringify(tier)}.`);
|
|
94
|
+
return validateSharedStackSettings(tier, file.tiers[tier]);
|
|
95
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function reaches its site's GraphQL API as itself, signed with its own role: the operator lane. The Papyrus engine's
|
|
3
|
+
* default lane is a signed-in person (`papyrus login`), and it never falls back to AWS credentials on its own (PPY-5f119a),
|
|
4
|
+
* so the endpoint and the lane always travel together. Give a function the endpoint only through these.
|
|
5
|
+
*/
|
|
6
|
+
export const OPERATOR_LANE = { PAPYRUS_GRAPHQL_AUTH: "iam" };
|
|
7
|
+
export function siteApiEnvironment(graphqlEndpoint) {
|
|
8
|
+
return { PAPYRUS_GRAPHQL_ENDPOINT: graphqlEndpoint, ...OPERATOR_LANE };
|
|
9
|
+
}
|
|
10
|
+
export function connectToSiteApi(target, graphqlEndpoint) {
|
|
11
|
+
for (const [name, value] of Object.entries(siteApiEnvironment(graphqlEndpoint)))
|
|
12
|
+
target.addEnvironment(name, value);
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function reaches its site's GraphQL API as itself, signed with its own role: the operator lane. The Papyrus engine's
|
|
3
|
+
* default lane is a signed-in person (`papyrus login`), and it never falls back to AWS credentials on its own (PPY-5f119a),
|
|
4
|
+
* so the endpoint and the lane always travel together. Give a function the endpoint only through these.
|
|
5
|
+
*/
|
|
6
|
+
export const OPERATOR_LANE = { PAPYRUS_GRAPHQL_AUTH: "iam" } as const;
|
|
7
|
+
|
|
8
|
+
export function siteApiEnvironment(graphqlEndpoint: string): Record<string, string> {
|
|
9
|
+
return { PAPYRUS_GRAPHQL_ENDPOINT: graphqlEndpoint, ...OPERATOR_LANE };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function connectToSiteApi(target: { addEnvironment(name: string, value: string): unknown }, graphqlEndpoint: string): void {
|
|
13
|
+
for (const [name, value] of Object.entries(siteApiEnvironment(graphqlEndpoint))) target.addEnvironment(name, value);
|
|
14
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSharedTier } from "./shared-stack/names.js";
|
|
1
2
|
export const MAXIMUM_HTML_S_MAXAGE_SECONDS = 86400;
|
|
2
3
|
/** The live lifetime is a few seconds by intent; a larger value is `htmlSMaxAgeSeconds` with extra steps. */
|
|
3
4
|
export const MAXIMUM_LIVE_S_MAXAGE_SECONDS = 60;
|
|
@@ -126,10 +127,15 @@ export function validateTenancyConfig(tenancy) {
|
|
|
126
127
|
return [];
|
|
127
128
|
if (typeof tenancy !== "object" || tenancy === null || Array.isArray(tenancy))
|
|
128
129
|
return ["tenancy must be an object"];
|
|
129
|
-
const mode = tenancy
|
|
130
|
+
const { mode, tier } = tenancy;
|
|
130
131
|
if (mode !== undefined && mode !== "dedicated" && mode !== "shared") {
|
|
131
132
|
return [`tenancy.mode must be "dedicated" or "shared" (got ${JSON.stringify(mode)})`];
|
|
132
133
|
}
|
|
134
|
+
if (mode === "shared" && !isSharedTier(tier)) {
|
|
135
|
+
return [`tenancy.tier must be "production" or "staging" for a shared stack (got ${JSON.stringify(tier)})`];
|
|
136
|
+
}
|
|
137
|
+
if (mode !== "shared" && tier !== undefined)
|
|
138
|
+
return ["tenancy.tier is only for tenancy.mode \"shared\""];
|
|
133
139
|
return [];
|
|
134
140
|
}
|
|
135
141
|
export function assertValidTenancyConfig(tenancy) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginRequest } from "./plugins/types";
|
|
2
|
+
import { isSharedTier, type SharedTier } from "./shared-stack/names";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Per-site backend configuration: the argument of `defineSiteBackend(site)`.
|
|
@@ -209,17 +210,22 @@ export function assertValidPublicationConfig(publication: unknown): void {
|
|
|
209
210
|
* helpers `papyrus_content.tenancy` (Python) and `lib/tenant-keys.ts` (TypeScript) may read.
|
|
210
211
|
*/
|
|
211
212
|
export type PapyrusTenancyMode = "dedicated" | "shared";
|
|
212
|
-
|
|
213
|
+
/** `tier` names which shared stack this backend is (docs/shared-stack.md); required with mode "shared", refused without it. */
|
|
214
|
+
export type PapyrusTenancyConfig = { mode?: PapyrusTenancyMode; tier?: SharedTier };
|
|
213
215
|
|
|
214
216
|
export const TENANCY_MODE_ENVIRONMENT_VARIABLE = "PAPYRUS_TENANCY_MODE";
|
|
215
217
|
|
|
216
218
|
export function validateTenancyConfig(tenancy: unknown): string[] {
|
|
217
219
|
if (tenancy === undefined) return [];
|
|
218
220
|
if (typeof tenancy !== "object" || tenancy === null || Array.isArray(tenancy)) return ["tenancy must be an object"];
|
|
219
|
-
const mode =
|
|
221
|
+
const { mode, tier } = tenancy as { mode?: unknown; tier?: unknown };
|
|
220
222
|
if (mode !== undefined && mode !== "dedicated" && mode !== "shared") {
|
|
221
223
|
return [`tenancy.mode must be "dedicated" or "shared" (got ${JSON.stringify(mode)})`];
|
|
222
224
|
}
|
|
225
|
+
if (mode === "shared" && !isSharedTier(tier)) {
|
|
226
|
+
return [`tenancy.tier must be "production" or "staging" for a shared stack (got ${JSON.stringify(tier)})`];
|
|
227
|
+
}
|
|
228
|
+
if (mode !== "shared" && tier !== undefined) return ["tenancy.tier is only for tenancy.mode \"shared\""];
|
|
223
229
|
return [];
|
|
224
230
|
}
|
|
225
231
|
|
package/amplify/site-backend.js
CHANGED
|
@@ -19,7 +19,13 @@ import { assertValidMonitoringConfig, assertValidPublicationConfig, assertValidT
|
|
|
19
19
|
import { revalidateSecretReadStatement } from "./revalidate-secret-policy.js";
|
|
20
20
|
import { revalidateDistributionEnvironment, revalidateInvalidationStatement, validateRevalidateDistributionIds, } from "./revalidate-invalidation-settings.js";
|
|
21
21
|
import { enablePointInTimeRecoveryOnDataTables } from "./data-table-recovery.js";
|
|
22
|
-
import { applySiteBackendCostTags, siteCostAttribution, wireSiteUsageSender } from "./cost-attribution.js";
|
|
22
|
+
import { applySiteBackendCostTags, sharedStackCostAttribution, siteCostAttribution, wireSiteUsageSender } from "./cost-attribution.js";
|
|
23
|
+
import { addSharedStackAlarms } from "./shared-stack/alarms.js";
|
|
24
|
+
import { addSharedStackDeny, isModelDataStack } from "./shared-stack/deny.js";
|
|
25
|
+
import { isInfrastructureConstructId } from "./shared-stack/inline-policy.js";
|
|
26
|
+
import { applySharedStackIsolation } from "./shared-stack/isolation.js";
|
|
27
|
+
import { sharedTierPlan } from "./shared-stack/names.js";
|
|
28
|
+
import { sharedStackSettings } from "./shared-stack/settings.js";
|
|
23
29
|
import { addInvalidationPathAlarm } from "./publication/invalidation-alarm.js";
|
|
24
30
|
import { applyCognitoDomainPrefix, applyGoogleEmailVerifiedMapping, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource.js";
|
|
25
31
|
import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, CLI_FEDERATION_REFRESH_TOKEN_VALIDITY_DAYS, addProspectusGoogleOnlyClient, cliFederationClientCallbackUrls, trustClientOnIdentityPool } from "./auth/prospectus-google-client.js";
|
|
@@ -50,6 +56,8 @@ import { contentActions, setSiteFilesForContentActionsBundle } from "./functions
|
|
|
50
56
|
import { knowledgeQuery } from "./functions/knowledge-query/resource.js";
|
|
51
57
|
import { wireReferenceWordIndex } from "./functions/reference-word-index/wire.js";
|
|
52
58
|
import { manageUserRole } from "./functions/manage-user-role/resource.js";
|
|
59
|
+
import { tenantClaims } from "./functions/tenant-claims/resource.js";
|
|
60
|
+
import { applyTenantSessionClaims } from "./auth/tenant-session-claims.js";
|
|
53
61
|
import { modelAttachmentUpload } from "./functions/model-attachment-upload/resource.js";
|
|
54
62
|
import { newsroomSummary } from "./functions/newsroom-summary/resource.js";
|
|
55
63
|
import { derivePublicFormOrigins } from "./functions/public-forms/origins.js";
|
|
@@ -67,13 +75,13 @@ import { InboundEmailStack } from "./inbound-email/stack.js";
|
|
|
67
75
|
import { deriveKnowledgeVectorIndexName, deriveReceiptRuleName, deriveReceiptRuleSetName, deriveStorageBackupVaultName, isLegacyProductionPipeline, planInboundEmailSes, resolveSiteBackendFeatureFlags, sanitizeAwsName, } from "./site-backend-names.js";
|
|
68
76
|
import { addStorageBackups } from "./storage-backups/construct.js";
|
|
69
77
|
import { storage } from "./storage/resource.js";
|
|
70
|
-
|
|
78
|
+
import { connectToSiteApi } from "./site-api-access.js";
|
|
79
|
+
export function defineSiteBackend(papyrusSite, options = {}) {
|
|
71
80
|
// `papyrus.config.ts`'s default export. Backend options live under `backend`;
|
|
72
81
|
// the default brand id namespaces account-global resources.
|
|
73
82
|
const site = { brandId: papyrusSite.defaultBrand, ...papyrusSite.backend };
|
|
74
83
|
// Prospectus cost accounting: on when `papyrus-infra backend-deploy` asks for a cost tag wave (PAPYRUS_COST_TAG_WAVE).
|
|
75
|
-
// Null, from a plain `ampx pipeline-deploy`, leaves the backend untouched.
|
|
76
|
-
const costAttribution = siteCostAttribution();
|
|
84
|
+
// Null, from a plain `ampx pipeline-deploy`, leaves the backend untouched. A shared stack is always tagged (see below).
|
|
77
85
|
const knowledgeVectorDimension = 1536;
|
|
78
86
|
const knowledgeEmbeddingModel = "text-embedding-3-small";
|
|
79
87
|
const amplifyBranch = (process.env.AWS_BRANCH ?? "").trim();
|
|
@@ -108,10 +116,19 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
108
116
|
assertValidMonitoringConfig(site.monitoring);
|
|
109
117
|
assertValidTenancyConfig(site.tenancy);
|
|
110
118
|
const tenancyMode = resolveTenancyMode(site.tenancy);
|
|
119
|
+
// A shared stack is one of two fixed tiers (docs/shared-stack.md). Its settings (reserved concurrency, alarm thresholds) come from
|
|
120
|
+
// amplify/shared-stack/settings.json, and a tier whose numbers are not measured yet refuses to synthesise.
|
|
121
|
+
const sharedTier = tenancyMode === "shared" ? sharedTierPlan(site.tenancy.tier) : undefined;
|
|
122
|
+
const sharedSettings = sharedTier ? sharedStackSettings(sharedTier.tier) : undefined;
|
|
123
|
+
const costAttribution = sharedTier ? sharedStackCostAttribution(sharedTier) : siteCostAttribution();
|
|
124
|
+
if (sharedTier && (publication?.projector !== undefined || publication?.staticDir !== undefined)) {
|
|
125
|
+
throw new Error("A shared stack serves many sites, so its publication cannot name one site's projector or static directory.");
|
|
126
|
+
}
|
|
111
127
|
const emailMonitorId = site.monitoring?.emailMonitorId ?? "hn";
|
|
112
128
|
const publicationPlan = planS3ProjectionBackend(publication);
|
|
113
129
|
const renditionsPlan = planRenditions(publication, process.cwd());
|
|
114
|
-
|
|
130
|
+
// The shared stack bundles no site's files: its configuration comes from the site store, one site per tenant.
|
|
131
|
+
setSiteFilesForContentActionsBundle(sharedTier ? [] : publicationPlan.enabled ? publicationPlan.siteFiles : undefined);
|
|
115
132
|
const plugins = resolvePlugins(site.plugins, { staticDir: publication?.staticDir });
|
|
116
133
|
const pluginDefinitions = Object.assign({}, ...plugins.map(({ plugin }) => plugin.schemaDefinitions()));
|
|
117
134
|
const pluginFunctions = Object.assign({}, ...plugins.map(({ plugin }) => plugin.functions()));
|
|
@@ -149,6 +166,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
149
166
|
slackEvents,
|
|
150
167
|
slackDelivery,
|
|
151
168
|
storage,
|
|
169
|
+
tenantClaims,
|
|
152
170
|
});
|
|
153
171
|
// Tenancy mode reaches every function; dedicated adds nothing, so an existing site's template is unchanged.
|
|
154
172
|
for (const resource of Object.values(backend)) {
|
|
@@ -163,6 +181,9 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
163
181
|
applyGoogleEmailVerifiedMapping(backend.auth.stack);
|
|
164
182
|
}
|
|
165
183
|
orderModelStacksInWaves(backend.data.resources.graphqlApi.node.scope, Object.keys(backend.data.resources.tables), site.resolverWaveSize ?? DEFAULT_RESOLVER_WAVE_SIZE);
|
|
184
|
+
// Session role claims (PPY-0bb0fd): the pre-token trigger moves to event version 2 on the Essentials plan and reads the two
|
|
185
|
+
// tenancy models when the `tenancy` model group is deployed. Dark: no authorization rule reads the claims yet.
|
|
186
|
+
applyTenantSessionClaims(backend.auth.resources.cfnResources.cfnUserPool, backend.tenantClaims.resources.lambda, "TenantMembership" in backend.data.resources.tables && "TenantSelection" in backend.data.resources.tables);
|
|
166
187
|
const requestedCognitoDomainPrefix = (authConfig.cognitoDomainPrefix ?? "").trim();
|
|
167
188
|
if (authConfig.applyCognitoDomainPrefix === true
|
|
168
189
|
&& requestedCognitoDomainPrefix !== ""
|
|
@@ -256,14 +277,14 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
256
277
|
actions: ["appsync:GraphQL"],
|
|
257
278
|
resources: ["*"],
|
|
258
279
|
}));
|
|
259
|
-
backend.slackEvents
|
|
280
|
+
connectToSiteApi(backend.slackEvents, graphqlEndpoint);
|
|
260
281
|
backend.slackEvents.addEnvironment("PAPYRUS_CONSOLE_RESPONSE_TARGET", (process.env.PAPYRUS_CONSOLE_RESPONSE_TARGET ?? "cloud").trim() || "cloud");
|
|
261
282
|
backend.slackEvents.addEnvironment("PAPYRUS_SLACK_ALLOWED_USER_IDS", (process.env.PAPYRUS_SLACK_ALLOWED_USER_IDS ?? "").trim());
|
|
262
283
|
if (amplifySsmEnvConfig) {
|
|
263
284
|
backend.slackEvents.addEnvironment("AMPLIFY_SSM_ENV_CONFIG", amplifySsmEnvConfig);
|
|
264
285
|
backend.slackDelivery.addEnvironment("AMPLIFY_SSM_ENV_CONFIG", amplifySsmEnvConfig);
|
|
265
286
|
}
|
|
266
|
-
backend.slackDelivery
|
|
287
|
+
connectToSiteApi(backend.slackDelivery, graphqlEndpoint);
|
|
267
288
|
backend.slackDelivery.addEnvironment("PAPYRUS_CONSOLE_RESPONSE_TARGET", (process.env.PAPYRUS_CONSOLE_RESPONSE_TARGET ?? "cloud").trim() || "cloud");
|
|
268
289
|
const slackBotTokenName = (process.env.PAPYRUS_SLACK_BOT_TOKEN_NAME ?? "PAPYRUS_SLACK_BOT_TOKEN").trim();
|
|
269
290
|
backend.slackDelivery.addEnvironment("PAPYRUS_SLACK_BOT_TOKEN", secret(slackBotTokenName));
|
|
@@ -398,7 +419,8 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
398
419
|
if (backendTenantId !== "") {
|
|
399
420
|
// editorialChecks too: it compares the site's editorial context (a tenant's publication) with its own tenant and refuses a mismatch,
|
|
400
421
|
// so without the variable every check after a save-version on a tenant site fails with "Editorial context tenant mismatch" (PPY-49303f).
|
|
401
|
-
|
|
422
|
+
// tenantClaims: a dedicated stack's fixed tenant is the one its session claims name (PPY-0bb0fd).
|
|
423
|
+
for (const tenantLambda of [contentActionsLambda, backend.categoryAction.resources.lambda, backend.assignmentAction.resources.lambda, backend.newsroomSummary.resources.lambda, backend.editorialChecks.resources.lambda, backend.tenantClaims.resources.lambda]) {
|
|
402
424
|
tenantLambda.addEnvironment("PAPYRUS_TENANT_ID", backendTenantId);
|
|
403
425
|
}
|
|
404
426
|
}
|
|
@@ -421,7 +443,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
421
443
|
// AppSync validates the token; pending intake additionally binds its actor
|
|
422
444
|
// and publication to this deployment's pool and existing API endpoint.
|
|
423
445
|
contentActionsLambda.addEnvironment("PAPYRUS_USER_POOL_ISSUER", `https://cognito-idp.${Stack.of(contentActionsLambda).region}.amazonaws.com/${backend.auth.resources.userPool.userPoolId}`);
|
|
424
|
-
contentActionsLambda
|
|
446
|
+
connectToSiteApi(contentActionsLambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
425
447
|
wireEmailReferenceIntake(contentActionsLambda, emailMonitorId);
|
|
426
448
|
contentActionsLambda.addToRolePolicy(new PolicyStatement({
|
|
427
449
|
actions: ["appsync:GraphQL"],
|
|
@@ -526,13 +548,13 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
526
548
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_DOMAIN", inboundEmailDomain);
|
|
527
549
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_LOCAL_PARTS", inboundEmailLocalParts.join(","));
|
|
528
550
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_CORPUS_KEY", inboundEmailCorpusKey);
|
|
529
|
-
inboundReceive
|
|
551
|
+
connectToSiteApi(inboundReceive, graphqlEndpoint);
|
|
530
552
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_EMAIL_CORPUS_KEY", inboundEmailCorpusKey);
|
|
531
553
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_EMAIL_DOMAIN", inboundEmailDomain);
|
|
532
554
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_FEEDBACK_EMAIL_ENABLED", "true");
|
|
533
555
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_FEEDBACK_FROM_EMAIL", `Papyrus Submissions <submissions@${inboundEmailDomain}>`);
|
|
534
556
|
inboundProcessor.addEnvironment("PAPYRUS_PUBLIC_SITE_BASE_URL", inbound.publicSiteBaseUrl);
|
|
535
|
-
inboundProcessor
|
|
557
|
+
connectToSiteApi(inboundProcessor, graphqlEndpoint);
|
|
536
558
|
receiveLambda.addToRolePolicy(new PolicyStatement({
|
|
537
559
|
actions: ["lambda:InvokeFunction"],
|
|
538
560
|
resources: [processorLambda.functionArn],
|
|
@@ -645,7 +667,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
645
667
|
const knowledgeQueryLambda = backend.knowledgeQuery.resources.lambda;
|
|
646
668
|
backend.knowledgeQuery.addEnvironment("OPENAI_API_KEY", secret("OPENAI_API_KEY"));
|
|
647
669
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_STORAGE_BUCKET_NAME", storageBucket.bucketName);
|
|
648
|
-
knowledgeQueryLambda
|
|
670
|
+
connectToSiteApi(knowledgeQueryLambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
649
671
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_S3_VECTOR_INDEX_ARN", knowledgeVectorIndex.attrIndexArn);
|
|
650
672
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_S3_VECTOR_INDEX_NAME", knowledgeVectorIndexName);
|
|
651
673
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_EMBEDDING_MODEL", knowledgeEmbeddingModel);
|
|
@@ -740,7 +762,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
740
762
|
});
|
|
741
763
|
wireEditorialChecks(backend);
|
|
742
764
|
// The functions that call models report their tokens to the site's Prospectus usage queue.
|
|
743
|
-
if (costAttribution) {
|
|
765
|
+
if (costAttribution && !sharedTier) {
|
|
744
766
|
const editorialChecksLambda = backend.editorialChecks.resources.lambda;
|
|
745
767
|
wireSiteUsageSender(editorialChecksLambda, costAttribution);
|
|
746
768
|
wireSiteUsageSender(knowledgeQueryLambda, costAttribution);
|
|
@@ -748,6 +770,9 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
748
770
|
// each fit one CloudFormation operation; the usage senders' stacks change in the first pass, so they go first.
|
|
749
771
|
applySiteBackendCostTags(backend.stack, costAttribution, [Stack.of(editorialChecksLambda), Stack.of(knowledgeQueryLambda)]);
|
|
750
772
|
}
|
|
773
|
+
// The shared stack reports usage per tenant through Prospectus later (kanbus-f45f7f); until then its resources are only tagged.
|
|
774
|
+
if (costAttribution && sharedTier)
|
|
775
|
+
applySiteBackendCostTags(backend.stack, costAttribution);
|
|
751
776
|
wireMonitoringView(backend, emailMonitorId);
|
|
752
777
|
wireAutomationView(backend);
|
|
753
778
|
wireImageService(backend);
|
|
@@ -755,5 +780,32 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
755
780
|
// Announcements are off until the owner turns them on; the parameters and the lease are per site (the brand id names the site).
|
|
756
781
|
wireAnnouncements(backend, siteBackendIdentity.brandId);
|
|
757
782
|
wirePlugins(backend, plugins, contentActionsLambda, s3ProjectionPublication !== undefined);
|
|
783
|
+
if (tenancyMode === "shared") {
|
|
784
|
+
// The loop at the top reaches the functions Amplify defines. A shared stack also has functions that wires and plugins make with `new Function`
|
|
785
|
+
// (the console chat responder, the reference word index consumer, the public forms handler); each must know it is shared.
|
|
786
|
+
for (const node of backend.stack.node.findAll()) {
|
|
787
|
+
if (!(node instanceof LambdaFunction) || isInfrastructureConstructId(node.node.id))
|
|
788
|
+
continue;
|
|
789
|
+
for (const [name, value] of Object.entries(tenancyFunctionEnvironment(tenancyMode)))
|
|
790
|
+
node.addEnvironment(name, value);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (sharedTier && sharedSettings) {
|
|
794
|
+
// Layers 2, 3 and 5 of the shared tier's isolation (the key, the boundary, reserved concurrency, alarms); the foundation stack holds the key and the boundary policy.
|
|
795
|
+
const isolation = applySharedStackIsolation(backend, sharedTier, sharedSettings);
|
|
796
|
+
const alarmsStack = backend.createStack("shared-alarms");
|
|
797
|
+
addSharedStackAlarms(alarmsStack, sharedTier, sharedSettings, {
|
|
798
|
+
functions: isolation.functionTargets,
|
|
799
|
+
appSyncApiId: backend.data.resources.graphqlApi.apiId,
|
|
800
|
+
tableNames: Object.values(backend.data.resources.tables).map((table) => table.tableName),
|
|
801
|
+
projectionDeadLetterQueueName: s3ProjectionPublication?.deadLetterQueue.queueName,
|
|
802
|
+
distributionId: s3ProjectionPublication?.distributionId,
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
else if (options.dedicatedSharedStackDeny !== false) {
|
|
806
|
+
// A dedicated site's roles may not touch the shared tier. Roles of the per-model data stacks are left alone (see addSharedStackDeny).
|
|
807
|
+
const modelNames = new Set(Object.keys(backend.data.resources.tables));
|
|
808
|
+
addSharedStackDeny(backend.stack, (stack) => isModelDataStack(stack, modelNames));
|
|
809
|
+
}
|
|
758
810
|
return backend;
|
|
759
811
|
}
|
package/amplify/site-backend.ts
CHANGED
|
@@ -26,7 +26,13 @@ import {
|
|
|
26
26
|
validateRevalidateDistributionIds,
|
|
27
27
|
} from "./revalidate-invalidation-settings";
|
|
28
28
|
import { enablePointInTimeRecoveryOnDataTables } from "./data-table-recovery";
|
|
29
|
-
import { applySiteBackendCostTags, siteCostAttribution, wireSiteUsageSender } from "./cost-attribution";
|
|
29
|
+
import { applySiteBackendCostTags, sharedStackCostAttribution, siteCostAttribution, wireSiteUsageSender } from "./cost-attribution";
|
|
30
|
+
import { addSharedStackAlarms } from "./shared-stack/alarms";
|
|
31
|
+
import { addSharedStackDeny, isModelDataStack } from "./shared-stack/deny";
|
|
32
|
+
import { isInfrastructureConstructId } from "./shared-stack/inline-policy";
|
|
33
|
+
import { applySharedStackIsolation } from "./shared-stack/isolation";
|
|
34
|
+
import { sharedTierPlan } from "./shared-stack/names";
|
|
35
|
+
import { sharedStackSettings } from "./shared-stack/settings";
|
|
30
36
|
import { addInvalidationPathAlarm } from "./publication/invalidation-alarm";
|
|
31
37
|
import { applyCognitoDomainPrefix, applyGoogleEmailVerifiedMapping, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource";
|
|
32
38
|
import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, CLI_FEDERATION_REFRESH_TOKEN_VALIDITY_DAYS, addProspectusGoogleOnlyClient, cliFederationClientCallbackUrls, trustClientOnIdentityPool } from "./auth/prospectus-google-client";
|
|
@@ -57,6 +63,8 @@ import { contentActions, setSiteFilesForContentActionsBundle } from "./functions
|
|
|
57
63
|
import { knowledgeQuery } from "./functions/knowledge-query/resource";
|
|
58
64
|
import { wireReferenceWordIndex } from "./functions/reference-word-index/wire";
|
|
59
65
|
import { manageUserRole } from "./functions/manage-user-role/resource";
|
|
66
|
+
import { tenantClaims } from "./functions/tenant-claims/resource";
|
|
67
|
+
import { applyTenantSessionClaims } from "./auth/tenant-session-claims";
|
|
60
68
|
import { modelAttachmentUpload } from "./functions/model-attachment-upload/resource";
|
|
61
69
|
import { newsroomSummary } from "./functions/newsroom-summary/resource";
|
|
62
70
|
import { derivePublicFormOrigins } from "./functions/public-forms/origins";
|
|
@@ -85,14 +93,22 @@ import {
|
|
|
85
93
|
import { addStorageBackups } from "./storage-backups/construct";
|
|
86
94
|
import { storage } from "./storage/resource";
|
|
87
95
|
import type { PapyrusSite } from "../lib/define-site";
|
|
96
|
+
import { connectToSiteApi } from "./site-api-access";
|
|
88
97
|
|
|
89
|
-
export
|
|
98
|
+
export type DefineSiteBackendOptions = {
|
|
99
|
+
/**
|
|
100
|
+
* Add the deny on the shared tier's resources to every dedicated role (default true). Only the synth test that proves the deny is
|
|
101
|
+
* the whole difference turns it off, to get the template without it.
|
|
102
|
+
*/
|
|
103
|
+
dedicatedSharedStackDeny?: boolean;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function defineSiteBackend(papyrusSite: PapyrusSite, options: DefineSiteBackendOptions = {}) {
|
|
90
107
|
// `papyrus.config.ts`'s default export. Backend options live under `backend`;
|
|
91
108
|
// the default brand id namespaces account-global resources.
|
|
92
109
|
const site = { brandId: papyrusSite.defaultBrand, ...papyrusSite.backend };
|
|
93
110
|
// Prospectus cost accounting: on when `papyrus-infra backend-deploy` asks for a cost tag wave (PAPYRUS_COST_TAG_WAVE).
|
|
94
|
-
// Null, from a plain `ampx pipeline-deploy`, leaves the backend untouched.
|
|
95
|
-
const costAttribution = siteCostAttribution();
|
|
111
|
+
// Null, from a plain `ampx pipeline-deploy`, leaves the backend untouched. A shared stack is always tagged (see below).
|
|
96
112
|
const knowledgeVectorDimension = 1536;
|
|
97
113
|
const knowledgeEmbeddingModel = "text-embedding-3-small";
|
|
98
114
|
|
|
@@ -130,10 +146,19 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
130
146
|
assertValidMonitoringConfig(site.monitoring);
|
|
131
147
|
assertValidTenancyConfig(site.tenancy);
|
|
132
148
|
const tenancyMode = resolveTenancyMode(site.tenancy);
|
|
149
|
+
// A shared stack is one of two fixed tiers (docs/shared-stack.md). Its settings (reserved concurrency, alarm thresholds) come from
|
|
150
|
+
// amplify/shared-stack/settings.json, and a tier whose numbers are not measured yet refuses to synthesise.
|
|
151
|
+
const sharedTier = tenancyMode === "shared" ? sharedTierPlan(site.tenancy!.tier!) : undefined;
|
|
152
|
+
const sharedSettings = sharedTier ? sharedStackSettings(sharedTier.tier) : undefined;
|
|
153
|
+
const costAttribution = sharedTier ? sharedStackCostAttribution(sharedTier) : siteCostAttribution();
|
|
154
|
+
if (sharedTier && (publication?.projector !== undefined || publication?.staticDir !== undefined)) {
|
|
155
|
+
throw new Error("A shared stack serves many sites, so its publication cannot name one site's projector or static directory.");
|
|
156
|
+
}
|
|
133
157
|
const emailMonitorId = site.monitoring?.emailMonitorId ?? "hn";
|
|
134
158
|
const publicationPlan = planS3ProjectionBackend(publication);
|
|
135
159
|
const renditionsPlan = planRenditions(publication, process.cwd());
|
|
136
|
-
|
|
160
|
+
// The shared stack bundles no site's files: its configuration comes from the site store, one site per tenant.
|
|
161
|
+
setSiteFilesForContentActionsBundle(sharedTier ? [] : publicationPlan.enabled ? publicationPlan.siteFiles : undefined);
|
|
137
162
|
const plugins = resolvePlugins(site.plugins, { staticDir: publication?.staticDir });
|
|
138
163
|
const pluginDefinitions = Object.assign({}, ...plugins.map(({ plugin }) => plugin.schemaDefinitions()));
|
|
139
164
|
const pluginFunctions: Record<never, never> = Object.assign({}, ...plugins.map(({ plugin }) => plugin.functions()));
|
|
@@ -171,6 +196,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
171
196
|
slackEvents,
|
|
172
197
|
slackDelivery,
|
|
173
198
|
storage,
|
|
199
|
+
tenantClaims,
|
|
174
200
|
});
|
|
175
201
|
|
|
176
202
|
// Tenancy mode reaches every function; dedicated adds nothing, so an existing site's template is unchanged.
|
|
@@ -192,6 +218,14 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
192
218
|
site.resolverWaveSize ?? DEFAULT_RESOLVER_WAVE_SIZE,
|
|
193
219
|
);
|
|
194
220
|
|
|
221
|
+
// Session role claims (PPY-0bb0fd): the pre-token trigger moves to event version 2 on the Essentials plan and reads the two
|
|
222
|
+
// tenancy models when the `tenancy` model group is deployed. Dark: no authorization rule reads the claims yet.
|
|
223
|
+
applyTenantSessionClaims(
|
|
224
|
+
backend.auth.resources.cfnResources.cfnUserPool,
|
|
225
|
+
backend.tenantClaims.resources.lambda,
|
|
226
|
+
"TenantMembership" in backend.data.resources.tables && "TenantSelection" in backend.data.resources.tables,
|
|
227
|
+
);
|
|
228
|
+
|
|
195
229
|
const requestedCognitoDomainPrefix = (authConfig.cognitoDomainPrefix ?? "").trim();
|
|
196
230
|
if (
|
|
197
231
|
authConfig.applyCognitoDomainPrefix === true
|
|
@@ -308,7 +342,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
308
342
|
resources: ["*"],
|
|
309
343
|
}),
|
|
310
344
|
);
|
|
311
|
-
backend.slackEvents
|
|
345
|
+
connectToSiteApi(backend.slackEvents, graphqlEndpoint);
|
|
312
346
|
backend.slackEvents.addEnvironment(
|
|
313
347
|
"PAPYRUS_CONSOLE_RESPONSE_TARGET",
|
|
314
348
|
(process.env.PAPYRUS_CONSOLE_RESPONSE_TARGET ?? "cloud").trim() || "cloud",
|
|
@@ -321,7 +355,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
321
355
|
backend.slackEvents.addEnvironment("AMPLIFY_SSM_ENV_CONFIG", amplifySsmEnvConfig);
|
|
322
356
|
backend.slackDelivery.addEnvironment("AMPLIFY_SSM_ENV_CONFIG", amplifySsmEnvConfig);
|
|
323
357
|
}
|
|
324
|
-
backend.slackDelivery
|
|
358
|
+
connectToSiteApi(backend.slackDelivery, graphqlEndpoint);
|
|
325
359
|
backend.slackDelivery.addEnvironment(
|
|
326
360
|
"PAPYRUS_CONSOLE_RESPONSE_TARGET",
|
|
327
361
|
(process.env.PAPYRUS_CONSOLE_RESPONSE_TARGET ?? "cloud").trim() || "cloud",
|
|
@@ -492,7 +526,8 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
492
526
|
if (backendTenantId !== "") {
|
|
493
527
|
// editorialChecks too: it compares the site's editorial context (a tenant's publication) with its own tenant and refuses a mismatch,
|
|
494
528
|
// so without the variable every check after a save-version on a tenant site fails with "Editorial context tenant mismatch" (PPY-49303f).
|
|
495
|
-
|
|
529
|
+
// tenantClaims: a dedicated stack's fixed tenant is the one its session claims name (PPY-0bb0fd).
|
|
530
|
+
for (const tenantLambda of [contentActionsLambda, backend.categoryAction.resources.lambda, backend.assignmentAction.resources.lambda, backend.newsroomSummary.resources.lambda, backend.editorialChecks.resources.lambda, backend.tenantClaims.resources.lambda]) {
|
|
496
531
|
(tenantLambda as LambdaFunction).addEnvironment("PAPYRUS_TENANT_ID", backendTenantId);
|
|
497
532
|
}
|
|
498
533
|
}
|
|
@@ -518,10 +553,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
518
553
|
"PAPYRUS_USER_POOL_ISSUER",
|
|
519
554
|
`https://cognito-idp.${Stack.of(contentActionsLambda).region}.amazonaws.com/${backend.auth.resources.userPool.userPoolId}`,
|
|
520
555
|
);
|
|
521
|
-
contentActionsLambda.
|
|
522
|
-
"PAPYRUS_GRAPHQL_ENDPOINT",
|
|
523
|
-
backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl,
|
|
524
|
-
);
|
|
556
|
+
connectToSiteApi(contentActionsLambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
525
557
|
wireEmailReferenceIntake(contentActionsLambda, emailMonitorId);
|
|
526
558
|
contentActionsLambda.addToRolePolicy(
|
|
527
559
|
new PolicyStatement({
|
|
@@ -643,7 +675,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
643
675
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_DOMAIN", inboundEmailDomain);
|
|
644
676
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_LOCAL_PARTS", inboundEmailLocalParts.join(","));
|
|
645
677
|
inboundReceive.addEnvironment("PAPYRUS_INBOUND_EMAIL_CORPUS_KEY", inboundEmailCorpusKey);
|
|
646
|
-
inboundReceive
|
|
678
|
+
connectToSiteApi(inboundReceive, graphqlEndpoint);
|
|
647
679
|
|
|
648
680
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_EMAIL_CORPUS_KEY", inboundEmailCorpusKey);
|
|
649
681
|
inboundProcessor.addEnvironment("PAPYRUS_INBOUND_EMAIL_DOMAIN", inboundEmailDomain);
|
|
@@ -653,7 +685,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
653
685
|
`Papyrus Submissions <submissions@${inboundEmailDomain}>`,
|
|
654
686
|
);
|
|
655
687
|
inboundProcessor.addEnvironment("PAPYRUS_PUBLIC_SITE_BASE_URL", inbound.publicSiteBaseUrl);
|
|
656
|
-
inboundProcessor
|
|
688
|
+
connectToSiteApi(inboundProcessor, graphqlEndpoint);
|
|
657
689
|
|
|
658
690
|
receiveLambda.addToRolePolicy(
|
|
659
691
|
new PolicyStatement({
|
|
@@ -788,10 +820,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
788
820
|
const knowledgeQueryLambda = backend.knowledgeQuery.resources.lambda as LambdaFunction;
|
|
789
821
|
backend.knowledgeQuery.addEnvironment("OPENAI_API_KEY", secret("OPENAI_API_KEY"));
|
|
790
822
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_STORAGE_BUCKET_NAME", storageBucket.bucketName);
|
|
791
|
-
knowledgeQueryLambda.
|
|
792
|
-
"PAPYRUS_GRAPHQL_ENDPOINT",
|
|
793
|
-
backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl,
|
|
794
|
-
);
|
|
823
|
+
connectToSiteApi(knowledgeQueryLambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
795
824
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_S3_VECTOR_INDEX_ARN", knowledgeVectorIndex.attrIndexArn);
|
|
796
825
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_S3_VECTOR_INDEX_NAME", knowledgeVectorIndexName);
|
|
797
826
|
knowledgeQueryLambda.addEnvironment("PAPYRUS_EMBEDDING_MODEL", knowledgeEmbeddingModel);
|
|
@@ -896,7 +925,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
896
925
|
});
|
|
897
926
|
wireEditorialChecks(backend);
|
|
898
927
|
// The functions that call models report their tokens to the site's Prospectus usage queue.
|
|
899
|
-
if (costAttribution) {
|
|
928
|
+
if (costAttribution && !sharedTier) {
|
|
900
929
|
const editorialChecksLambda = backend.editorialChecks.resources.lambda as LambdaFunction;
|
|
901
930
|
wireSiteUsageSender(editorialChecksLambda, costAttribution);
|
|
902
931
|
wireSiteUsageSender(knowledgeQueryLambda, costAttribution);
|
|
@@ -904,6 +933,8 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
904
933
|
// each fit one CloudFormation operation; the usage senders' stacks change in the first pass, so they go first.
|
|
905
934
|
applySiteBackendCostTags(backend.stack, costAttribution, [Stack.of(editorialChecksLambda), Stack.of(knowledgeQueryLambda)]);
|
|
906
935
|
}
|
|
936
|
+
// The shared stack reports usage per tenant through Prospectus later (kanbus-f45f7f); until then its resources are only tagged.
|
|
937
|
+
if (costAttribution && sharedTier) applySiteBackendCostTags(backend.stack, costAttribution);
|
|
907
938
|
wireMonitoringView(backend, emailMonitorId);
|
|
908
939
|
wireAutomationView(backend);
|
|
909
940
|
wireImageService(backend);
|
|
@@ -912,5 +943,30 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
912
943
|
wireAnnouncements(backend, siteBackendIdentity.brandId);
|
|
913
944
|
wirePlugins(backend, plugins, contentActionsLambda, s3ProjectionPublication !== undefined);
|
|
914
945
|
|
|
946
|
+
if (tenancyMode === "shared") {
|
|
947
|
+
// The loop at the top reaches the functions Amplify defines. A shared stack also has functions that wires and plugins make with `new Function`
|
|
948
|
+
// (the console chat responder, the reference word index consumer, the public forms handler); each must know it is shared.
|
|
949
|
+
for (const node of backend.stack.node.findAll()) {
|
|
950
|
+
if (!(node instanceof LambdaFunction) || isInfrastructureConstructId(node.node.id)) continue;
|
|
951
|
+
for (const [name, value] of Object.entries(tenancyFunctionEnvironment(tenancyMode))) node.addEnvironment(name, value);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (sharedTier && sharedSettings) {
|
|
955
|
+
// Layers 2, 3 and 5 of the shared tier's isolation (the key, the boundary, reserved concurrency, alarms); the foundation stack holds the key and the boundary policy.
|
|
956
|
+
const isolation = applySharedStackIsolation(backend, sharedTier, sharedSettings);
|
|
957
|
+
const alarmsStack = backend.createStack("shared-alarms");
|
|
958
|
+
addSharedStackAlarms(alarmsStack, sharedTier, sharedSettings, {
|
|
959
|
+
functions: isolation.functionTargets,
|
|
960
|
+
appSyncApiId: backend.data.resources.graphqlApi.apiId,
|
|
961
|
+
tableNames: Object.values(backend.data.resources.tables).map((table) => table.tableName),
|
|
962
|
+
projectionDeadLetterQueueName: s3ProjectionPublication?.deadLetterQueue.queueName,
|
|
963
|
+
distributionId: s3ProjectionPublication?.distributionId,
|
|
964
|
+
});
|
|
965
|
+
} else if (options.dedicatedSharedStackDeny !== false) {
|
|
966
|
+
// A dedicated site's roles may not touch the shared tier. Roles of the per-model data stacks are left alone (see addSharedStackDeny).
|
|
967
|
+
const modelNames = new Set(Object.keys(backend.data.resources.tables));
|
|
968
|
+
addSharedStackDeny(backend.stack, (stack) => isModelDataStack(stack, modelNames));
|
|
969
|
+
}
|
|
970
|
+
|
|
915
971
|
return backend;
|
|
916
972
|
}
|
|
@@ -3191,6 +3191,11 @@ async function listUserPoolModel<T>(modelName: string): Promise<T[]> {
|
|
|
3191
3191
|
return items;
|
|
3192
3192
|
}
|
|
3193
3193
|
|
|
3194
|
+
/** The site's Sections, read on their own (the shell dashboard is a summary that holds none). */
|
|
3195
|
+
export async function loadEditorNewsroomSections(): Promise<NewsroomSectionRecord[]> {
|
|
3196
|
+
return listOptionalUserPoolModel<NewsroomSectionRecord>("NewsroomSection");
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3194
3199
|
async function listOptionalUserPoolModel<T>(modelName: string): Promise<T[]> {
|
|
3195
3200
|
const client = generateClient<Schema>();
|
|
3196
3201
|
const model = (client.models as Record<string, ListableModel<T>>)[modelName];
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
} from "./ui/dialog";
|
|
16
16
|
import { Input } from "./ui/input";
|
|
17
17
|
import { isLocalPreviewEnabled } from "../lib/local-preview";
|
|
18
|
-
import {
|
|
18
|
+
import { newsroomDeskPickerOptions } from "../lib/newsroom-sections";
|
|
19
|
+
import { useNewsroomDeskSections } from "./use-newsroom-desk-sections";
|
|
19
20
|
import { StoryReportingTrailView } from "./story-reporting-trail";
|
|
20
21
|
import { loadNewestStoryVersion } from "./story-reporting-trail-client";
|
|
21
22
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "./ui/select";
|
|
@@ -173,7 +174,8 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false, stars
|
|
|
173
174
|
const latestVersionNumber = latestVersion?.number ?? null;
|
|
174
175
|
const [changeReason, setChangeReason] = useState("");
|
|
175
176
|
const citedKeys = useMemo(() => Object.values(((bodyIr as { papyrus?: { citations?: Record<string, string[]> } } | null)?.papyrus?.citations) ?? {}).flat(), [bodyIr]);
|
|
176
|
-
const
|
|
177
|
+
const { sections: deskSections, loading: deskSectionsLoading, error: deskSectionsError } = useNewsroomDeskSections();
|
|
178
|
+
const deskOptions = useMemo(() => newsroomDeskPickerOptions(deskSections, editor?.section), [deskSections, editor?.section]);
|
|
177
179
|
const [reloadToken, setReloadToken] = useState(0);
|
|
178
180
|
const [imageUrls, setImageUrls] = useState<Record<string, string>>({});
|
|
179
181
|
const [mediaIndex, setMediaIndex] = useState<MediaIndex>({ loaded: false, failed: false, assets: [] });
|
|
@@ -879,7 +881,9 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false, stars
|
|
|
879
881
|
) : null)}
|
|
880
882
|
</SelectContent>
|
|
881
883
|
</Select>
|
|
882
|
-
|
|
884
|
+
<small data-newsroom-article-section-status role="status" className="block h-6 overflow-hidden text-xs leading-6">
|
|
885
|
+
{deskSectionsLoading ? "Loading the site's sections…" : deskSectionsError ? `Could not load the site's sections: ${deskSectionsError}` : ""}
|
|
886
|
+
</small>
|
|
883
887
|
</label>
|
|
884
888
|
<label className="space-y-1 text-sm font-medium">
|
|
885
889
|
<span>Slug</span>
|