@anthusai/papyrus 5.111.0 → 5.112.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.
- 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 +16 -0
- package/amplify/data/resource.ts +17 -0
- package/amplify/data/schema.js +20 -1
- package/amplify/data/schema.ts +21 -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 +49 -21
- 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/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/signup/papyrus.plugin.js +2 -1
- package/amplify/plugins/signup/papyrus.plugin.ts +2 -1
- 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
package/amplify/auth/resource.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineAuth, secret } from "@aws-amplify/backend";
|
|
2
2
|
import { manageUserRole } from "../functions/manage-user-role/resource.js";
|
|
3
|
+
import { tenantClaims } from "../functions/tenant-claims/resource.js";
|
|
3
4
|
import { CfnUserPoolDomain, CfnUserPoolIdentityProvider } from "aws-cdk-lib/aws-cognito";
|
|
4
5
|
import { expandNewsroomRedirectUrls } from "./redirect-urls.js";
|
|
5
6
|
// Default OAuth redirect URLs for the p.apyr.us app. Other publications pass
|
|
@@ -76,6 +77,8 @@ export function defineSiteAuth(config, extraCallbackUrls = []) {
|
|
|
76
77
|
}),
|
|
77
78
|
},
|
|
78
79
|
groups: ["admin", "editor", "curator"],
|
|
80
|
+
// Wired as version 1 by Amplify; amplify/auth/tenant-session-claims.ts moves it to version 2 (access-token claims).
|
|
81
|
+
triggers: { preTokenGeneration: tenantClaims },
|
|
79
82
|
access: (allow) => [
|
|
80
83
|
allow.resource(manageUserRole).to(["addUserToGroup", "removeUserFromGroup", "listUsers", "listGroupsForUser"]),
|
|
81
84
|
],
|
package/amplify/auth/resource.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineAuth, secret } from "@aws-amplify/backend";
|
|
2
2
|
import { manageUserRole } from "../functions/manage-user-role/resource";
|
|
3
|
+
import { tenantClaims } from "../functions/tenant-claims/resource";
|
|
3
4
|
import { Stack } from "aws-cdk-lib";
|
|
4
5
|
import { CfnUserPoolDomain, CfnUserPoolIdentityProvider } from "aws-cdk-lib/aws-cognito";
|
|
5
6
|
import type { PapyrusAuthConfig } from "../site-backend-config";
|
|
@@ -88,6 +89,8 @@ export function defineSiteAuth(config: PapyrusAuthConfig, extraCallbackUrls: rea
|
|
|
88
89
|
}),
|
|
89
90
|
},
|
|
90
91
|
groups: ["admin", "editor", "curator"],
|
|
92
|
+
// Wired as version 1 by Amplify; amplify/auth/tenant-session-claims.ts moves it to version 2 (access-token claims).
|
|
93
|
+
triggers: { preTokenGeneration: tenantClaims },
|
|
91
94
|
access: (allow) => [
|
|
92
95
|
allow.resource(manageUserRole).to(["addUserToGroup", "removeUserFromGroup", "listUsers", "listGroupsForUser"]),
|
|
93
96
|
],
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TENANCY_MODELS_ENVIRONMENT_VARIABLE } from "../functions/tenant-claims/environment.js";
|
|
2
|
+
/** The Cognito feature plan that supports pre-token-generation event version 2 (access-token claims). Lite does not. */
|
|
3
|
+
export const TENANT_CLAIMS_USER_POOL_TIER = "ESSENTIALS";
|
|
4
|
+
/** The pre-token-generation event version that customises the access token as well as the ID token. */
|
|
5
|
+
export const TENANT_CLAIMS_TRIGGER_VERSION = "V2_0";
|
|
6
|
+
/**
|
|
7
|
+
* Wire the tenant claims function as the pool's pre-token-generation trigger at event version 2 (PPY-0bb0fd).
|
|
8
|
+
*
|
|
9
|
+
* Amplify's `triggers.preTokenGeneration` wires version 1, which customises only the ID token, and the Amplify data client
|
|
10
|
+
* sends the access token. The CDK escape hatch below moves the same function to `PreTokenGenerationConfig` at `V2_0` and
|
|
11
|
+
* removes the version 1 entry (the two must not both be set). Version 2 needs the Cognito Essentials plan, so the pool's
|
|
12
|
+
* `UserPoolTier` is set to it; that is a plan and cost change for every site that deploys this.
|
|
13
|
+
*
|
|
14
|
+
* `tenancyModelsDeployed` says whether TenantMembership and TenantSelection exist (the `tenancy` model group is deployed; a
|
|
15
|
+
* bootstrap deploy leaves it out). When they do not, the function reads nothing and emits only a dedicated stack's group claims.
|
|
16
|
+
*/
|
|
17
|
+
export function applyTenantSessionClaims(cfnUserPool, trigger, tenancyModelsDeployed) {
|
|
18
|
+
cfnUserPool.userPoolTier = TENANT_CLAIMS_USER_POOL_TIER;
|
|
19
|
+
cfnUserPool.addPropertyDeletionOverride("LambdaConfig.PreTokenGeneration");
|
|
20
|
+
cfnUserPool.addPropertyOverride("LambdaConfig.PreTokenGenerationConfig", {
|
|
21
|
+
LambdaArn: trigger.functionArn,
|
|
22
|
+
LambdaVersion: TENANT_CLAIMS_TRIGGER_VERSION,
|
|
23
|
+
});
|
|
24
|
+
if (tenancyModelsDeployed) {
|
|
25
|
+
trigger.addEnvironment(TENANCY_MODELS_ENVIRONMENT_VARIABLE, "true");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CfnUserPool } from "aws-cdk-lib/aws-cognito";
|
|
2
|
+
import type { IFunction } from "aws-cdk-lib/aws-lambda";
|
|
3
|
+
import { TENANCY_MODELS_ENVIRONMENT_VARIABLE } from "../functions/tenant-claims/environment";
|
|
4
|
+
|
|
5
|
+
/** The Cognito feature plan that supports pre-token-generation event version 2 (access-token claims). Lite does not. */
|
|
6
|
+
export const TENANT_CLAIMS_USER_POOL_TIER = "ESSENTIALS";
|
|
7
|
+
/** The pre-token-generation event version that customises the access token as well as the ID token. */
|
|
8
|
+
export const TENANT_CLAIMS_TRIGGER_VERSION = "V2_0";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wire the tenant claims function as the pool's pre-token-generation trigger at event version 2 (PPY-0bb0fd).
|
|
12
|
+
*
|
|
13
|
+
* Amplify's `triggers.preTokenGeneration` wires version 1, which customises only the ID token, and the Amplify data client
|
|
14
|
+
* sends the access token. The CDK escape hatch below moves the same function to `PreTokenGenerationConfig` at `V2_0` and
|
|
15
|
+
* removes the version 1 entry (the two must not both be set). Version 2 needs the Cognito Essentials plan, so the pool's
|
|
16
|
+
* `UserPoolTier` is set to it; that is a plan and cost change for every site that deploys this.
|
|
17
|
+
*
|
|
18
|
+
* `tenancyModelsDeployed` says whether TenantMembership and TenantSelection exist (the `tenancy` model group is deployed; a
|
|
19
|
+
* bootstrap deploy leaves it out). When they do not, the function reads nothing and emits only a dedicated stack's group claims.
|
|
20
|
+
*/
|
|
21
|
+
export function applyTenantSessionClaims(cfnUserPool: CfnUserPool, trigger: IFunction, tenancyModelsDeployed: boolean): void {
|
|
22
|
+
cfnUserPool.userPoolTier = TENANT_CLAIMS_USER_POOL_TIER;
|
|
23
|
+
cfnUserPool.addPropertyDeletionOverride("LambdaConfig.PreTokenGeneration");
|
|
24
|
+
cfnUserPool.addPropertyOverride("LambdaConfig.PreTokenGenerationConfig", {
|
|
25
|
+
LambdaArn: trigger.functionArn,
|
|
26
|
+
LambdaVersion: TENANT_CLAIMS_TRIGGER_VERSION,
|
|
27
|
+
});
|
|
28
|
+
if (tenancyModelsDeployed) {
|
|
29
|
+
(trigger as IFunction & { addEnvironment(key: string, value: string): unknown }).addEnvironment(TENANCY_MODELS_ENVIRONMENT_VARIABLE, "true");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -5,6 +5,8 @@ import path from "node:path";
|
|
|
5
5
|
import { applyCostTagWaves, costTagWave } from "./cost-tag-waves.js";
|
|
6
6
|
import { costTags } from "./vendor/anthus-cost-accounting/tags.js";
|
|
7
7
|
import { OWNER } from "./vendor/anthus-cost-accounting/cdk.js";
|
|
8
|
+
import { isReservedDeployment } from "./shared-stack/names.js";
|
|
9
|
+
import { SHARED } from "./vendor/anthus-cost-accounting/tags.js";
|
|
8
10
|
/**
|
|
9
11
|
* Prospectus cost accounting in a site's Amplify backend (Prospectus docs/COST_ACCOUNTING.md).
|
|
10
12
|
*
|
|
@@ -49,8 +51,18 @@ export function siteCostAttribution(env = process.env, root = process.cwd()) {
|
|
|
49
51
|
}
|
|
50
52
|
if (!SITE_ID.test(siteId))
|
|
51
53
|
throw new Error("The site ID must be lower-case letters, digits and hyphens.");
|
|
54
|
+
if (isReservedDeployment(siteId))
|
|
55
|
+
throw new Error(`The site ID ${siteId} is a deployment value of the shared tier (shared, shared-prod, shared-staging); a dedicated site cannot use it.`);
|
|
52
56
|
return { account: OWNER, app: "papyrus", deployment: siteId, wave };
|
|
53
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A shared stack's cost attribution: account `shared` (Prospectus splits the cost by each tenant's reported usage) and the
|
|
60
|
+
* tier's own deployment value, so each stack has its own line in Cost Explorer and its own budget. Always every wave: a
|
|
61
|
+
* shared stack is created fresh by the pipeline, so there is no earlier release to split the tagging across.
|
|
62
|
+
*/
|
|
63
|
+
export function sharedStackCostAttribution(plan) {
|
|
64
|
+
return { account: SHARED, app: "papyrus", deployment: plan.deployment, wave: Number.POSITIVE_INFINITY };
|
|
65
|
+
}
|
|
54
66
|
/**
|
|
55
67
|
* Tags the backend's resources, in every nested stack, up to the build's wave. `first` names stacks that change in
|
|
56
68
|
* the first pass anyway (the usage senders'), so their tags arrive in the same operation.
|
|
@@ -6,6 +6,8 @@ import path from "node:path";
|
|
|
6
6
|
import { applyCostTagWaves, costTagWave } from "./cost-tag-waves";
|
|
7
7
|
import { costTags } from "./vendor/anthus-cost-accounting/tags";
|
|
8
8
|
import { OWNER, type CostTagConfiguration } from "./vendor/anthus-cost-accounting/cdk";
|
|
9
|
+
import { isReservedDeployment, type SharedTierPlan } from "./shared-stack/names";
|
|
10
|
+
import { SHARED } from "./vendor/anthus-cost-accounting/tags";
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Prospectus cost accounting in a site's Amplify backend (Prospectus docs/COST_ACCOUNTING.md).
|
|
@@ -54,9 +56,19 @@ export function siteCostAttribution(env: Record<string, string | undefined> = pr
|
|
|
54
56
|
);
|
|
55
57
|
}
|
|
56
58
|
if (!SITE_ID.test(siteId)) throw new Error("The site ID must be lower-case letters, digits and hyphens.");
|
|
59
|
+
if (isReservedDeployment(siteId)) throw new Error(`The site ID ${siteId} is a deployment value of the shared tier (shared, shared-prod, shared-staging); a dedicated site cannot use it.`);
|
|
57
60
|
return { account: OWNER, app: "papyrus", deployment: siteId, wave };
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
/**
|
|
64
|
+
* A shared stack's cost attribution: account `shared` (Prospectus splits the cost by each tenant's reported usage) and the
|
|
65
|
+
* tier's own deployment value, so each stack has its own line in Cost Explorer and its own budget. Always every wave: a
|
|
66
|
+
* shared stack is created fresh by the pipeline, so there is no earlier release to split the tagging across.
|
|
67
|
+
*/
|
|
68
|
+
export function sharedStackCostAttribution(plan: SharedTierPlan): SiteCostAttribution {
|
|
69
|
+
return { account: SHARED, app: "papyrus", deployment: plan.deployment, wave: Number.POSITIVE_INFINITY };
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
/**
|
|
61
73
|
* Tags the backend's resources, in every nested stack, up to the build's wave. `first` names stacks that change in
|
|
62
74
|
* the first pass anyway (the usage senders'), so their tags arrive in the same operation.
|
package/amplify/data/resource.js
CHANGED
|
@@ -1566,6 +1566,22 @@ const schema = a.schema({
|
|
|
1566
1566
|
allow.group(adminGroup),
|
|
1567
1567
|
allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
|
|
1568
1568
|
]),
|
|
1569
|
+
/**
|
|
1570
|
+
* The site a person's session acts for; id = the person's Cognito sub. The Google sign-in flow cannot tell the token trigger
|
|
1571
|
+
* which site was chosen, so the choice is stored here and the trigger reads it (PPY-0bb0fd). A person writes only their
|
|
1572
|
+
* own row (the owner is the id itself, so nobody can write another person's), and a selection without an active
|
|
1573
|
+
* TenantMembership grants nothing. Group "tenancy".
|
|
1574
|
+
*/
|
|
1575
|
+
TenantSelection: a
|
|
1576
|
+
.model({
|
|
1577
|
+
id: a.id().required(),
|
|
1578
|
+
selectedTenantId: a.string().required(),
|
|
1579
|
+
selectedAt: a.datetime().required(),
|
|
1580
|
+
})
|
|
1581
|
+
.authorization((allow) => [
|
|
1582
|
+
allow.group(adminGroup),
|
|
1583
|
+
allow.ownerDefinedIn("id").identityClaim("sub").to(["create", "read", "update"]),
|
|
1584
|
+
]),
|
|
1569
1585
|
/** A hostname served for a tenant; id = the lowercase hostname, so it can belong to one tenant only (PPY-31c45c). Group "tenancy". */
|
|
1570
1586
|
TenantDomain: a
|
|
1571
1587
|
.model({
|
package/amplify/data/resource.ts
CHANGED
|
@@ -1698,6 +1698,23 @@ const schema = a.schema({
|
|
|
1698
1698
|
allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
|
|
1699
1699
|
]),
|
|
1700
1700
|
|
|
1701
|
+
/**
|
|
1702
|
+
* The site a person's session acts for; id = the person's Cognito sub. The Google sign-in flow cannot tell the token trigger
|
|
1703
|
+
* which site was chosen, so the choice is stored here and the trigger reads it (PPY-0bb0fd). A person writes only their
|
|
1704
|
+
* own row (the owner is the id itself, so nobody can write another person's), and a selection without an active
|
|
1705
|
+
* TenantMembership grants nothing. Group "tenancy".
|
|
1706
|
+
*/
|
|
1707
|
+
TenantSelection: a
|
|
1708
|
+
.model({
|
|
1709
|
+
id: a.id().required(),
|
|
1710
|
+
selectedTenantId: a.string().required(),
|
|
1711
|
+
selectedAt: a.datetime().required(),
|
|
1712
|
+
})
|
|
1713
|
+
.authorization((allow) => [
|
|
1714
|
+
allow.group(adminGroup),
|
|
1715
|
+
allow.ownerDefinedIn("id").identityClaim("sub").to(["create", "read", "update"]),
|
|
1716
|
+
]),
|
|
1717
|
+
|
|
1701
1718
|
/** A hostname served for a tenant; id = the lowercase hostname, so it can belong to one tenant only (PPY-31c45c). Group "tenancy". */
|
|
1702
1719
|
TenantDomain: a
|
|
1703
1720
|
.model({
|
package/amplify/data/schema.js
CHANGED
|
@@ -13,6 +13,7 @@ import { monitoringViewSchemaDefinitions } from "../functions/monitoring-view/sc
|
|
|
13
13
|
import { contentActions } from "../functions/content-actions/resource.js";
|
|
14
14
|
import { knowledgeQuery } from "../functions/knowledge-query/resource.js";
|
|
15
15
|
import { manageUserRole } from "../functions/manage-user-role/resource.js";
|
|
16
|
+
import { tenantClaims } from "../functions/tenant-claims/resource.js";
|
|
16
17
|
import { modelAttachmentUpload } from "../functions/model-attachment-upload/resource.js";
|
|
17
18
|
import { newsroomSummary } from "../functions/newsroom-summary/resource.js";
|
|
18
19
|
import { publicForms } from "../functions/public-forms/resource.js";
|
|
@@ -49,7 +50,7 @@ export const OPTIONAL_MODEL_GROUPS = {
|
|
|
49
50
|
editorial: ["EditorialCheckRun", "EditorialFeedback", "EditorialPolicy", "EditorialCheckSettings"],
|
|
50
51
|
steering: ["SteeringProposal", "SteeringDecision", "LexicalSteeringRule"],
|
|
51
52
|
variations: ["StoryVariation"],
|
|
52
|
-
tenancy: ["Tenant", "TenantMembership", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
|
|
53
|
+
tenancy: ["Tenant", "TenantMembership", "TenantSelection", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
|
|
53
54
|
localization: ["LocalizationRequest"],
|
|
54
55
|
};
|
|
55
56
|
/**
|
|
@@ -1090,6 +1091,7 @@ function buildBaseDefinitions(excludedGroups = []) {
|
|
|
1090
1091
|
assignmentId: a.id(),
|
|
1091
1092
|
maxCharacters: a.integer(),
|
|
1092
1093
|
optionalPublicationDoctrine: a.boolean(),
|
|
1094
|
+
tenantId: a.string(), // an IAM caller (the editorial-checks function) names its tenant; a signed-in caller's comes from its token
|
|
1093
1095
|
})
|
|
1094
1096
|
.returns(a.json().required())
|
|
1095
1097
|
.authorization((allow) => [allow.groups(categoryWriteGroups)])
|
|
@@ -2695,6 +2697,21 @@ function buildBaseDefinitions(excludedGroups = []) {
|
|
|
2695
2697
|
allow.group(adminGroup),
|
|
2696
2698
|
allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
|
|
2697
2699
|
]),
|
|
2700
|
+
/**
|
|
2701
|
+
* The site a person's session acts for; id = the person's Cognito sub. The Google sign-in flow cannot tell the token trigger
|
|
2702
|
+
* which site was chosen, so the choice is stored here and the trigger reads it (PPY-0bb0fd). A person writes only their
|
|
2703
|
+
* own row (the owner is the id itself, so nobody can write another person's), and a selection without an active
|
|
2704
|
+
* TenantMembership grants nothing. Group "tenancy".
|
|
2705
|
+
*/
|
|
2706
|
+
TenantSelection: modelWithoutSubscriptions({
|
|
2707
|
+
id: a.id().required(),
|
|
2708
|
+
selectedTenantId: a.string().required(),
|
|
2709
|
+
selectedAt: a.datetime().required(),
|
|
2710
|
+
})
|
|
2711
|
+
.authorization((allow) => [
|
|
2712
|
+
allow.group(adminGroup),
|
|
2713
|
+
allow.ownerDefinedIn("id").identityClaim("sub").to(["create", "read", "update"]),
|
|
2714
|
+
]),
|
|
2698
2715
|
/** A hostname served for a tenant; id = the lowercase hostname, so it can belong to one tenant only (PPY-31c45c). Group "tenancy". */
|
|
2699
2716
|
TenantDomain: modelWithoutSubscriptions({
|
|
2700
2717
|
id: a.id().required(),
|
|
@@ -2778,6 +2795,8 @@ function functionGrants(allow) {
|
|
|
2778
2795
|
allow.resource(newsroomSummary),
|
|
2779
2796
|
allow.resource(procedureAction),
|
|
2780
2797
|
allow.resource(publicForms).to(["mutate"]),
|
|
2798
|
+
// The token trigger reads TenantMembership and TenantSelection by id; it can query, never write (PPY-0bb0fd).
|
|
2799
|
+
allow.resource(tenantClaims).to(["query"]),
|
|
2781
2800
|
];
|
|
2782
2801
|
}
|
|
2783
2802
|
/**
|
package/amplify/data/schema.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { monitoringViewSchemaDefinitions } from "../functions/monitoring-view/sc
|
|
|
13
13
|
import { contentActions } from "../functions/content-actions/resource";
|
|
14
14
|
import { knowledgeQuery } from "../functions/knowledge-query/resource";
|
|
15
15
|
import { manageUserRole } from "../functions/manage-user-role/resource";
|
|
16
|
+
import { tenantClaims } from "../functions/tenant-claims/resource";
|
|
16
17
|
import { modelAttachmentUpload } from "../functions/model-attachment-upload/resource";
|
|
17
18
|
import { newsroomSummary } from "../functions/newsroom-summary/resource";
|
|
18
19
|
import { publicForms } from "../functions/public-forms/resource";
|
|
@@ -52,7 +53,7 @@ export const OPTIONAL_MODEL_GROUPS = {
|
|
|
52
53
|
editorial: ["EditorialCheckRun", "EditorialFeedback", "EditorialPolicy", "EditorialCheckSettings"],
|
|
53
54
|
steering: ["SteeringProposal", "SteeringDecision", "LexicalSteeringRule"],
|
|
54
55
|
variations: ["StoryVariation"],
|
|
55
|
-
tenancy: ["Tenant", "TenantMembership", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
|
|
56
|
+
tenancy: ["Tenant", "TenantMembership", "TenantSelection", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
|
|
56
57
|
localization: ["LocalizationRequest"],
|
|
57
58
|
} as const;
|
|
58
59
|
|
|
@@ -1198,6 +1199,7 @@ const definitions = {
|
|
|
1198
1199
|
assignmentId: a.id(),
|
|
1199
1200
|
maxCharacters: a.integer(),
|
|
1200
1201
|
optionalPublicationDoctrine: a.boolean(),
|
|
1202
|
+
tenantId: a.string(), // an IAM caller (the editorial-checks function) names its tenant; a signed-in caller's comes from its token
|
|
1201
1203
|
})
|
|
1202
1204
|
.returns(a.json().required())
|
|
1203
1205
|
.authorization((allow) => [allow.groups(categoryWriteGroups)])
|
|
@@ -2863,6 +2865,22 @@ const definitions = {
|
|
|
2863
2865
|
allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
|
|
2864
2866
|
]),
|
|
2865
2867
|
|
|
2868
|
+
/**
|
|
2869
|
+
* The site a person's session acts for; id = the person's Cognito sub. The Google sign-in flow cannot tell the token trigger
|
|
2870
|
+
* which site was chosen, so the choice is stored here and the trigger reads it (PPY-0bb0fd). A person writes only their
|
|
2871
|
+
* own row (the owner is the id itself, so nobody can write another person's), and a selection without an active
|
|
2872
|
+
* TenantMembership grants nothing. Group "tenancy".
|
|
2873
|
+
*/
|
|
2874
|
+
TenantSelection: modelWithoutSubscriptions({
|
|
2875
|
+
id: a.id().required(),
|
|
2876
|
+
selectedTenantId: a.string().required(),
|
|
2877
|
+
selectedAt: a.datetime().required(),
|
|
2878
|
+
})
|
|
2879
|
+
.authorization((allow) => [
|
|
2880
|
+
allow.group(adminGroup),
|
|
2881
|
+
allow.ownerDefinedIn("id").identityClaim("sub").to(["create", "read", "update"]),
|
|
2882
|
+
]),
|
|
2883
|
+
|
|
2866
2884
|
/** A hostname served for a tenant; id = the lowercase hostname, so it can belong to one tenant only (PPY-31c45c). Group "tenancy". */
|
|
2867
2885
|
TenantDomain: modelWithoutSubscriptions({
|
|
2868
2886
|
id: a.id().required(),
|
|
@@ -2951,6 +2969,8 @@ function functionGrants(allow: any) {
|
|
|
2951
2969
|
allow.resource(newsroomSummary),
|
|
2952
2970
|
allow.resource(procedureAction),
|
|
2953
2971
|
allow.resource(publicForms).to(["mutate"]),
|
|
2972
|
+
// The token trigger reads TenantMembership and TenantSelection by id; it can query, never write (PPY-0bb0fd).
|
|
2973
|
+
allow.resource(tenantClaims).to(["query"]),
|
|
2954
2974
|
];
|
|
2955
2975
|
}
|
|
2956
2976
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assignmentDoctrine, resolveEditorialContext, type EditorialClient } from "../shared/editorial-context";
|
|
2
|
-
import {
|
|
2
|
+
import { actingFor, buildEventTenantContext, currentTenantContext } from "../shared/tenant-context";
|
|
3
|
+
import { newsroomSummaryPayloadId, tenantScopedClient } from "../shared/tenant-scoped-client";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { spawnSync } from "node:child_process";
|
|
5
6
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -32,13 +33,17 @@ type DataClientResult<T = unknown> = {
|
|
|
32
33
|
|
|
33
34
|
const FINAL_STATUSES = new Set(["completed", "canceled"]);
|
|
34
35
|
const IMMEDIATE_ASSIGNMENT_TYPES = new Set(["procedure.run"]);
|
|
35
|
-
const NEWSROOM_SUMMARY_PAYLOAD_ID = "knowledge-raw-payload-newsroom-summary-current";
|
|
36
36
|
const NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND = "knowledgeRawPayload";
|
|
37
37
|
const SUMMARY_STALE_AFTER_MS = 15 * 60 * 1000;
|
|
38
38
|
let clientPromise: Promise<DataClient> | null = null;
|
|
39
39
|
let editorialEndpoint: string | undefined;
|
|
40
40
|
|
|
41
41
|
export const handler = async (event: any): Promise<any> => {
|
|
42
|
+
const context = buildEventTenantContext(event); // one context per call; a shared stack refuses before any read
|
|
43
|
+
return actingFor(context, () => handleField(event));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
async function handleField(event: any): Promise<any> {
|
|
42
47
|
const fieldName = normalizeRequiredString(event.info?.fieldName ?? event.fieldName, "fieldName");
|
|
43
48
|
if (fieldName === "getEditorialContext") return getEditorialContext(event as Parameters<Schema["getEditorialContext"]["functionHandler"]>[0]);
|
|
44
49
|
if (fieldName === "getAssignmentContext") return getAssignmentContext(event as Parameters<Schema["getAssignmentContext"]["functionHandler"]>[0]);
|
|
@@ -46,7 +51,7 @@ export const handler = async (event: any): Promise<any> => {
|
|
|
46
51
|
if (fieldName === "listAssignmentsForObject") return listAssignmentsForObject(event as Parameters<Schema["listAssignmentsForObject"]["functionHandler"]>[0]);
|
|
47
52
|
if (fieldName === "retryImmediateAssignment") return retryImmediateAssignment(event as Parameters<Schema["retryImmediateAssignment"]["functionHandler"]>[0]);
|
|
48
53
|
return mutateAssignment(event as Parameters<Schema["claimAssignment"]["functionHandler"]>[0], fieldName);
|
|
49
|
-
}
|
|
54
|
+
}
|
|
50
55
|
|
|
51
56
|
async function mutateAssignment(event: Parameters<Schema["claimAssignment"]["functionHandler"]>[0], fieldName: string) {
|
|
52
57
|
const client = await getDataClient();
|
|
@@ -231,7 +236,7 @@ async function updateNewsroomSummaryForAssignmentAction(
|
|
|
231
236
|
client: DataClient,
|
|
232
237
|
input: { assignmentTypeKey: string | null; sectionKey: string | null; previousStatus: string | null; nextStatus: string | null; now: string },
|
|
233
238
|
): Promise<void> {
|
|
234
|
-
const response = await client.models.KnowledgeRawPayload.get({ id:
|
|
239
|
+
const response = await client.models.KnowledgeRawPayload.get({ id: newsroomSummaryPayloadId(currentTenantContext()) });
|
|
235
240
|
assertNoDataErrors(response.errors, "get Newsroom summary snapshot");
|
|
236
241
|
const payload = normalizeSummaryPayload(await readNewsroomSummaryPayload(client), input.now);
|
|
237
242
|
payload.generatedAt = input.now;
|
|
@@ -319,7 +324,7 @@ async function listAssignmentsForObject(event: Parameters<Schema["listAssignment
|
|
|
319
324
|
async function editorialContext(client: DataClient, scope: { publicationKey?: string; sectionId?: string | null; storyLineageId?: string | null; assignmentId?: string | null; maxCharacters?: number | null; optionalPublicationDoctrine?: boolean | null }) {
|
|
320
325
|
if (!editorialEndpoint) throw new Error("Editorial context requires the configured backend endpoint.");
|
|
321
326
|
return resolveEditorialContext(client as unknown as EditorialClient, {
|
|
322
|
-
...scope, endpoint: editorialEndpoint, tenantId:
|
|
327
|
+
...scope, endpoint: editorialEndpoint, tenantId: currentTenantContext().tenantId ?? undefined, includeGuidelines: true, readAttachment: readEditorialAttachment,
|
|
323
328
|
});
|
|
324
329
|
}
|
|
325
330
|
|
|
@@ -1023,7 +1028,7 @@ async function getDataClient(): Promise<DataClient> {
|
|
|
1023
1028
|
return generateClient<Schema>();
|
|
1024
1029
|
})();
|
|
1025
1030
|
}
|
|
1026
|
-
return clientPromise;
|
|
1031
|
+
return tenantScopedClient(await clientPromise, currentTenantContext());
|
|
1027
1032
|
}
|
|
1028
1033
|
|
|
1029
1034
|
async function getRequiredRecord(
|
|
@@ -1201,7 +1206,7 @@ async function upsertNewsroomSummaryPayload(
|
|
|
1201
1206
|
now: string,
|
|
1202
1207
|
): Promise<void> {
|
|
1203
1208
|
const input = {
|
|
1204
|
-
id:
|
|
1209
|
+
id: newsroomSummaryPayloadId(currentTenantContext()),
|
|
1205
1210
|
ownerType: "newsroom",
|
|
1206
1211
|
ownerId: "newsroom",
|
|
1207
1212
|
payloadKind: "summary-snapshot",
|
|
@@ -1216,7 +1221,7 @@ async function upsertNewsroomSummaryPayload(
|
|
|
1216
1221
|
}
|
|
1217
1222
|
await putJsonModelPayload(
|
|
1218
1223
|
client as any,
|
|
1219
|
-
{ ownerKind: NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND, ownerId:
|
|
1224
|
+
{ ownerKind: NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND, ownerId: newsroomSummaryPayloadId(currentTenantContext()), importRunId: input.importRunId },
|
|
1220
1225
|
"raw_payload",
|
|
1221
1226
|
"summary-snapshot",
|
|
1222
1227
|
payload,
|
|
@@ -1228,7 +1233,7 @@ async function readNewsroomSummaryPayload(client: DataClient): Promise<Record<st
|
|
|
1228
1233
|
return readJsonModelPayload(
|
|
1229
1234
|
client as any,
|
|
1230
1235
|
NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND,
|
|
1231
|
-
|
|
1236
|
+
newsroomSummaryPayloadId(currentTenantContext()),
|
|
1232
1237
|
"raw_payload",
|
|
1233
1238
|
"summary-snapshot",
|
|
1234
1239
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
3
3
|
import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringViewParameterArn, monitoringViewTableArns, } from "../monitoring-view/wire.js";
|
|
4
|
+
import { connectToSiteApi } from "../../site-api-access.js";
|
|
4
5
|
/** The reads the function makes of its own site's API with its own role. It writes nothing there. */
|
|
5
6
|
export const AUTOMATION_VIEW_FUNCTION_FIELDS = [
|
|
6
7
|
"Query/fields/getAutomation",
|
|
@@ -23,7 +24,7 @@ export const AUTOMATION_RUN_NOW_LEADING_KEYS = ["MONITOR#*"];
|
|
|
23
24
|
export function wireAutomationView(backend) {
|
|
24
25
|
const lambda = backend.automationView.resources.lambda;
|
|
25
26
|
const stack = Stack.of(lambda);
|
|
26
|
-
lambda
|
|
27
|
+
connectToSiteApi(lambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
27
28
|
lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
|
|
28
29
|
lambda.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
|
|
29
30
|
const apiId = backend.data.resources.graphqlApi.apiId;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
monitoringViewParameterArn,
|
|
8
8
|
monitoringViewTableArns,
|
|
9
9
|
} from "../monitoring-view/wire";
|
|
10
|
+
import { connectToSiteApi } from "../../site-api-access";
|
|
10
11
|
|
|
11
12
|
/** The reads the function makes of its own site's API with its own role. It writes nothing there. */
|
|
12
13
|
export const AUTOMATION_VIEW_FUNCTION_FIELDS = [
|
|
@@ -33,7 +34,7 @@ export const AUTOMATION_RUN_NOW_LEADING_KEYS = ["MONITOR#*"];
|
|
|
33
34
|
export function wireAutomationView(backend: any): void {
|
|
34
35
|
const lambda = backend.automationView.resources.lambda as LambdaFunction;
|
|
35
36
|
const stack = Stack.of(lambda);
|
|
36
|
-
lambda
|
|
37
|
+
connectToSiteApi(lambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl as string);
|
|
37
38
|
lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
|
|
38
39
|
lambda.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
|
|
39
40
|
const apiId = backend.data.resources.graphqlApi.apiId as string;
|
|
@@ -5,6 +5,8 @@ import { Amplify } from "aws-amplify";
|
|
|
5
5
|
import { generateClient } from "aws-amplify/data";
|
|
6
6
|
import type { Schema } from "../../data/resource";
|
|
7
7
|
import { putJsonModelPayload, putTextModelPayload, readJsonModelPayload } from "../shared/model-payloads";
|
|
8
|
+
import { actingFor, buildEventTenantContext, currentTenantContext } from "../shared/tenant-context";
|
|
9
|
+
import { newsroomSummaryPayloadId, tenantScopedClient } from "../shared/tenant-scoped-client";
|
|
8
10
|
import { curationActorKind, referenceStarFields, referenceVoteFields, validatedCurationSectionId } from "../shared/reference-curation-metadata";
|
|
9
11
|
import {
|
|
10
12
|
delegationExpiry,
|
|
@@ -131,7 +133,6 @@ const CATEGORY_PROPOSAL_KINDS = new Set([
|
|
|
131
133
|
"move-category",
|
|
132
134
|
"archive-category",
|
|
133
135
|
]);
|
|
134
|
-
const NEWSROOM_SUMMARY_PAYLOAD_ID = "knowledge-raw-payload-newsroom-summary-current";
|
|
135
136
|
const NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND = "knowledgeRawPayload";
|
|
136
137
|
const SUMMARY_STALE_AFTER_MS = 15 * 60 * 1000;
|
|
137
138
|
const REFERENCE_CURATION_ASSIGNMENT_TYPE = "curation.reference-refresh";
|
|
@@ -156,6 +157,11 @@ const DEFAULT_REFERENCE_CURATION_POLICY = {
|
|
|
156
157
|
let clientPromise: Promise<DataClient> | null = null;
|
|
157
158
|
|
|
158
159
|
export const handler = async (event: CategoryActionEvent) => {
|
|
160
|
+
const context = buildEventTenantContext(event); // one context per call; a shared stack refuses before any read
|
|
161
|
+
return actingFor(context, () => handleField(event));
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
async function handleField(event: CategoryActionEvent) {
|
|
159
165
|
const fieldName = normalizeOptionalString(event.info?.fieldName) ?? normalizeOptionalString((event as { fieldName?: string | null }).fieldName);
|
|
160
166
|
if (!fieldName) {
|
|
161
167
|
throw new Error("Unsupported steering action: missing GraphQL field name.");
|
|
@@ -195,7 +201,7 @@ export const handler = async (event: CategoryActionEvent) => {
|
|
|
195
201
|
if (fieldName === "archiveDraftCategory") return archiveDraftCategory(event as Parameters<ArchiveDraftCategoryHandler>[0]);
|
|
196
202
|
if (fieldName === "reviewReferenceTopicLabel") return reviewReferenceTopicLabel(event as Parameters<ReviewReferenceTopicLabelHandler>[0]);
|
|
197
203
|
throw new Error(`Unsupported steering action ${fieldName}.`);
|
|
198
|
-
}
|
|
204
|
+
}
|
|
199
205
|
|
|
200
206
|
async function reviewSteeringProposal(event: Parameters<ReviewHandler>[0]) {
|
|
201
207
|
const client = await getDataClient();
|
|
@@ -310,7 +316,7 @@ async function reviewReferenceCuration(
|
|
|
310
316
|
delegation,
|
|
311
317
|
decisionRelationId,
|
|
312
318
|
}),
|
|
313
|
-
newsroomFeedKey: reference.newsroomFeedKey ?? globalKey(REFERENCE_FEED_KEY),
|
|
319
|
+
newsroomFeedKey: reference.newsroomFeedKey ?? globalKey(REFERENCE_FEED_KEY, currentTenantContext().tenantId),
|
|
314
320
|
reviewedFeedKey: reviewedFeedKeyForStatus(nextStatus),
|
|
315
321
|
// A vote moves the Reference between the unrated and rated feeds; its original prediction and arrival stay as they were.
|
|
316
322
|
feedStateKey: referenceFeedStateKey({ ...reference, curationStatus: nextStatus }),
|
|
@@ -810,7 +816,7 @@ async function requestStoryStarsProjection(itemId: string) {
|
|
|
810
816
|
new InvokeCommand({
|
|
811
817
|
FunctionName: functionName,
|
|
812
818
|
InvocationType: "Event",
|
|
813
|
-
Payload: new TextEncoder().encode(JSON.stringify({ projectionTask: { task: STORY_STARS_PROJECTION_TASK, itemId } })),
|
|
819
|
+
Payload: new TextEncoder().encode(JSON.stringify({ projectionTask: { task: STORY_STARS_PROJECTION_TASK, itemId, ...(currentTenantContext().tenantId ? { tenantId: currentTenantContext().tenantId } : {}) } })),
|
|
814
820
|
}),
|
|
815
821
|
);
|
|
816
822
|
} catch (error) {
|
|
@@ -903,7 +909,7 @@ async function setReferenceQualityRating(event: Parameters<ReferenceQualityHandl
|
|
|
903
909
|
curationStatusUpdatedAt: now,
|
|
904
910
|
curationStatusUpdatedBy: actor,
|
|
905
911
|
curationStatusReason: note,
|
|
906
|
-
newsroomFeedKey: reference.newsroomFeedKey ?? globalKey(REFERENCE_FEED_KEY),
|
|
912
|
+
newsroomFeedKey: reference.newsroomFeedKey ?? globalKey(REFERENCE_FEED_KEY, currentTenantContext().tenantId),
|
|
907
913
|
reviewedFeedKey: reviewedFeedKeyForStatus(nextStatus),
|
|
908
914
|
// A vote moves the Reference between the unrated and rated feeds; its original prediction and arrival stay as they were.
|
|
909
915
|
feedStateKey: referenceFeedStateKey({ ...reference, curationStatus: nextStatus }),
|
|
@@ -1234,7 +1240,7 @@ async function createReferenceNote(event: Parameters<ReferenceNoteHandler>[0]) {
|
|
|
1234
1240
|
importedAt: now,
|
|
1235
1241
|
createdAt: now,
|
|
1236
1242
|
updatedAt: now,
|
|
1237
|
-
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY),
|
|
1243
|
+
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY, currentTenantContext().tenantId),
|
|
1238
1244
|
metadata: JSON.stringify({
|
|
1239
1245
|
kind: "reference.note",
|
|
1240
1246
|
summary,
|
|
@@ -1378,7 +1384,7 @@ async function moveReferenceCorpus(event: Parameters<MoveReferenceCorpusHandler>
|
|
|
1378
1384
|
curationShareable: typeof current.curationShareable === "boolean" ? current.curationShareable : null,
|
|
1379
1385
|
curationDelegation: current.curationDelegation ?? null,
|
|
1380
1386
|
curationDecisionRelationId: normalizeOptionalString(current.curationDecisionRelationId),
|
|
1381
|
-
newsroomFeedKey: normalizeOptionalString(current.newsroomFeedKey) ?? globalKey(REFERENCE_FEED_KEY),
|
|
1387
|
+
newsroomFeedKey: normalizeOptionalString(current.newsroomFeedKey) ?? globalKey(REFERENCE_FEED_KEY, currentTenantContext().tenantId),
|
|
1382
1388
|
reviewedFeedKey: normalizeOptionalString(current.reviewedFeedKey) ?? reviewedFeedKeyForStatus(curationStatus),
|
|
1383
1389
|
predictedAcceptProbability: typeof current.predictedAcceptProbability === "number" ? current.predictedAcceptProbability : null,
|
|
1384
1390
|
predictionDecidedAt: normalizeOptionalString(current.predictionDecidedAt),
|
|
@@ -1529,7 +1535,7 @@ async function startReferenceCuration(event: Parameters<StartReferenceCurationHa
|
|
|
1529
1535
|
importedAt: now,
|
|
1530
1536
|
createdAt: now,
|
|
1531
1537
|
updatedAt: now,
|
|
1532
|
-
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY),
|
|
1538
|
+
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY, currentTenantContext().tenantId),
|
|
1533
1539
|
metadata: JSON.stringify({
|
|
1534
1540
|
kind: "reference.curation.assignment",
|
|
1535
1541
|
runId,
|
|
@@ -2474,7 +2480,7 @@ function buildAuthoritativeLabelRelation({
|
|
|
2474
2480
|
importedAt: now,
|
|
2475
2481
|
createdAt: now,
|
|
2476
2482
|
updatedAt: now,
|
|
2477
|
-
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY),
|
|
2483
|
+
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY, currentTenantContext().tenantId),
|
|
2478
2484
|
metadata: JSON.stringify({
|
|
2479
2485
|
kind: sourceMode === "accepted_prediction"
|
|
2480
2486
|
? "classification.authoritative_label.accepted_from_prediction"
|
|
@@ -2540,7 +2546,7 @@ function buildReferenceQualityRelation({
|
|
|
2540
2546
|
importedAt: now,
|
|
2541
2547
|
createdAt: now,
|
|
2542
2548
|
updatedAt: now,
|
|
2543
|
-
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY),
|
|
2549
|
+
newsroomFeedKey: globalKey(SEMANTIC_RELATION_FEED_KEY, currentTenantContext().tenantId),
|
|
2544
2550
|
metadata: JSON.stringify({
|
|
2545
2551
|
kind: "reference.quality-rating.manual",
|
|
2546
2552
|
actor,
|
|
@@ -2557,7 +2563,7 @@ async function updateNewsroomSummaryForSemanticRelationDelta(
|
|
|
2557
2563
|
amount: number,
|
|
2558
2564
|
now: string,
|
|
2559
2565
|
): Promise<void> {
|
|
2560
|
-
const response = await client.models.KnowledgeRawPayload.get({ id:
|
|
2566
|
+
const response = await client.models.KnowledgeRawPayload.get({ id: newsroomSummaryPayloadId(currentTenantContext()) });
|
|
2561
2567
|
assertNoDataErrors(response.errors, "get Newsroom summary snapshot");
|
|
2562
2568
|
const payload = normalizeSummaryPayload(await readNewsroomSummaryPayload(client), now);
|
|
2563
2569
|
payload.generatedAt = now;
|
|
@@ -2579,7 +2585,7 @@ async function getDataClient(): Promise<DataClient> {
|
|
|
2579
2585
|
return generateClient<Schema>();
|
|
2580
2586
|
})();
|
|
2581
2587
|
}
|
|
2582
|
-
return clientPromise;
|
|
2588
|
+
return tenantScopedClient(await clientPromise, currentTenantContext());
|
|
2583
2589
|
}
|
|
2584
2590
|
|
|
2585
2591
|
async function getRequiredRecord(
|
|
@@ -2623,7 +2629,7 @@ function normalizeReferenceCurationAction(value: unknown): "accept" | "reject" |
|
|
|
2623
2629
|
}
|
|
2624
2630
|
|
|
2625
2631
|
function reviewedFeedKeyForStatus(status: string): string | null {
|
|
2626
|
-
return status === "pending" ? null : globalKey(REFERENCE_REVIEWED_FEED_KEY);
|
|
2632
|
+
return status === "pending" ? null : globalKey(REFERENCE_REVIEWED_FEED_KEY, currentTenantContext().tenantId);
|
|
2627
2633
|
}
|
|
2628
2634
|
|
|
2629
2635
|
function referenceCurationStatusForAction(action: "accept" | "reject" | "reopen" | "archive"): "accepted" | "rejected" | "pending" | "archived" {
|
|
@@ -2702,7 +2708,7 @@ async function updateNewsroomSummaryForReferenceCuration(
|
|
|
2702
2708
|
client: DataClient,
|
|
2703
2709
|
input: { corpusId: string | null; previousStatus: string; nextStatus: string; now: string },
|
|
2704
2710
|
): Promise<void> {
|
|
2705
|
-
const response = await client.models.KnowledgeRawPayload.get({ id:
|
|
2711
|
+
const response = await client.models.KnowledgeRawPayload.get({ id: newsroomSummaryPayloadId(currentTenantContext()) });
|
|
2706
2712
|
assertNoDataErrors(response.errors, "get Newsroom summary snapshot");
|
|
2707
2713
|
const payload = normalizeSummaryPayload(await readNewsroomSummaryPayload(client), input.now);
|
|
2708
2714
|
payload.generatedAt = input.now;
|
|
@@ -2726,7 +2732,7 @@ async function updateNewsroomSummaryForReferenceStatus(
|
|
|
2726
2732
|
client: DataClient,
|
|
2727
2733
|
input: { corpusId: string | null; previousStatus: string; nextStatus: string; now: string },
|
|
2728
2734
|
): Promise<void> {
|
|
2729
|
-
const response = await client.models.KnowledgeRawPayload.get({ id:
|
|
2735
|
+
const response = await client.models.KnowledgeRawPayload.get({ id: newsroomSummaryPayloadId(currentTenantContext()) });
|
|
2730
2736
|
assertNoDataErrors(response.errors, "get Newsroom summary snapshot");
|
|
2731
2737
|
const payload = normalizeSummaryPayload(await readNewsroomSummaryPayload(client), input.now);
|
|
2732
2738
|
payload.generatedAt = input.now;
|
|
@@ -2854,7 +2860,7 @@ async function upsertNewsroomSummaryPayload(
|
|
|
2854
2860
|
now: string,
|
|
2855
2861
|
): Promise<void> {
|
|
2856
2862
|
const input = {
|
|
2857
|
-
id:
|
|
2863
|
+
id: newsroomSummaryPayloadId(currentTenantContext()),
|
|
2858
2864
|
ownerType: "newsroom",
|
|
2859
2865
|
ownerId: "newsroom",
|
|
2860
2866
|
payloadKind: "summary-snapshot",
|
|
@@ -2869,7 +2875,7 @@ async function upsertNewsroomSummaryPayload(
|
|
|
2869
2875
|
}
|
|
2870
2876
|
await putJsonModelPayload(
|
|
2871
2877
|
client as any,
|
|
2872
|
-
{ ownerKind: NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND, ownerId:
|
|
2878
|
+
{ ownerKind: NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND, ownerId: newsroomSummaryPayloadId(currentTenantContext()), importRunId: input.importRunId },
|
|
2873
2879
|
"raw_payload",
|
|
2874
2880
|
"summary-snapshot",
|
|
2875
2881
|
payload,
|
|
@@ -2881,7 +2887,7 @@ async function readNewsroomSummaryPayload(client: DataClient): Promise<Record<st
|
|
|
2881
2887
|
return readJsonModelPayload(
|
|
2882
2888
|
client as any,
|
|
2883
2889
|
NEWSROOM_SUMMARY_PAYLOAD_OWNER_KIND,
|
|
2884
|
-
|
|
2890
|
+
newsroomSummaryPayloadId(currentTenantContext()),
|
|
2885
2891
|
"raw_payload",
|
|
2886
2892
|
"summary-snapshot",
|
|
2887
2893
|
);
|
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { hashtagsInMessageText } from "../../../lib/message-hashtags.js";
|
|
3
3
|
import { conceptKeysForHashtag } from "../../../lib/wiki.js";
|
|
4
4
|
import { REFERENCE_LINK_FEED_KEY, globalKey } from "../../../lib/tenant-knowledge-keys.js";
|
|
5
|
+
import { currentTenantContext } from "../shared/tenant-context.js";
|
|
5
6
|
export const MESSAGE_CONCEPT_EDGE_KIND = "message.concept";
|
|
6
7
|
export const MESSAGE_CONCEPT_FEED_KEY = REFERENCE_LINK_FEED_KEY;
|
|
7
8
|
function parseMetadata(value) {
|
|
@@ -78,7 +79,7 @@ export async function linkMessageHashtags(store, input) {
|
|
|
78
79
|
reviewRecommended: false,
|
|
79
80
|
importedAt: input.now,
|
|
80
81
|
updatedAt: input.now,
|
|
81
|
-
newsroomFeedKey: globalKey(MESSAGE_CONCEPT_FEED_KEY),
|
|
82
|
+
newsroomFeedKey: globalKey(MESSAGE_CONCEPT_FEED_KEY, currentTenantContext().tenantId),
|
|
82
83
|
metadata: JSON.stringify(metadata),
|
|
83
84
|
}, existing !== null);
|
|
84
85
|
linkedNodeKeys.push(node.nodeKey);
|