@comet/site-react 8.32.0 → 8.32.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.
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { PreviewData } from '../graphQLFetch/graphQLFetch';
|
|
2
|
+
export declare function persistedQueryRoute(req: Request, { graphqlTarget, headers: headersInit, persistedQueriesPath, cacheMaxAge, previewData, }: {
|
|
2
3
|
graphqlTarget: string;
|
|
3
4
|
headers?: HeadersInit;
|
|
4
5
|
persistedQueriesPath: string;
|
|
5
6
|
cacheMaxAge: number | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Must be obtained from a verified source (e.g. the signed site preview cookie), never from the incoming request.
|
|
9
|
+
*/
|
|
10
|
+
previewData?: PreviewData;
|
|
6
11
|
}): Promise<Response>;
|
|
7
12
|
//# sourceMappingURL=persistedQueryRoute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistedQueryRoute.d.ts","sourceRoot":"","sources":["../../src/persistedQueries/persistedQueryRoute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"persistedQueryRoute.d.ts","sourceRoot":"","sources":["../../src/persistedQueries/persistedQueryRoute.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AA8C7F,wBAAsB,mBAAmB,CACrC,GAAG,EAAE,OAAO,EACZ,EACI,aAAa,EACb,OAAO,EAAE,WAAW,EACpB,oBAAgD,EAChD,WAAW,EACX,WAAW,GACd,EAAE;IACC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B,qBAmEJ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile } from "fs/promises";
|
|
2
|
+
import { convertPreviewDataToHeaders } from "../graphQLFetch/graphQLFetch.js";
|
|
2
3
|
let queryMap;
|
|
3
4
|
let fragmentsMap;
|
|
4
5
|
async function loadPersistedQueries(path) {
|
|
@@ -38,7 +39,8 @@ async function persistedQueryRoute(req, {
|
|
|
38
39
|
graphqlTarget,
|
|
39
40
|
headers: headersInit,
|
|
40
41
|
persistedQueriesPath = ".persisted-queries.json",
|
|
41
|
-
cacheMaxAge
|
|
42
|
+
cacheMaxAge,
|
|
43
|
+
previewData
|
|
42
44
|
}) {
|
|
43
45
|
var _a, _b;
|
|
44
46
|
if (!queryMap) {
|
|
@@ -74,11 +76,8 @@ async function persistedQueryRoute(req, {
|
|
|
74
76
|
}
|
|
75
77
|
const headers = new Headers(headersInit);
|
|
76
78
|
headers.set("Content-Type", "application/json");
|
|
77
|
-
for (const
|
|
78
|
-
|
|
79
|
-
if (value !== null) {
|
|
80
|
-
headers.set(header, value);
|
|
81
|
-
}
|
|
79
|
+
for (const [name, value] of Object.entries(convertPreviewDataToHeaders(previewData))) {
|
|
80
|
+
headers.set(name, value);
|
|
82
81
|
}
|
|
83
82
|
const upstreamRes = await fetch(graphqlTarget, {
|
|
84
83
|
method: "POST",
|
|
@@ -88,7 +87,9 @@ async function persistedQueryRoute(req, {
|
|
|
88
87
|
const responseHeaders = {
|
|
89
88
|
"Content-Type": "application/json"
|
|
90
89
|
};
|
|
91
|
-
if (
|
|
90
|
+
if (previewData) {
|
|
91
|
+
responseHeaders["Cache-Control"] = "private, no-store";
|
|
92
|
+
} else if (req.method === "GET" && upstreamRes.ok && cacheMaxAge !== void 0) {
|
|
92
93
|
responseHeaders["Cache-Control"] = `public, max-age=${cacheMaxAge}`;
|
|
93
94
|
}
|
|
94
95
|
return new Response(upstreamRes.body, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/site-react",
|
|
3
|
-
"version": "8.32.
|
|
3
|
+
"version": "8.32.2",
|
|
4
4
|
"description": "Comet Site React package",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"vite-plugin-dts": "^4.5.4",
|
|
53
53
|
"vitest": "^4.0.16",
|
|
54
54
|
"webpack": "^5.102.1",
|
|
55
|
-
"@comet/cli": "8.32.
|
|
56
|
-
"@comet/eslint-config": "8.32.
|
|
55
|
+
"@comet/cli": "8.32.2",
|
|
56
|
+
"@comet/eslint-config": "8.32.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": "^18.0.0"
|