@anthusai/papyrus 1.0.0-next.7 → 1.0.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.
@@ -130,7 +130,7 @@ def request_staging_build_action() -> dict:
130
130
 
131
131
 
132
132
  def handler(event, context):
133
- field = event["info"]["fieldName"]
133
+ field = event["fieldName"]
134
134
  arguments = parse_input(event["arguments"]["input"])
135
135
  actor = actor_from_event(event)
136
136
  try:
@@ -3,12 +3,22 @@ import { getContentSource, type ContentSource } from "./site-env";
3
3
 
4
4
  export type ContentSourceContext = {
5
5
  source: ContentSource;
6
+ /** Request-scoped data client (drafts mode: carries the visitor's session cookies). */
7
+ client?: unknown;
6
8
  };
7
9
 
8
10
  const contentSourceStorage = new AsyncLocalStorage<ContentSourceContext>();
9
11
 
10
- export function runWithContentSource<T>(source: ContentSource, operation: () => Promise<T>): Promise<T> {
11
- return contentSourceStorage.run({ source }, operation);
12
+ export function runWithContentSource<T>(
13
+ source: ContentSource,
14
+ operation: () => Promise<T>,
15
+ client?: unknown,
16
+ ): Promise<T> {
17
+ return contentSourceStorage.run({ source, client }, operation);
18
+ }
19
+
20
+ export function currentRequestClient<T>(): T | undefined {
21
+ return contentSourceStorage.getStore()?.client as T | undefined;
12
22
  }
13
23
 
14
24
  export function currentContentSource(): ContentSource {
@@ -1,3 +1,4 @@
1
+ import { generateServerClientUsingCookies } from "@aws-amplify/adapter-nextjs/api";
1
2
  import { generateClient } from "aws-amplify/data";
2
3
  import type { Schema } from "../amplify/data/resource";
3
4
  import type { Article, ArticleImage, ArticleImageAsset, ArticleImageLayout, ArticleImageThemeVariants, ArticleVideoAsset, ArticleVideoThemeVariants } from "./articles";
@@ -17,7 +18,7 @@ import {
17
18
  } from "./publication-items";
18
19
  import { BodyIrError, matchBodyImages, projectBodyIr, type BodyProjection, type BodyProjectionImage } from "./markus-body";
19
20
  import { SITE_BRAND } from "./site-brand";
20
- import { currentContentSource, runWithContentSource } from "./content-source-context";
21
+ import { currentContentSource, currentRequestClient, runWithContentSource } from "./content-source-context";
21
22
  import { getContentSource } from "./site-env";
22
23
 
23
24
  const DEFAULT_EDITION_SLUG = "current";
@@ -143,12 +144,18 @@ function isVisibleItemStatus(status: string): boolean {
143
144
  }
144
145
 
145
146
  async function withReaderGraphQLContext<T>(operation: () => Promise<T>): Promise<T> {
146
- const { runWithAmplifyServerContext } = getAmplifyServerRuntime();
147
+ const { runWithAmplifyServerContext, config } = getAmplifyServerRuntime();
147
148
  const source = getContentSource();
148
- const nextServerContext = source === "drafts" ? { cookies: (await import("next/headers")).cookies } : null;
149
+ if (source === "drafts") {
150
+ // Drafts are read as the signed-in visitor: the client reads the session from the request cookies, and it is
151
+ // kept in the request's async context (never a module global) so one visitor's session cannot serve another.
152
+ const { cookies } = await import("next/headers");
153
+ const client = generateServerClientUsingCookies<Schema>({ config, cookies, authMode: "userPool" });
154
+ return runWithContentSource(source, operation, client);
155
+ }
149
156
  return runWithContentSource(source, () =>
150
157
  runWithAmplifyServerContext({
151
- nextServerContext,
158
+ nextServerContext: null,
152
159
  operation: async () => {
153
160
  readerContextClient = generateClient<Schema>({ authMode: authMode() });
154
161
  try {
@@ -241,6 +248,8 @@ export const graphqlContentRepository: ContentRepository = {
241
248
  };
242
249
 
243
250
  function getClient(): DataClient {
251
+ const requestClient = currentRequestClient<DataClient>();
252
+ if (requestClient) return requestClient;
244
253
  if (readerContextClient) return readerContextClient;
245
254
 
246
255
  if (!buildTimeClient) {
package/package.json CHANGED
@@ -276,7 +276,7 @@
276
276
  "optional": true
277
277
  }
278
278
  },
279
- "version": "1.0.0-next.7",
279
+ "version": "1.0.0-next.8",
280
280
  "dependencies": {
281
281
  "@aws-amplify/adapter-nextjs": "^1.7.3",
282
282
  "@aws-sdk/client-cognito-identity-provider": "3.1045.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-next.7",
2
+ "version": "1.0.0-next.8",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",