@anthusai/papyrus 2.0.0-next.7 → 2.0.0-next.9

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.
@@ -2146,6 +2146,7 @@ const schema = a.schema({
2146
2146
  allow.groups(contentWriteGroups),
2147
2147
  ]),
2148
2148
  }).authorization((allow) => [
2149
+ allow.resource(assignmentAction).to(["query", "mutate"]),
2149
2150
  allow.resource(categoryAction),
2150
2151
  allow.resource(contentActions),
2151
2152
  allow.resource(manageUserRole),
@@ -2271,6 +2271,7 @@ const schema = a.schema({
2271
2271
  allow.groups(contentWriteGroups),
2272
2272
  ]),
2273
2273
  }).authorization((allow) => [
2274
+ allow.resource(assignmentAction).to(["query", "mutate"]),
2274
2275
  allow.resource(categoryAction),
2275
2276
  allow.resource(contentActions),
2276
2277
  allow.resource(manageUserRole),
@@ -1989,6 +1989,7 @@ const baseDefinitions = {
1989
1989
  ]),
1990
1990
  };
1991
1991
  export const schema = a.schema(baseDefinitions).authorization((allow) => [
1992
+ allow.resource(assignmentAction).to(["query", "mutate"]),
1992
1993
  allow.resource(categoryAction),
1993
1994
  allow.resource(contentActions),
1994
1995
  allow.resource(manageUserRole),
@@ -1999,6 +2000,7 @@ export const schema = a.schema(baseDefinitions).authorization((allow) => [
1999
2000
  /** The deployed schema of a site that enables plugins: the base definitions plus what each plugin contributes (docs/plugins.md). */
2000
2001
  export function schemaWithPlugins(pluginDefinitions) {
2001
2002
  return a.schema({ ...baseDefinitions, ...pluginDefinitions }).authorization((allow) => [
2003
+ allow.resource(assignmentAction).to(["query", "mutate"]),
2002
2004
  allow.resource(categoryAction),
2003
2005
  allow.resource(contentActions),
2004
2006
  allow.resource(manageUserRole),
@@ -2108,6 +2108,7 @@ const baseDefinitions = {
2108
2108
  };
2109
2109
 
2110
2110
  export const schema = a.schema(baseDefinitions).authorization((allow) => [
2111
+ allow.resource(assignmentAction).to(["query", "mutate"]),
2111
2112
  allow.resource(categoryAction),
2112
2113
  allow.resource(contentActions),
2113
2114
  allow.resource(manageUserRole),
@@ -2119,6 +2120,7 @@ export const schema = a.schema(baseDefinitions).authorization((allow) => [
2119
2120
  /** The deployed schema of a site that enables plugins: the base definitions plus what each plugin contributes (docs/plugins.md). */
2120
2121
  export function schemaWithPlugins(pluginDefinitions: Record<string, any>) {
2121
2122
  return a.schema({ ...baseDefinitions, ...pluginDefinitions } as typeof baseDefinitions).authorization((allow) => [
2123
+ allow.resource(assignmentAction).to(["query", "mutate"]),
2122
2124
  allow.resource(categoryAction),
2123
2125
  allow.resource(contentActions),
2124
2126
  allow.resource(manageUserRole),
@@ -0,0 +1,88 @@
1
+ import { Aspects, Stack } from "aws-cdk-lib";
2
+ import { CfnPolicy } from "aws-cdk-lib/aws-iam";
3
+ /** Lifecycle/context calls, including the fixed reference registration CLI's provenance operations. */
4
+ export const ASSIGNMENT_DATA_FIELDS = [
5
+ "Query/fields/getAssignment",
6
+ "Query/fields/getKnowledgeRawPayload",
7
+ "Query/fields/getProcedureRun",
8
+ "Query/fields/getProcedureVersion",
9
+ "Query/fields/getProcedureDefinition",
10
+ "Query/fields/getModelAttachment",
11
+ "Query/fields/getNewsroomSection",
12
+ "Query/fields/getKnowledgeCorpus",
13
+ "Query/fields/getKnowledgeImportRun",
14
+ "Query/fields/getReference",
15
+ "Query/fields/getReferenceAttachment",
16
+ "Query/fields/getMessage",
17
+ "Query/fields/getSemanticRelation",
18
+ "Query/fields/getSemanticNode",
19
+ "Query/fields/listReferences",
20
+ "Query/fields/listReferenceAttachments",
21
+ "Query/fields/listSemanticRelations",
22
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
23
+ "Query/fields/listItemsByLineageAndVersion",
24
+ "Query/fields/itemBySlug",
25
+ "Query/fields/itemByTenantSlug",
26
+ "Query/fields/listModelAttachmentsByOwnerRoleAndSortKey",
27
+ "Query/fields/listAssignmentsByQueueStatusAndPriority",
28
+ "Query/fields/listSemanticRelationsByObjectState",
29
+ "Query/fields/listSemanticRelationsBySubjectState",
30
+ "Query/fields/listAssignmentEventsByAssignmentAndCreatedAt",
31
+ "Mutation/fields/createAssignment",
32
+ "Mutation/fields/updateAssignment",
33
+ "Mutation/fields/createAssignmentEvent",
34
+ "Mutation/fields/createProcedureRun",
35
+ "Mutation/fields/updateProcedureRun",
36
+ "Mutation/fields/createKnowledgeCorpus",
37
+ "Mutation/fields/updateKnowledgeCorpus",
38
+ "Mutation/fields/createKnowledgeImportRun",
39
+ "Mutation/fields/updateKnowledgeImportRun",
40
+ "Mutation/fields/createKnowledgeRawPayload",
41
+ "Mutation/fields/updateKnowledgeRawPayload",
42
+ "Mutation/fields/createReference",
43
+ "Mutation/fields/updateReference",
44
+ "Mutation/fields/createReferenceAttachment",
45
+ "Mutation/fields/updateReferenceAttachment",
46
+ "Mutation/fields/createMessage",
47
+ "Mutation/fields/updateMessage",
48
+ "Mutation/fields/createSemanticRelation",
49
+ "Mutation/fields/updateSemanticRelation",
50
+ "Mutation/fields/createSemanticNode",
51
+ "Mutation/fields/updateSemanticNode",
52
+ "Mutation/fields/createModelAttachment",
53
+ "Mutation/fields/updateModelAttachment",
54
+ "Mutation/fields/createModelAttachmentUpload",
55
+ "Mutation/fields/completeModelAttachmentUpload",
56
+ "Mutation/fields/createModelAttachmentDownload",
57
+ "Mutation/fields/updateNewsroomSummary",
58
+ ];
59
+ /** Keep the SDK's generated configuration, replacing only this role's GraphQL grants at synthesis. */
60
+ export function scopeAssignmentDataAccess(lambda, graphqlApiArn) {
61
+ if (!lambda.role)
62
+ throw new Error("Assignment function needs an execution role.");
63
+ const roleName = lambda.role.roleName;
64
+ const resources = ASSIGNMENT_DATA_FIELDS.map((field) => `${graphqlApiArn}/types/${field}`);
65
+ Aspects.of(Stack.of(lambda)).add({
66
+ visit(node) {
67
+ if (!(node instanceof CfnPolicy))
68
+ return;
69
+ const stack = Stack.of(node);
70
+ const roles = stack.resolve(node.roles);
71
+ if (!roles?.some((role) => JSON.stringify(role) === JSON.stringify(stack.resolve(roleName))))
72
+ return;
73
+ const document = stack.resolve(node.policyDocument);
74
+ document.Statement.forEach((statement, index) => {
75
+ const actions = Array.isArray(statement.Action) ? statement.Action : [statement.Action];
76
+ if (actions.includes("*") || actions.includes("appsync:*")) {
77
+ throw new Error("Unexpected wildcard assignment action; review permissions before synthesis.");
78
+ }
79
+ if (!actions.includes("appsync:GraphQL"))
80
+ return;
81
+ if (statement.Effect !== "Allow" || actions.length !== 1 || statement.NotResource) {
82
+ throw new Error("Unexpected assignment GraphQL policy; review field scoping before synthesis.");
83
+ }
84
+ node.addPropertyOverride(`PolicyDocument.Statement.${index}.Resource`, resources);
85
+ });
86
+ },
87
+ });
88
+ }
@@ -0,0 +1,87 @@
1
+ import { Aspects, Stack } from "aws-cdk-lib";
2
+ import { CfnPolicy } from "aws-cdk-lib/aws-iam";
3
+ import type { IFunction } from "aws-cdk-lib/aws-lambda";
4
+
5
+ /** Lifecycle/context calls, including the fixed reference registration CLI's provenance operations. */
6
+ export const ASSIGNMENT_DATA_FIELDS = [
7
+ "Query/fields/getAssignment",
8
+ "Query/fields/getKnowledgeRawPayload",
9
+ "Query/fields/getProcedureRun",
10
+ "Query/fields/getProcedureVersion",
11
+ "Query/fields/getProcedureDefinition",
12
+ "Query/fields/getModelAttachment",
13
+ "Query/fields/getNewsroomSection",
14
+ "Query/fields/getKnowledgeCorpus",
15
+ "Query/fields/getKnowledgeImportRun",
16
+ "Query/fields/getReference",
17
+ "Query/fields/getReferenceAttachment",
18
+ "Query/fields/getMessage",
19
+ "Query/fields/getSemanticRelation",
20
+ "Query/fields/getSemanticNode",
21
+ "Query/fields/listReferences",
22
+ "Query/fields/listReferenceAttachments",
23
+ "Query/fields/listSemanticRelations",
24
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
25
+ "Query/fields/listItemsByLineageAndVersion",
26
+ "Query/fields/itemBySlug",
27
+ "Query/fields/itemByTenantSlug",
28
+ "Query/fields/listModelAttachmentsByOwnerRoleAndSortKey",
29
+ "Query/fields/listAssignmentsByQueueStatusAndPriority",
30
+ "Query/fields/listSemanticRelationsByObjectState",
31
+ "Query/fields/listSemanticRelationsBySubjectState",
32
+ "Query/fields/listAssignmentEventsByAssignmentAndCreatedAt",
33
+ "Mutation/fields/createAssignment",
34
+ "Mutation/fields/updateAssignment",
35
+ "Mutation/fields/createAssignmentEvent",
36
+ "Mutation/fields/createProcedureRun",
37
+ "Mutation/fields/updateProcedureRun",
38
+ "Mutation/fields/createKnowledgeCorpus",
39
+ "Mutation/fields/updateKnowledgeCorpus",
40
+ "Mutation/fields/createKnowledgeImportRun",
41
+ "Mutation/fields/updateKnowledgeImportRun",
42
+ "Mutation/fields/createKnowledgeRawPayload",
43
+ "Mutation/fields/updateKnowledgeRawPayload",
44
+ "Mutation/fields/createReference",
45
+ "Mutation/fields/updateReference",
46
+ "Mutation/fields/createReferenceAttachment",
47
+ "Mutation/fields/updateReferenceAttachment",
48
+ "Mutation/fields/createMessage",
49
+ "Mutation/fields/updateMessage",
50
+ "Mutation/fields/createSemanticRelation",
51
+ "Mutation/fields/updateSemanticRelation",
52
+ "Mutation/fields/createSemanticNode",
53
+ "Mutation/fields/updateSemanticNode",
54
+ "Mutation/fields/createModelAttachment",
55
+ "Mutation/fields/updateModelAttachment",
56
+ "Mutation/fields/createModelAttachmentUpload",
57
+ "Mutation/fields/completeModelAttachmentUpload",
58
+ "Mutation/fields/createModelAttachmentDownload",
59
+ "Mutation/fields/updateNewsroomSummary",
60
+ ] as const;
61
+
62
+ /** Keep the SDK's generated configuration, replacing only this role's GraphQL grants at synthesis. */
63
+ export function scopeAssignmentDataAccess(lambda: IFunction, graphqlApiArn: string): void {
64
+ if (!lambda.role) throw new Error("Assignment function needs an execution role.");
65
+ const roleName = lambda.role.roleName;
66
+ const resources = ASSIGNMENT_DATA_FIELDS.map((field) => `${graphqlApiArn}/types/${field}`);
67
+ Aspects.of(Stack.of(lambda)).add({
68
+ visit(node) {
69
+ if (!(node instanceof CfnPolicy)) return;
70
+ const stack = Stack.of(node);
71
+ const roles = stack.resolve(node.roles) as unknown[] | undefined;
72
+ if (!roles?.some((role) => JSON.stringify(role) === JSON.stringify(stack.resolve(roleName)))) return;
73
+ const document = stack.resolve(node.policyDocument) as { Statement: Array<Record<string, unknown>> };
74
+ document.Statement.forEach((statement, index) => {
75
+ const actions = Array.isArray(statement.Action) ? statement.Action : [statement.Action];
76
+ if (actions.includes("*") || actions.includes("appsync:*")) {
77
+ throw new Error("Unexpected wildcard assignment action; review permissions before synthesis.");
78
+ }
79
+ if (!actions.includes("appsync:GraphQL")) return;
80
+ if (statement.Effect !== "Allow" || actions.length !== 1 || statement.NotResource) {
81
+ throw new Error("Unexpected assignment GraphQL policy; review field scoping before synthesis.");
82
+ }
83
+ node.addPropertyOverride(`PolicyDocument.Statement.${index}.Resource`, resources);
84
+ });
85
+ },
86
+ });
87
+ }
@@ -7,6 +7,8 @@ export const EDITORIAL_CHECKS_QUERIES = ["checkEditorial", "suggestEditorialRewr
7
7
  export const EDITORIAL_CHECKS_MUTATIONS = ["importEditorialStarterPack", "recalibrateEditorialPolicies"];
8
8
  /** The model operations the function performs with its own role. */
9
9
  export const EDITORIAL_CHECKS_FUNCTION_FIELDS = [
10
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
11
+ "Query/fields/getEditorialContext",
10
12
  "Query/fields/listEditorialPolicies",
11
13
  "Query/fields/getEditorialCheckSettings",
12
14
  "Query/fields/listEditorialFeedbacks",
@@ -14,6 +14,8 @@ export const EDITORIAL_CHECKS_MUTATIONS = ["importEditorialStarterPack", "recali
14
14
 
15
15
  /** The model operations the function performs with its own role. */
16
16
  export const EDITORIAL_CHECKS_FUNCTION_FIELDS = [
17
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
18
+ "Query/fields/getEditorialContext",
17
19
  "Query/fields/listEditorialPolicies",
18
20
  "Query/fields/getEditorialCheckSettings",
19
21
  "Query/fields/listEditorialFeedbacks",
@@ -23,6 +23,7 @@ import { defineSiteData } from "./data/resource.js";
23
23
  import { resolvePlugins } from "./plugins/registry.js";
24
24
  import { wirePlugins } from "./plugins/wire.js";
25
25
  import { assignmentAction } from "./functions/assignment-action/resource.js";
26
+ import { scopeAssignmentDataAccess } from "./functions/assignment-action/data-access.js";
26
27
  import { categoryAction } from "./functions/category-action/resource.js";
27
28
  import { ConsoleChatResponderStack } from "./functions/console-chat-responder/resource.js";
28
29
  import { contentActions, setSiteFilesForContentActionsBundle } from "./functions/content-actions/resource.js";
@@ -304,6 +305,7 @@ export function defineSiteBackend(papyrusSite) {
304
305
  }
305
306
  grantCorporaRead(backend.knowledgeQuery.resources.lambda);
306
307
  grantNewsroomReadWrite(backend.assignmentAction.resources.lambda);
308
+ scopeAssignmentDataAccess(backend.assignmentAction.resources.lambda, backend.data.resources.graphqlApi.arn);
307
309
  grantNewsroomReadWrite(backend.categoryAction.resources.lambda);
308
310
  grantNewsroomReadWrite(backend.newsroomSummary.resources.lambda);
309
311
  const contentActionsLambda = backend.contentActions.resources.lambda;
@@ -30,6 +30,7 @@ import { defineSiteData } from "./data/resource";
30
30
  import { resolvePlugins } from "./plugins/registry";
31
31
  import { wirePlugins } from "./plugins/wire";
32
32
  import { assignmentAction } from "./functions/assignment-action/resource";
33
+ import { scopeAssignmentDataAccess } from "./functions/assignment-action/data-access";
33
34
  import { categoryAction } from "./functions/category-action/resource";
34
35
  import { ConsoleChatResponderStack } from "./functions/console-chat-responder/resource";
35
36
  import { contentActions, setSiteFilesForContentActionsBundle } from "./functions/content-actions/resource";
@@ -387,6 +388,10 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
387
388
  }
388
389
  grantCorporaRead(backend.knowledgeQuery.resources.lambda as LambdaFunction);
389
390
  grantNewsroomReadWrite(backend.assignmentAction.resources.lambda as LambdaFunction);
391
+ scopeAssignmentDataAccess(
392
+ backend.assignmentAction.resources.lambda as LambdaFunction,
393
+ backend.data.resources.graphqlApi.arn,
394
+ );
390
395
  grantNewsroomReadWrite(backend.categoryAction.resources.lambda as LambdaFunction);
391
396
  grantNewsroomReadWrite(backend.newsroomSummary.resources.lambda as LambdaFunction);
392
397
  const contentActionsLambda = backend.contentActions.resources.lambda as LambdaFunction;
package/package.json CHANGED
@@ -395,7 +395,7 @@
395
395
  "optional": true
396
396
  }
397
397
  },
398
- "version": "2.0.0-next.7",
398
+ "version": "2.0.0-next.9",
399
399
  "dependencies": {
400
400
  "@aws-amplify/adapter-nextjs": "^1.7.3",
401
401
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.0-next.7",
2
+ "version": "2.0.0-next.9",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",