@anthusai/papyrus 1.4.0-next.7 → 1.4.0-next.8

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.
@@ -298,6 +298,7 @@ const schema = a.schema({
298
298
  reasonCode: a.string(),
299
299
  decisionRelationId: a.id(),
300
300
  shareable: a.boolean(),
301
+ sectionId: a.id(),
301
302
  })
302
303
  .returns(a.ref("ReferenceCurationActionResult"))
303
304
  .authorization((allow) => [
@@ -346,6 +347,7 @@ const schema = a.schema({
346
347
  reasonCode: a.string(),
347
348
  decisionRelationId: a.id(),
348
349
  shareable: a.boolean(),
350
+ sectionId: a.id(),
349
351
  })
350
352
  .returns(a.ref("ReferenceCurationActionResult"))
351
353
  .authorization((allow) => [
@@ -324,6 +324,7 @@ const schema = a.schema({
324
324
  reasonCode: a.string(),
325
325
  decisionRelationId: a.id(),
326
326
  shareable: a.boolean(),
327
+ sectionId: a.id(),
327
328
  })
328
329
  .returns(a.ref("ReferenceCurationActionResult"))
329
330
  .authorization((allow) => [
@@ -376,6 +377,7 @@ const schema = a.schema({
376
377
  reasonCode: a.string(),
377
378
  decisionRelationId: a.id(),
378
379
  shareable: a.boolean(),
380
+ sectionId: a.id(),
379
381
  })
380
382
  .returns(a.ref("ReferenceCurationActionResult"))
381
383
  .authorization((allow) => [
@@ -256,6 +256,7 @@ const baseDefinitions = {
256
256
  reasonCode: a.string(),
257
257
  decisionRelationId: a.id(),
258
258
  shareable: a.boolean(),
259
+ sectionId: a.id(),
259
260
  })
260
261
  .returns(a.ref("ReferenceCurationActionResult"))
261
262
  .authorization((allow) => [
@@ -304,6 +305,7 @@ const baseDefinitions = {
304
305
  reasonCode: a.string(),
305
306
  decisionRelationId: a.id(),
306
307
  shareable: a.boolean(),
308
+ sectionId: a.id(),
307
309
  })
308
310
  .returns(a.ref("ReferenceCurationActionResult"))
309
311
  .authorization((allow) => [
@@ -280,6 +280,7 @@ const baseDefinitions = {
280
280
  reasonCode: a.string(),
281
281
  decisionRelationId: a.id(),
282
282
  shareable: a.boolean(),
283
+ sectionId: a.id(),
283
284
  })
284
285
  .returns(a.ref("ReferenceCurationActionResult"))
285
286
  .authorization((allow) => [
@@ -332,6 +333,7 @@ const baseDefinitions = {
332
333
  reasonCode: a.string(),
333
334
  decisionRelationId: a.id(),
334
335
  shareable: a.boolean(),
336
+ sectionId: a.id(),
335
337
  })
336
338
  .returns(a.ref("ReferenceCurationActionResult"))
337
339
  .authorization((allow) => [
@@ -4,7 +4,7 @@ import { Amplify } from "aws-amplify";
4
4
  import { generateClient } from "aws-amplify/data";
5
5
  import type { Schema } from "../../data/resource";
6
6
  import { putJsonModelPayload, putTextModelPayload, readJsonModelPayload } from "../shared/model-payloads";
7
- import { curationActorKind, referenceCurationMetadata } from "../shared/reference-curation-metadata";
7
+ import { curationActorKind, referenceCurationMetadata, validatedCurationSectionId } from "../shared/reference-curation-metadata";
8
8
  import {
9
9
  CURATION_DELEGATION_OWNER_TYPE,
10
10
  CURATION_DELEGATION_PAYLOAD_KIND,
@@ -193,6 +193,11 @@ async function reviewReferenceCuration(
193
193
  const nextStatus = referenceCurationStatusForAction(action);
194
194
  const reasonCode = normalizeReferenceRejectionReasonCode(event.arguments.reasonCode, action === "reject");
195
195
  const reference = await getRequiredRecord(client.models.Reference, referenceId, "Reference");
196
+ const requestedSectionId = normalizeOptionalString(event.arguments.sectionId);
197
+ const sectionRecord = requestedSectionId
198
+ ? (await client.models.NewsroomSection.get({ id: requestedSectionId })).data ?? null
199
+ : null;
200
+ const sectionId = validatedCurationSectionId(requestedSectionId, action, sectionRecord);
196
201
  const now = new Date().toISOString();
197
202
  const actorSub = normalizeOptionalString(event.arguments.actorSub) ?? getIdentitySub(event);
198
203
  const actorLabel = normalizeOptionalString(event.arguments.actorLabel) ?? getIdentityLabel(event);
@@ -259,6 +264,7 @@ async function reviewReferenceCuration(
259
264
  decisionRelationId: normalizeOptionalString(event.arguments.decisionRelationId),
260
265
  shareable: event.arguments.shareable ?? null,
261
266
  actorKind: delegation ? "human" : curationActorKind(event.identity),
267
+ sectionId,
262
268
  delegation,
263
269
  }),
264
270
  { filename: "metadata.json", now },
@@ -463,6 +469,7 @@ async function recordDelegatedCuration(event: Parameters<RecordDelegatedCuration
463
469
  reasonCode: event.arguments.reasonCode,
464
470
  decisionRelationId: event.arguments.decisionRelationId,
465
471
  shareable: event.arguments.shareable,
472
+ sectionId: event.arguments.sectionId,
466
473
  actorSub: delegation.grantorSub,
467
474
  actorLabel: delegation.grantorLabel,
468
475
  },
@@ -13,6 +13,7 @@ export type ReferenceCurationMetadataInput = {
13
13
  decisionRelationId?: string | null
14
14
  shareable?: boolean | null
15
15
  actorKind?: CurationActorKind | null
16
+ sectionId?: string | null
16
17
  delegation?: { delegationId: string; relayedBy: string; instruction: string } | null
17
18
  }
18
19
 
@@ -39,6 +40,7 @@ export function referenceCurationMetadata(input: ReferenceCurationMetadataInput)
39
40
  referenceId: input.referenceId,
40
41
  referenceLineageId: input.referenceLineageId,
41
42
  ...(input.actorKind ? {actorKind: input.actorKind} : {}),
43
+ ...(input.sectionId?.trim() ? {sectionId: input.sectionId.trim()} : {}),
42
44
  ...(input.delegation
43
45
  ? {attestation: "delegated", relayedBy: input.delegation.relayedBy, delegationId: input.delegation.delegationId,
44
46
  instruction: input.delegation.instruction}
@@ -47,3 +49,32 @@ export function referenceCurationMetadata(input: ReferenceCurationMetadataInput)
47
49
  ...(decisionRelationId ? {shareable: input.shareable === true} : {}),
48
50
  }
49
51
  }
52
+
53
+ export type CurationSectionCandidate = {
54
+ id?: string | null
55
+ enabled?: boolean | null
56
+ enabledStatus?: string | null
57
+ } | null | undefined
58
+
59
+ /**
60
+ * A curation may name the newsroom Section the Reference belongs in, but only
61
+ * when it accepts the Reference and the Section exists and is enabled.
62
+ */
63
+ export function validatedCurationSectionId(
64
+ requestedSectionId: string | null | undefined,
65
+ action: string,
66
+ section: CurationSectionCandidate,
67
+ ): string | null {
68
+ const sectionId = requestedSectionId?.trim() || null
69
+ if (!sectionId) return null
70
+ if (action !== "accept") {
71
+ throw new Error("A section can be recorded only when accepting a reference.")
72
+ }
73
+ if (!section || section.id !== sectionId) {
74
+ throw new Error(`Newsroom section ${sectionId} was not found.`)
75
+ }
76
+ if (section.enabled === false || section.enabledStatus === "disabled") {
77
+ throw new Error(`Newsroom section ${sectionId} is disabled.`)
78
+ }
79
+ return sectionId
80
+ }
package/package.json CHANGED
@@ -374,7 +374,7 @@
374
374
  "optional": true
375
375
  }
376
376
  },
377
- "version": "1.4.0-next.7",
377
+ "version": "1.4.0-next.8",
378
378
  "dependencies": {
379
379
  "@aws-amplify/adapter-nextjs": "^1.7.3",
380
380
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.0-next.7",
2
+ "version": "1.4.0-next.8",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",