@pantheon-systems/p1-next-sdk 0.12.0 → 0.14.0
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/bin/lib/transform.js +274 -1
- package/dist/P1NextRouterProvider.js +0 -4
- package/dist/P1NextRouterProvider.js.map +1 -1
- package/dist/auth-handler.d.ts.map +1 -1
- package/dist/auth-handler.js +4 -4
- package/dist/auth-handler.js.map +1 -1
- package/dist/create-published-page.d.ts +110 -0
- package/dist/create-published-page.d.ts.map +1 -0
- package/dist/create-published-page.js +86 -0
- package/dist/create-published-page.js.map +1 -0
- package/dist/editor-paths.js +0 -12
- package/dist/editor-paths.js.map +1 -1
- package/dist/handler-actions.js +0 -4
- package/dist/handler-actions.js.map +1 -1
- package/dist/handler.js +0 -16
- package/dist/handler.js.map +1 -1
- package/dist/middleware.js +0 -5
- package/dist/middleware.js.map +1 -1
- package/dist/pages-handler.js +0 -12
- package/dist/pages-handler.js.map +1 -1
- package/dist/published-page.d.ts +19 -6
- package/dist/published-page.d.ts.map +1 -1
- package/dist/published-page.js +15 -39
- package/dist/published-page.js.map +1 -1
- package/dist/routes/broker.d.ts +6 -0
- package/dist/routes/broker.d.ts.map +1 -1
- package/dist/routes/broker.js +25 -23
- package/dist/routes/broker.js.map +1 -1
- package/dist/routes/datasource-context.js +2 -2
- package/dist/routes/editor-context.js +4 -9
- package/dist/routes/editor-context.js.map +1 -1
- package/dist/routes/publish.js +0 -10
- package/dist/routes/publish.js.map +1 -1
- package/dist/routes/remote-datasources-api.d.ts +2 -2
- package/dist/server.d.ts +2 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -0
- package/dist/server.js.map +1 -1
- package/package.json +5 -4
package/bin/lib/transform.js
CHANGED
|
@@ -72,12 +72,285 @@ export function rewriteWrapperSignature(source) {
|
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* The editor's mid-switch waiting state moved into the SDK: `useP1Editor` now
|
|
77
|
+
* retains the last rendered props itself and reports *why* it is reloading, and
|
|
78
|
+
* `<EditorReloadOverlay>` owns the copy for each wait. The old inline version
|
|
79
|
+
* could not tell a workstream switch from a page switch, so it announced every
|
|
80
|
+
* reload as "Switching workstream".
|
|
81
|
+
*/
|
|
82
|
+
const OVERLAY_EDITS = [
|
|
83
|
+
[
|
|
84
|
+
` const [userRole, setUserRole] = useState<ContentRole>('editor');\n` +
|
|
85
|
+
` const lastGoodStateRef = React.useRef<{ puckKey: string; puckProps: any } | null>(null);\n`,
|
|
86
|
+
` const [userRole, setUserRole] = useState<ContentRole>('editor');\n`,
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
`<EditorContent path={path} lastGoodStateRef={lastGoodStateRef} />`,
|
|
90
|
+
`<EditorContent path={path} />`,
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
`function EditorContent({\n` +
|
|
94
|
+
` path,\n` +
|
|
95
|
+
` lastGoodStateRef,\n` +
|
|
96
|
+
`}: {\n` +
|
|
97
|
+
` path: string;\n` +
|
|
98
|
+
` lastGoodStateRef: React.MutableRefObject<{ puckKey: string; puckProps: any } | null>;\n` +
|
|
99
|
+
`}) {`,
|
|
100
|
+
`function EditorContent({ path }: { path: string }) {`,
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
` const { loading, error, puckKey, puckProps } = useP1Editor({`,
|
|
104
|
+
` const { loading, reloading, hasContent, error, puckKey, puckProps } = useP1Editor({`,
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
` P1QueryProvider,\n editorPathHref,\n} from "@pantheon-systems/puck-css";`,
|
|
108
|
+
` P1QueryProvider,\n editorPathHref,\n EditorReloadOverlay,\n} from "@pantheon-systems/puck-css";`,
|
|
109
|
+
],
|
|
110
|
+
[
|
|
111
|
+
` // Update last good state when loading completes successfully (ref passed from parent)
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
if (!loading && !error) {
|
|
114
|
+
lastGoodStateRef.current = { puckKey, puckProps };
|
|
115
|
+
}
|
|
116
|
+
}, [loading, error, puckKey, puckProps]);
|
|
117
|
+
|
|
118
|
+
if (redirecting) {
|
|
119
|
+
return <LoadingMessage message="Redirecting" data-testid="editor-redirecting" />;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Show full loading screen only on first load (no previous state)
|
|
123
|
+
if (loading && !lastGoodStateRef.current) {
|
|
124
|
+
return <LoadingMessage message="Loading document" data-testid="editor-loading" />;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Show error only if we have no previous state to fall back to
|
|
128
|
+
if (error && !lastGoodStateRef.current) {
|
|
129
|
+
return (
|
|
130
|
+
<div style={{ textAlign: "center", padding: "4rem", fontFamily: "system-ui" }}>
|
|
131
|
+
<h3>Error loading document</h3>
|
|
132
|
+
<p style={{ color: "#666" }}>{error.message}</p>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Use current state if loaded, otherwise keep showing last good state
|
|
138
|
+
const displayState = (!loading && !error)
|
|
139
|
+
? { puckKey, puckProps }
|
|
140
|
+
: lastGoodStateRef.current ?? { puckKey, puckProps };
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div className="puck-editor-theme" style={{ position: "relative" }}>
|
|
144
|
+
{/* Loading overlay - shown during branch switch */}
|
|
145
|
+
{loading && lastGoodStateRef.current && (
|
|
146
|
+
<div
|
|
147
|
+
style={{
|
|
148
|
+
position: "fixed",
|
|
149
|
+
top: "50%",
|
|
150
|
+
left: "50%",
|
|
151
|
+
transform: "translate(-50%, -50%)",
|
|
152
|
+
zIndex: 9999,
|
|
153
|
+
background: "rgba(255, 255, 255, 0.95)",
|
|
154
|
+
padding: "1rem 2rem",
|
|
155
|
+
borderRadius: "8px",
|
|
156
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
157
|
+
fontFamily: "system-ui",
|
|
158
|
+
fontSize: "14px",
|
|
159
|
+
color: "#333",
|
|
160
|
+
fontWeight: 500,
|
|
161
|
+
display: "flex",
|
|
162
|
+
alignItems: "center",
|
|
163
|
+
gap: "0.75rem",
|
|
164
|
+
}}
|
|
165
|
+
>
|
|
166
|
+
<div
|
|
167
|
+
style={{
|
|
168
|
+
width: "16px",
|
|
169
|
+
height: "16px",
|
|
170
|
+
border: "2px solid #e0e0e0",
|
|
171
|
+
borderTopColor: "#2563eb",
|
|
172
|
+
borderRadius: "50%",
|
|
173
|
+
animation: "spin 0.6s linear infinite",
|
|
174
|
+
}}
|
|
175
|
+
/>
|
|
176
|
+
Switching workstream...
|
|
177
|
+
<style>{\`
|
|
178
|
+
@keyframes spin {
|
|
179
|
+
to { transform: rotate(360deg); }
|
|
180
|
+
}
|
|
181
|
+
\`}</style>
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
<DatasourceRegistryProvider registry={editorCtx?.remoteDatasourceRegistry ?? []}>
|
|
185
|
+
<DatasourceDataProvider context={remoteDatasourceContext}>
|
|
186
|
+
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
|
187
|
+
<Puck key={\`\${displayState.puckKey}-\${chatbotEnabled ? "ai" : "no-ai"}\`} {...displayState.puckProps as any} _experimentalFullScreenCanvas={true} />
|
|
188
|
+
</DatasourceDataProvider>
|
|
189
|
+
</DatasourceRegistryProvider>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
`,
|
|
194
|
+
` if (redirecting) {
|
|
195
|
+
return <LoadingMessage message="Redirecting" data-testid="editor-redirecting" />;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (loading) {
|
|
199
|
+
return <LoadingMessage message="Loading document" data-testid="editor-loading" />;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// A failed load with a document already on screen keeps that document; only a
|
|
203
|
+
// failure with nothing to fall back on takes over the view.
|
|
204
|
+
if (error && !hasContent) {
|
|
205
|
+
return (
|
|
206
|
+
<div style={{ textAlign: "center", padding: "4rem", fontFamily: "system-ui" }}>
|
|
207
|
+
<h3>Error loading document</h3>
|
|
208
|
+
<p style={{ color: "#666" }}>{error.message}</p>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div className="puck-editor-theme" style={{ position: "relative" }}>
|
|
215
|
+
<EditorReloadOverlay reloading={reloading} />
|
|
216
|
+
<DatasourceRegistryProvider registry={editorCtx?.remoteDatasourceRegistry ?? []}>
|
|
217
|
+
<DatasourceDataProvider context={remoteDatasourceContext}>
|
|
218
|
+
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
|
219
|
+
<Puck key={\`\${puckKey}-\${chatbotEnabled ? "ai" : "no-ai"}\`} {...puckProps as any} _experimentalFullScreenCanvas={true} />
|
|
220
|
+
</DatasourceDataProvider>
|
|
221
|
+
</DatasourceRegistryProvider>
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
`,
|
|
226
|
+
],
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Swap the hand-rolled loading overlay for the SDK one. Every anchor has to
|
|
231
|
+
* match: an app already on the SDK overlay is left alone, and an app that
|
|
232
|
+
* edited part of this region keeps its own version rather than being left with
|
|
233
|
+
* a broken mix of the two.
|
|
234
|
+
*/
|
|
235
|
+
export function rewriteLoadingOverlay(source) {
|
|
236
|
+
const found = OVERLAY_EDITS.filter(([find]) => source.includes(find));
|
|
237
|
+
if (found.length === 0) return source;
|
|
238
|
+
if (found.length !== OVERLAY_EDITS.length) {
|
|
239
|
+
throw new BailError(
|
|
240
|
+
"editor-client.tsx has a partly-customized loading overlay; migrate this file by hand.",
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
let out = source;
|
|
244
|
+
for (const [find, replace] of OVERLAY_EDITS) out = out.replace(find, replace);
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The auto-create-on-404 behaviour is gone. It POSTed to `/p1/api/structure/page`,
|
|
250
|
+
* a route no SDK handler ever served, so opening an editor path for a page that
|
|
251
|
+
* did not exist silently did nothing. The editor now renders a page-not-found
|
|
252
|
+
* panel in the canvas — chrome and all — offering to create the page, and both
|
|
253
|
+
* halves of that live in the SDK so they version together. Every trace of the old
|
|
254
|
+
* client-side half comes out.
|
|
255
|
+
*
|
|
256
|
+
* Every anchor has to match: an app already on the SDK flow is left alone, and an
|
|
257
|
+
* app that edited part of this region keeps its own version rather than being left
|
|
258
|
+
* with a broken mix of the two.
|
|
259
|
+
*/
|
|
260
|
+
const NOT_FOUND_EDITS = [
|
|
261
|
+
[
|
|
262
|
+
`const DEFAULT_PAGE_DATA = {
|
|
263
|
+
root: { props: { title: "New page" } },
|
|
264
|
+
content: [],
|
|
265
|
+
zones: {},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const DEFAULT_ROOT_PAGE_DATA = {
|
|
269
|
+
root: { props: { title: "Welcome | P1 site" } },
|
|
270
|
+
content: [
|
|
271
|
+
{
|
|
272
|
+
type: "P1WelcomeBlock",
|
|
273
|
+
props: {
|
|
274
|
+
id: "seed-welcome",
|
|
275
|
+
heading: "Welcome to your new Pantheon P1 Site.",
|
|
276
|
+
description: "You just created this new site from Pantheon P1 starter kit, congrats! You'll need a Pantheon P1 user account to edit it and create new pages.",
|
|
277
|
+
ctaLabel: "Sign-in to P1",
|
|
278
|
+
ctaHref: "/p1",
|
|
279
|
+
footnote: "Visit [P1 documentation](https://docs.pantheon.io) for more information.",
|
|
280
|
+
loggedInHeading: "Welcome to your new Pantheon P1 Site.",
|
|
281
|
+
loggedInDescription: "You just created this new site from Pantheon P1 starter kit, congrats! Start editing this page or visit the P1 dashboard to manage your site.",
|
|
282
|
+
loggedInCtaLabel: "Edit this page with P1 Visual Editor",
|
|
283
|
+
loggedInCtaHref: "/p1",
|
|
284
|
+
loggedInSecondaryLabel: "Go to P1 Dashboard",
|
|
285
|
+
loggedInFootnote: "Visit [P1 documentation](https://docs.pantheon.io) for more information.",
|
|
286
|
+
showLogo: true,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
zones: {},
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
`,
|
|
294
|
+
``,
|
|
295
|
+
],
|
|
296
|
+
[
|
|
297
|
+
` const router = useRouter();
|
|
298
|
+
const { getToken } = useP1Auth();
|
|
299
|
+
`,
|
|
300
|
+
` const router = useRouter();
|
|
301
|
+
`,
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
` const handleDocumentNotFound = useCallback(
|
|
305
|
+
async (docPath: string, _error: Error) => {
|
|
306
|
+
const initialData = docPath === "/" ? DEFAULT_ROOT_PAGE_DATA : DEFAULT_PAGE_DATA;
|
|
307
|
+
const token = await getToken();
|
|
308
|
+
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
309
|
+
if (token) headers["Authorization"] = \`Bearer \${token}\`;
|
|
310
|
+
const res = await fetch("/p1/api/structure/page", {
|
|
311
|
+
method: "POST",
|
|
312
|
+
headers,
|
|
313
|
+
body: JSON.stringify({ path: docPath, initialData }),
|
|
314
|
+
});
|
|
315
|
+
return res.ok;
|
|
316
|
+
},
|
|
317
|
+
[getToken],
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
`,
|
|
321
|
+
``,
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
` additionalPlugins,
|
|
325
|
+
onDocumentNotFound: handleDocumentNotFound,
|
|
326
|
+
`,
|
|
327
|
+
` additionalPlugins,
|
|
328
|
+
`,
|
|
329
|
+
],
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
/** Strip the dead auto-create-on-404 call; the SDK owns the page-not-found flow now. */
|
|
333
|
+
export function rewriteDocumentNotFound(source) {
|
|
334
|
+
const found = NOT_FOUND_EDITS.filter(([find]) => source.includes(find));
|
|
335
|
+
if (found.length === 0) return source;
|
|
336
|
+
if (found.length !== NOT_FOUND_EDITS.length) {
|
|
337
|
+
throw new BailError(
|
|
338
|
+
"editor-client.tsx has a partly-customized page-not-found flow; migrate this file by hand.",
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
let out = source;
|
|
342
|
+
for (const [find, replace] of NOT_FOUND_EDITS) out = out.replace(find, replace);
|
|
343
|
+
return out;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Full editor-client transform: deepen imports, add the named imports, rewrite the signature, adopt the SDK overlay and page-not-found flow. */
|
|
76
347
|
export function rewriteEditorClient(source) {
|
|
77
348
|
let out = deepenRelativeImports(source);
|
|
78
349
|
out = addNamedImport(out, "next/navigation", "usePathname", "prepend");
|
|
79
350
|
out = addNamedImport(out, "@pantheon-systems/p1-next-sdk", "editorPagePathFromUrlPath", "append");
|
|
80
351
|
out = rewriteWrapperSignature(out);
|
|
352
|
+
out = rewriteLoadingOverlay(out);
|
|
353
|
+
out = rewriteDocumentNotFound(out);
|
|
81
354
|
return out;
|
|
82
355
|
}
|
|
83
356
|
|
|
@@ -8,9 +8,6 @@ export function P1NextRouterProvider({ children }) {
|
|
|
8
8
|
const pathname = usePathname();
|
|
9
9
|
const searchParams = useSearchParams();
|
|
10
10
|
const isInitialMount = useRef(true);
|
|
11
|
-
// Re-fetch server component data on back/forward navigation.
|
|
12
|
-
// Without this, Next.js restores the cached client shell but the
|
|
13
|
-
// server-rendered content inside it is empty.
|
|
14
11
|
useEffect(() => {
|
|
15
12
|
const handler = (event) => {
|
|
16
13
|
if (event.persisted) {
|
|
@@ -20,7 +17,6 @@ export function P1NextRouterProvider({ children }) {
|
|
|
20
17
|
window.addEventListener("pageshow", handler);
|
|
21
18
|
return () => window.removeEventListener("pageshow", handler);
|
|
22
19
|
}, [nextRouter]);
|
|
23
|
-
// Also handle popstate (Next.js client-side back navigation)
|
|
24
20
|
useEffect(() => {
|
|
25
21
|
if (isInitialMount.current) {
|
|
26
22
|
isInitialMount.current = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"P1NextRouterProvider.js","sourceRoot":"","sources":["../src/P1NextRouterProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,eAAe,EAAiB,MAAM,4BAA4B,CAAC;AAE5E,MAAM,UAAU,oBAAoB,CAAC,EAAE,QAAQ,EAA2B;IACxE,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"P1NextRouterProvider.js","sourceRoot":"","sources":["../src/P1NextRouterProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,eAAe,EAAiB,MAAM,4BAA4B,CAAC;AAE5E,MAAM,UAAU,oBAAoB,CAAC,EAAE,QAAQ,EAA2B;IACxE,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAKpC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,E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M,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB;oBAEhD,OAAO,cACJ;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE;
|
|
1
|
+
{"version":3,"file":"auth-handler.d.ts","sourceRoot":"","sources":["../src/auth-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB;oBAEhD,OAAO,cACJ;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE;EAuBzD"}
|
package/dist/auth-handler.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import { PRODUCTION_BASE_URL } from "@pantheon-systems/puck-css/server";
|
|
3
|
-
import { postBrokerLogin, postBrokerRedeem } from "./routes/broker";
|
|
3
|
+
import { postBrokerLogin, postBrokerLogout, postBrokerRedeem } from "./routes/broker";
|
|
4
4
|
export function createP1AuthHandler(opts) {
|
|
5
5
|
async function POST(request, { params }) {
|
|
6
6
|
const { action = [] } = await params;
|
|
7
7
|
const route = action[0];
|
|
8
|
-
// Same fallback as createNextConfig/createNextContentClient (PCC-3282):
|
|
9
|
-
// an unset p1BaseUrl (no CSS_BASE_URL / NEXT_PUBLIC_CSS_BASE_URL) should
|
|
10
|
-
// resolve to the production backend rather than failing broker login.
|
|
11
8
|
const p1BaseUrl = opts.p1BaseUrl ?? PRODUCTION_BASE_URL;
|
|
12
9
|
if (route === "login") {
|
|
13
10
|
return postBrokerLogin(request, opts.p1ApiKey, p1BaseUrl, opts.p1SiteUrl, opts.redirectUrl, opts.prompt);
|
|
@@ -15,6 +12,9 @@ export function createP1AuthHandler(opts) {
|
|
|
15
12
|
if (route === "redeem") {
|
|
16
13
|
return postBrokerRedeem(request, opts.p1ApiKey, p1BaseUrl);
|
|
17
14
|
}
|
|
15
|
+
if (route === "logout") {
|
|
16
|
+
return postBrokerLogout(request, p1BaseUrl);
|
|
17
|
+
}
|
|
18
18
|
return NextResponse.json({ error: "not_found" }, { status: 404 });
|
|
19
19
|
}
|
|
20
20
|
return { POST };
|
package/dist/auth-handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-handler.js","sourceRoot":"","sources":["../src/auth-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-handler.js","sourceRoot":"","sources":["../src/auth-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAUtF,MAAM,UAAU,mBAAmB,CAAC,IAAyB;IAC3D,KAAK,UAAU,IAAI,CACjB,OAAgB,EAChB,EAAE,MAAM,EAA8C;QAEtD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,MAAM,CAAC;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAIxB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,mBAAmB,CAAC;QAExD,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;YACtB,OAAO,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3G,CAAC;QACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvB,OAAO,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvB,OAAO,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route builders for the published-page render pipeline.
|
|
3
|
+
*
|
|
4
|
+
* The pipeline itself — read the page, branch on the outcome, resolve route
|
|
5
|
+
* templates and remote datasources, render — is the same for every P1 site, and
|
|
6
|
+
* carries the invariants documented in published-page.ts. Hand-assembling it in
|
|
7
|
+
* each app's route files froze a copy of it into every scaffold, so improvements
|
|
8
|
+
* to caching or datasource resolution could never reach a project once it was
|
|
9
|
+
* created. It lives here instead, and the routes become shims.
|
|
10
|
+
*
|
|
11
|
+
* What genuinely differs per app flows in as options: the render client (which
|
|
12
|
+
* holds that app's puck.config), the components shown when content is
|
|
13
|
+
* unavailable or the home page has no document yet, the app's datasource
|
|
14
|
+
* fetcher registry, and how it turns page data into <head> metadata.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* // app/published-pages.tsx (shared module — one instance, both routes)
|
|
18
|
+
* import { createPublishedPage } from "@pantheon-systems/p1-next-sdk/server";
|
|
19
|
+
* export const published = createPublishedPage({ ... });
|
|
20
|
+
*
|
|
21
|
+
* // app/[...puckPath]/page.tsx
|
|
22
|
+
* export const revalidate = 300;
|
|
23
|
+
* export default published.Page;
|
|
24
|
+
* export const generateMetadata = published.generateMetadata;
|
|
25
|
+
* export const generateStaticParams = published.generateStaticParams;
|
|
26
|
+
*
|
|
27
|
+
* // app/page.tsx
|
|
28
|
+
* export const revalidate = 300;
|
|
29
|
+
* export default published.HomePage;
|
|
30
|
+
* export const generateMetadata = published.generateHomeMetadata;
|
|
31
|
+
*
|
|
32
|
+
* `revalidate` must stay a literal in the route file. Next.js statically
|
|
33
|
+
* analyzes segment-config exports, so re-exporting one through the factory
|
|
34
|
+
* leaves it undetected and the route silently loses its revalidation window —
|
|
35
|
+
* the same constraint that keeps `dynamic` in the route file for createP1Pages.
|
|
36
|
+
*/
|
|
37
|
+
import type { Metadata } from "next";
|
|
38
|
+
import { type RemoteDatasourceFetcher } from "@pantheon-systems/puck-css/server";
|
|
39
|
+
import type { Data } from "@puckeditor/core";
|
|
40
|
+
/**
|
|
41
|
+
* Describes the rendered document to the render client, which uses it for the
|
|
42
|
+
* edit affordances that only make sense once a real document is on screen.
|
|
43
|
+
*/
|
|
44
|
+
export type PublishedPageMetadata = {
|
|
45
|
+
route: string;
|
|
46
|
+
documentName?: string;
|
|
47
|
+
pageType?: "page" | "template" | "override";
|
|
48
|
+
};
|
|
49
|
+
export type PublishedPageClientProps = {
|
|
50
|
+
data: Data;
|
|
51
|
+
pageMetadata: PublishedPageMetadata;
|
|
52
|
+
};
|
|
53
|
+
export type CreatePublishedPageConfig = {
|
|
54
|
+
/**
|
|
55
|
+
* Renders resolved Puck data. Holds the app's puck.config, which is why this
|
|
56
|
+
* cannot live in the SDK.
|
|
57
|
+
*/
|
|
58
|
+
Client: React.ComponentType<PublishedPageClientProps>;
|
|
59
|
+
/**
|
|
60
|
+
* Rendered instead of a 404 when the backend could not be reached. A
|
|
61
|
+
* published page must not 404 over a blip — that deindexes live content — so
|
|
62
|
+
* this is a 200 holding page on a render the SDK has already made uncacheable.
|
|
63
|
+
*/
|
|
64
|
+
Unavailable: React.ComponentType;
|
|
65
|
+
/**
|
|
66
|
+
* Rendered at "/" when no home document exists. Unlike the catch-all, "/"
|
|
67
|
+
* never 404s: it is a single fixed URL rather than an unbounded crawler
|
|
68
|
+
* surface, and a welcome state is the right answer for a freshly scaffolded
|
|
69
|
+
* site — including one with no backend configured yet.
|
|
70
|
+
*/
|
|
71
|
+
Fallback: React.ComponentType;
|
|
72
|
+
/** The app's remote-datasource fetcher registry. */
|
|
73
|
+
fetchers?: RemoteDatasourceFetcher[];
|
|
74
|
+
/**
|
|
75
|
+
* Turns published page data into <head> metadata. Called only for a page that
|
|
76
|
+
* actually resolved; the miss and outage titles come from `titles`.
|
|
77
|
+
*/
|
|
78
|
+
resolveMetadata?: (args: {
|
|
79
|
+
pageData: Data;
|
|
80
|
+
path: string;
|
|
81
|
+
}) => Metadata | Promise<Metadata>;
|
|
82
|
+
titles?: {
|
|
83
|
+
/** Catch-all, no such page. Default "Not Found". */
|
|
84
|
+
notFound?: string;
|
|
85
|
+
/** Backend unreachable. Default "Temporarily unavailable". */
|
|
86
|
+
unavailable?: string;
|
|
87
|
+
/** "/" with no home document yet — pairs with `Fallback`. Default "Home". */
|
|
88
|
+
home?: string;
|
|
89
|
+
};
|
|
90
|
+
/** Extra internal path prefixes to refuse, on top of the SDK's own list. */
|
|
91
|
+
internalPathPrefixes?: readonly string[];
|
|
92
|
+
};
|
|
93
|
+
export declare function createPublishedPage(config: CreatePublishedPageConfig): {
|
|
94
|
+
Page: ({ params, }: {
|
|
95
|
+
params: Promise<{
|
|
96
|
+
puckPath: string[];
|
|
97
|
+
}>;
|
|
98
|
+
}) => Promise<import("react").JSX.Element>;
|
|
99
|
+
HomePage: () => Promise<import("react").JSX.Element>;
|
|
100
|
+
generateMetadata: ({ params, }: {
|
|
101
|
+
params: Promise<{
|
|
102
|
+
puckPath: string[];
|
|
103
|
+
}>;
|
|
104
|
+
}) => Promise<Metadata>;
|
|
105
|
+
generateHomeMetadata: () => Promise<Metadata>;
|
|
106
|
+
generateStaticParams: () => {
|
|
107
|
+
puckPath: string[];
|
|
108
|
+
}[];
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=create-published-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-published-page.d.ts","sourceRoot":"","sources":["../src/create-published-page.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAErC,OAAO,EAKL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAS7C;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,EAAE,qBAAqB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;OAGG;IACH,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,wBAAwB,CAAC,CAAC;IACtD;;;;OAIG;IACH,WAAW,EAAE,KAAK,CAAC,aAAa,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC;IAC9B,oDAAoD;IACpD,QAAQ,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACrC;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QACvB,QAAQ,EAAE,IAAI,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE;QACP,oDAAoD;QACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,8DAA8D;QAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,6EAA6E;QAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,4EAA4E;IAC5E,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,yBAAyB;wBAuFhE;QACD,MAAM,EAAE,OAAO,CAAC;YAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KACzC;;oCAZE;QACD,MAAM,EAAE,OAAO,CAAC;YAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KACzC,KAAG,OAAO,CAAC,QAAQ,CAAC;gCA2BkB,OAAO,CAAC,QAAQ,CAAC;gCAnCvB;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE;EA0D1D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cache } from "react";
|
|
3
|
+
import { notFound } from "next/navigation";
|
|
4
|
+
import { loadRemoteDatasourceContext, extractReferencedDatasourceIds, resolveDataTemplates, pagePathFromCatchAllSegments, } from "@pantheon-systems/puck-css/server";
|
|
5
|
+
import { createCssQueryFetchers } from "./css-query-fetchers";
|
|
6
|
+
import { loadPublishedPage, loadRouteTemplateKeys, } from "./published-page";
|
|
7
|
+
export function createPublishedPage(config) {
|
|
8
|
+
const { Client, Unavailable, Fallback, fetchers = [], resolveMetadata, titles, internalPathPrefixes, } = config;
|
|
9
|
+
const loadOptions = internalPathPrefixes ? { internalPathPrefixes } : undefined;
|
|
10
|
+
const getCssQueryFetchers = cache(() => createCssQueryFetchers());
|
|
11
|
+
async function resolve(path, data) {
|
|
12
|
+
const [routeTemplateKeys, cssQueryFetchers] = await Promise.all([
|
|
13
|
+
loadRouteTemplateKeys(),
|
|
14
|
+
getCssQueryFetchers(),
|
|
15
|
+
]);
|
|
16
|
+
const context = await loadRemoteDatasourceContext({
|
|
17
|
+
fetchImpl: fetch,
|
|
18
|
+
pagePath: path,
|
|
19
|
+
routeTemplateKeys,
|
|
20
|
+
builtinFetchers: [...fetchers, ...cssQueryFetchers],
|
|
21
|
+
referencedDatasourceIds: extractReferencedDatasourceIds(data),
|
|
22
|
+
});
|
|
23
|
+
return resolveDataTemplates(data, context);
|
|
24
|
+
}
|
|
25
|
+
async function render(path, data) {
|
|
26
|
+
const resolvedData = await resolve(path, data);
|
|
27
|
+
return (_jsx(Client, { data: resolvedData, pageMetadata: {
|
|
28
|
+
route: path,
|
|
29
|
+
documentName: data.root.props?.title,
|
|
30
|
+
pageType: "page",
|
|
31
|
+
} }));
|
|
32
|
+
}
|
|
33
|
+
async function metadataFor(result, path) {
|
|
34
|
+
if (result.status === "missing") {
|
|
35
|
+
return { title: titles?.notFound ?? "Not Found" };
|
|
36
|
+
}
|
|
37
|
+
if (result.status === "unavailable") {
|
|
38
|
+
return { title: titles?.unavailable ?? "Temporarily unavailable" };
|
|
39
|
+
}
|
|
40
|
+
return resolveMetadata
|
|
41
|
+
? resolveMetadata({ pageData: result.data, path })
|
|
42
|
+
: {};
|
|
43
|
+
}
|
|
44
|
+
function generateStaticParams() {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
async function generateMetadata({ params, }) {
|
|
48
|
+
const { puckPath = [] } = await params;
|
|
49
|
+
const path = pagePathFromCatchAllSegments(puckPath);
|
|
50
|
+
return metadataFor(await loadPublishedPage(path, loadOptions), path);
|
|
51
|
+
}
|
|
52
|
+
async function Page({ params, }) {
|
|
53
|
+
const { puckPath = [] } = await params;
|
|
54
|
+
const path = pagePathFromCatchAllSegments(puckPath);
|
|
55
|
+
const result = await loadPublishedPage(path, loadOptions);
|
|
56
|
+
if (result.status === "missing") {
|
|
57
|
+
notFound();
|
|
58
|
+
}
|
|
59
|
+
if (result.status === "unavailable") {
|
|
60
|
+
return _jsx(Unavailable, {});
|
|
61
|
+
}
|
|
62
|
+
return render(path, result.data);
|
|
63
|
+
}
|
|
64
|
+
async function generateHomeMetadata() {
|
|
65
|
+
const result = await loadPublishedPage("/", loadOptions);
|
|
66
|
+
if (result.status !== "ok") {
|
|
67
|
+
return { title: titles?.home ?? "Home" };
|
|
68
|
+
}
|
|
69
|
+
return metadataFor(result, "/");
|
|
70
|
+
}
|
|
71
|
+
async function HomePage() {
|
|
72
|
+
const result = await loadPublishedPage("/", loadOptions);
|
|
73
|
+
if (result.status !== "ok") {
|
|
74
|
+
return _jsx(Fallback, {});
|
|
75
|
+
}
|
|
76
|
+
return render("/", result.data);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
Page,
|
|
80
|
+
HomePage,
|
|
81
|
+
generateMetadata,
|
|
82
|
+
generateHomeMetadata,
|
|
83
|
+
generateStaticParams,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=create-published-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-published-page.js","sourceRoot":"","sources":["../src/create-published-page.tsx"],"names":[],"mappings":";AAqCA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,oBAAoB,EACpB,4BAA4B,GAE7B,MAAM,mCAAmC,CAAC;AAG3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D,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YACpC,OAAO,KAAC,WAAW,KAAG,CAAC;QACzB,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,UAAU,oBAAoB;QACjC,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACzD,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,MAAM,EAAE,CAAC;QAC3C,CAAC;QACD,OAAO,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,UAAU,QAAQ;QACrB,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACzD,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,KAAC,QAAQ,KAAG,CAAC;QACtB,CAAC;QACD,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,OAAO;QACL,IAAI;QACJ,QAAQ;QACR,gBAAgB;QAChB,oBAAoB;QACpB,oBAAoB;KACrB,CAAC;AACJ,CAAC"}
|
package/dist/editor-paths.js
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Editor URL → page path mapping, shared by the server page handler and the
|
|
3
|
-
* client-side editor. Pure and client-safe: the editor renders from a
|
|
4
|
-
* persistent layout (so it survives route-param changes) and derives its page
|
|
5
|
-
* path from usePathname() with these helpers, which must agree with the
|
|
6
|
-
* server's parsing in pages-handler.
|
|
7
|
-
*/
|
|
8
1
|
import { pagePathFromCatchAllSegments } from "@pantheon-systems/puck-css/routes";
|
|
9
2
|
export function parseEditorSegments(segments) {
|
|
10
3
|
if (segments.length === 0)
|
|
11
4
|
return "/";
|
|
12
5
|
const command = segments[0];
|
|
13
|
-
// /p1/api/... is handled by the route handler, not the page
|
|
14
6
|
if (command === "api")
|
|
15
7
|
return "/";
|
|
16
|
-
// /p1/edit/... -> editor for the path
|
|
17
8
|
if (command === "edit") {
|
|
18
9
|
return pagePathFromCatchAllSegments(segments.slice(1));
|
|
19
10
|
}
|
|
20
|
-
// /p1/... (anything else) -> editor for that path
|
|
21
11
|
return pagePathFromCatchAllSegments(segments);
|
|
22
12
|
}
|
|
23
13
|
export function editorPagePathFromUrlPath(pathname, basePath = "/p1") {
|
|
24
14
|
if (pathname !== basePath && !pathname.startsWith(`${basePath}/`)) {
|
|
25
|
-
// Falling back silently would make the editor load and edit the root
|
|
26
|
-
// document while the URL points somewhere else entirely.
|
|
27
15
|
console.warn(`[p1-next-sdk] "${pathname}" is outside the editor base path "${basePath}"; ` +
|
|
28
16
|
`falling back to the root page. If the editor is not mounted at ${basePath}, ` +
|
|
29
17
|
`pass the correct basePath to editorPagePathFromUrlPath.`);
|
package/dist/editor-paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-paths.js","sourceRoot":"","sources":["../src/editor-paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editor-paths.js","sourceRoot":"","sources":["../src/editor-paths.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACpD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IACtC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAG5B,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC;IAGlC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,4BAA4B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;IAGD,OAAO,4BAA4B,CAAC,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,QAAgB,EAChB,QAAQ,GAAG,KAAK;IAEhB,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,EAAE,CAAC;QAGlE,OAAO,CAAC,IAAI,CACV,kBAAkB,QAAQ,sCAAsC,QAAQ,KAAK;YAC3E,kEAAkE,QAAQ,IAAI;YAC9E,yDAAyD,CAC5D,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ;SACtB,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;SACtB,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/handler-actions.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Barrel re-export for handler actions.
|
|
3
|
-
* Each domain lives in its own route module under `./routes/`.
|
|
4
|
-
*/
|
|
5
1
|
export { normalizePath } from "@pantheon-systems/puck-css/server";
|
|
6
2
|
export { getPageData } from "./routes/page-data";
|
|
7
3
|
export { getEditorContext } from "./routes/editor-context";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-actions.js","sourceRoot":"","sources":["../src/handler-actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-actions.js","sourceRoot":"","sources":["../src/handler-actions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACvH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/handler.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* P1 Next SDK handler — NextAuth-style catch-all for `/p1/api/[...p1]`.
|
|
3
|
-
*
|
|
4
|
-
* Usage in your Next.js app:
|
|
5
|
-
*
|
|
6
|
-
* // app/p1/api/[...p1]/route.ts
|
|
7
|
-
* import { createP1Handler } from "@pantheon-systems/p1-next-sdk";
|
|
8
|
-
* import config from "../../../../puck.config";
|
|
9
|
-
* const handler = createP1Handler({ config });
|
|
10
|
-
* export const { GET, POST, DELETE } = handler;
|
|
11
|
-
*/
|
|
12
1
|
import { NextResponse } from "next/server";
|
|
13
2
|
import { ensureInitialized } from "@pantheon-systems/puck-css/server";
|
|
14
3
|
import { runWithAuthToken } from "@pantheon-systems/puck-css/server";
|
|
15
4
|
import { extractBearerToken } from "./auth-utils";
|
|
16
5
|
import { getPageData, getRemoteDatasources, getEditorContext, getDatasourceContext, getRoutes, postPublish, postResolvePreview, postPreviewMeta, postRemoteDatasources, deleteRemoteDatasources, } from "./handler-actions";
|
|
17
|
-
/** Extract the sub-path segments from the catch-all `p1` param under `/p1/api/`. */
|
|
18
6
|
function parseP1Segments(p1) {
|
|
19
7
|
if (p1.length === 0)
|
|
20
8
|
return { action: "", rest: [] };
|
|
@@ -28,10 +16,6 @@ function withAuth(request, fn) {
|
|
|
28
16
|
return NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
29
17
|
}
|
|
30
18
|
export function createP1Handler(opts) {
|
|
31
|
-
// Called per request, not pinned at module load: ensureInitialized dedupes
|
|
32
|
-
// successful inits and clears its state on failure, so a transient failure at
|
|
33
|
-
// cold start retries instead of leaving every later request awaiting a
|
|
34
|
-
// permanently rejected promise.
|
|
35
19
|
const init = () => ensureInitialized(opts);
|
|
36
20
|
async function GET(request, { params }) {
|
|
37
21
|
await init();
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,iBAAiB,EAAqB,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,SAAS,eAAe,CAAC,EAAY;IACnC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACrD,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAeD,SAAS,QAAQ,CAAI,OAAgB,EAAE,EAAW;IAChD,MAAM,KAAK,GAAG,kBA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E,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/middleware.js
CHANGED
|
@@ -15,10 +15,6 @@ export function createP1Middleware(config) {
|
|
|
15
15
|
return NextResponse.next();
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
// Asset-extension paths deliberately still reach getRedirect: redirects are
|
|
19
|
-
// user-configured for arbitrary paths, and migrating sites point old asset
|
|
20
|
-
// URLs at their new home. Only the document lookup is skipped (see
|
|
21
|
-
// resolvePageData).
|
|
22
18
|
try {
|
|
23
19
|
const redirect = await client.getRedirect(pathname);
|
|
24
20
|
if (redirect !== null) {
|
|
@@ -29,7 +25,6 @@ export function createP1Middleware(config) {
|
|
|
29
25
|
const validStatusCodes = [301, 302, 303, 307, 308];
|
|
30
26
|
const statusCode = validStatusCodes.includes(redirect.statusCode) ? redirect.statusCode : 301;
|
|
31
27
|
const destinationUrl = new URL(destination);
|
|
32
|
-
// Preserve original query parameters
|
|
33
28
|
if (url.search) {
|
|
34
29
|
url.searchParams.forEach((value, key) => {
|
|
35
30
|
if (!destinationUrl.searchParams.has(key)) {
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IAC3D,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB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,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,CAAC,IAAI,CAAC,0CAA0C,EAAE,OAAO,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/pages-handler.js
CHANGED
|
@@ -3,16 +3,7 @@ import { ensureInitialized, } from "@pantheon-systems/puck-css/server";
|
|
|
3
3
|
import { parseEditorSegments } from "./editor-paths";
|
|
4
4
|
export function createP1Pages(opts) {
|
|
5
5
|
const { EditorClient } = opts;
|
|
6
|
-
// Called per request, not pinned at module load: ensureInitialized dedupes
|
|
7
|
-
// successful inits and clears its state on failure, so a transient failure at
|
|
8
|
-
// cold start retries instead of leaving every later request awaiting a
|
|
9
|
-
// permanently rejected promise.
|
|
10
6
|
const init = () => ensureInitialized(opts);
|
|
11
|
-
// A parent layout always renders before its child page within a request, so
|
|
12
|
-
// if the editor is mounted correctly Layout flips this before Page reads it.
|
|
13
|
-
// A legacy page-only app (no `(editor)/layout.tsx`) renders Page alone, and
|
|
14
|
-
// the flag is still false — the dev-only nudge below fires. Per-process,
|
|
15
|
-
// best-effort: it can't run in production and never affects output.
|
|
16
7
|
let layoutRendered = false;
|
|
17
8
|
let warnedMissingLayout = false;
|
|
18
9
|
async function generateMetadata({ params, }) {
|
|
@@ -21,14 +12,11 @@ export function createP1Pages(opts) {
|
|
|
21
12
|
const pagePath = parseEditorSegments(p1);
|
|
22
13
|
return { title: "P1 Editor: " + pagePath };
|
|
23
14
|
}
|
|
24
|
-
// Persists across route-param changes — the editor lives here. Sets the flag
|
|
25
|
-
// synchronously (before any await) so Page can observe it in the same request.
|
|
26
15
|
async function Layout({ children }) {
|
|
27
16
|
layoutRendered = true;
|
|
28
17
|
await init();
|
|
29
18
|
return (_jsxs(_Fragment, { children: [_jsx(EditorClient, {}), children] }));
|
|
30
19
|
}
|
|
31
|
-
// Remounts per navigation; must stay empty so nothing is lost when it does.
|
|
32
20
|
function Page() {
|
|
33
21
|
if (process.env.NODE_ENV !== "production" &&
|
|
34
22
|
!layoutRendered &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages-handler.js","sourceRoot":"","sources":["../src/pages-handler.tsx"],"names":[],"mappings":";AA4CA,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"pages-handler.js","sourceRoot":"","sources":["../src/pages-handler.tsx"],"names":[],"mappings":";AA4CA,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAK9B,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAO3C,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,mBAAmB,GAAG,KAAK,CAAC;IAEhC,KAAK,UAAU,gBAAgB,CAAC,EAC9B,MAAM,GAGP;QACC,MAAM,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,MAAM,MAAM,CAAC;QACjC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,EAAE,KAAK,EAAE,aAAa,GAAG,QAAQ,EAAE,CAAC;IAC7C,CAAC;IAID,KAAK,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAiC;QAC/D,cAAc,GAAG,IAAI,CAAC;QACtB,MAAM,IAAI,EAAE,CAAC;QACb,OAAO,CACL,8BACE,KAAC,YAAY,KAAG,EACf,QAAQ,IACR,CACJ,CAAC;IACJ,CAAC;IAGD,SAAS,IAAI;QACX,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACrC,CAAC,cAAc;YACf,CAAC,mBAAmB,EACpB,CAAC;YACD,mBAAmB,GAAG,IAAI,CAAC;YAC3B,OAAO,CAAC,IAAI,CACV,sEAAsE;gBACpE,uEAAuE;gBACvE,4CAA4C;gBAC5C,qDAAqD;gBACrD,iCAAiC,CACpC,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAC5C,CAAC"}
|
package/dist/published-page.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* invariants that keep public routes cacheable and correct: initialization is
|
|
6
6
|
* awaited per read so a failed cold start can recover, a miss is reported
|
|
7
7
|
* distinctly from an outage so it can become a real 404 instead of a cached
|
|
8
|
-
* 200,
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* 200, internal document namespaces are refused before they can render as
|
|
9
|
+
* public pages, and prerendering is aborted rather than baking an empty page
|
|
10
|
+
* into the build. A renderer that gets any of those wrong fails in ways that
|
|
11
|
+
* only show up under CDN caching or a backend blip.
|
|
11
12
|
*
|
|
12
13
|
* How a miss is presented — the copy, the styling, the editor links — is the
|
|
13
14
|
* app's business, and stays in the app.
|
|
@@ -30,13 +31,25 @@ export type PublishedPageResult = {
|
|
|
30
31
|
} | {
|
|
31
32
|
status: "unavailable";
|
|
32
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Options for a published-page read.
|
|
36
|
+
*/
|
|
37
|
+
export type LoadPublishedPageOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Extra path prefixes to refuse, added to the built-in list rather than
|
|
40
|
+
* replacing it. Additive on purpose: a site that needs its own internal
|
|
41
|
+
* namespace should not be able to un-block `/_registry` by supplying a
|
|
42
|
+
* shorter list.
|
|
43
|
+
*/
|
|
44
|
+
internalPathPrefixes?: readonly string[];
|
|
45
|
+
};
|
|
33
46
|
/**
|
|
34
47
|
* Published Puck data for `path`.
|
|
35
48
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
49
|
+
* Internal namespaces report `missing` without reaching the backend, so a
|
|
50
|
+
* renderer that carries no denylist of its own still 404s them.
|
|
38
51
|
*/
|
|
39
|
-
export declare
|
|
52
|
+
export declare function loadPublishedPage(path: string, options?: LoadPublishedPageOptions): Promise<PublishedPageResult>;
|
|
40
53
|
/**
|
|
41
54
|
* Collection template keys for the current render.
|
|
42
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published-page.d.ts","sourceRoot":"","sources":["../src/published-page.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"published-page.d.ts","sourceRoot":"","sources":["../src/published-page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAC5B;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAuEF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,QAAmB,OAAO,CAAC,MAAM,EAAE,CAGnE,CAAC"}
|
package/dist/published-page.js
CHANGED
|
@@ -1,50 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side readers for published content.
|
|
3
|
-
*
|
|
4
|
-
* These live in the SDK rather than the scaffolded app because they carry the
|
|
5
|
-
* invariants that keep public routes cacheable and correct: initialization is
|
|
6
|
-
* awaited per read so a failed cold start can recover, a miss is reported
|
|
7
|
-
* distinctly from an outage so it can become a real 404 instead of a cached
|
|
8
|
-
* 200, and prerendering is aborted rather than baking an empty page into the
|
|
9
|
-
* build. A renderer that gets any of those wrong fails in ways that only show
|
|
10
|
-
* up under CDN caching or a backend blip.
|
|
11
|
-
*
|
|
12
|
-
* How a miss is presented — the copy, the styling, the editor links — is the
|
|
13
|
-
* app's business, and stays in the app.
|
|
14
|
-
*/
|
|
15
1
|
import { cache } from "react";
|
|
16
2
|
import { connection } from "next/server";
|
|
17
3
|
import { ensureInitialized, getPage, listRouteTemplateKeysFromDatabase, } from "@pantheon-systems/puck-css/server";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
const INTERNAL_PATH_PREFIXES = ["/_registry", "/_redirects"];
|
|
5
|
+
function isInternalPath(path, extra) {
|
|
6
|
+
const normalized = path.toLowerCase();
|
|
7
|
+
return [...INTERNAL_PATH_PREFIXES, ...(extra ?? [])].some((prefix) => {
|
|
8
|
+
const target = prefix.toLowerCase();
|
|
9
|
+
return normalized === target || normalized.startsWith(`${target}/`);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
24
12
|
const initP1 = () => ensureInitialized({
|
|
25
13
|
p1BaseUrl: process.env.NEXT_PUBLIC_CSS_BASE_URL,
|
|
26
14
|
p1ApiKey: process.env.CSS_API_KEY,
|
|
27
15
|
p1SiteId: process.env.NEXT_PUBLIC_CSS_SITE_ID,
|
|
28
|
-
// Default to "main" when unset: server components (no user token) need a
|
|
29
|
-
// branch to list/read documents (e.g. the /structure routes table).
|
|
30
16
|
p1BranchId: process.env.NEXT_PUBLIC_CSS_BRANCH_ID ?? "main",
|
|
31
17
|
});
|
|
32
18
|
async function unavailable(path, error) {
|
|
33
19
|
console.warn(`[p1-next-sdk] published content unavailable for ${path}:`, error instanceof Error ? error.message : String(error));
|
|
34
|
-
// Aborts prerendering and defers to the request. Public pages are prerendered
|
|
35
|
-
// at build time now that they no longer opt out of caching, so without this a
|
|
36
|
-
// build running while the backend is down would fail outright, and a build
|
|
37
|
-
// against a half-up backend would bake the holding page into cached output.
|
|
38
20
|
await connection();
|
|
39
21
|
return { status: "unavailable" };
|
|
40
22
|
}
|
|
41
|
-
|
|
42
|
-
* Published Puck data for `path`.
|
|
43
|
-
*
|
|
44
|
-
* Memoized with cache(): generateMetadata and the page body both need the same
|
|
45
|
-
* page, and without this every render reads it from Postgres twice.
|
|
46
|
-
*/
|
|
47
|
-
export const loadPublishedPage = cache(async (path) => {
|
|
23
|
+
const readPublishedPage = cache(async (path) => {
|
|
48
24
|
try {
|
|
49
25
|
await initP1();
|
|
50
26
|
const data = await getPage(path);
|
|
@@ -54,12 +30,12 @@ export const loadPublishedPage = cache(async (path) => {
|
|
|
54
30
|
return unavailable(path, error);
|
|
55
31
|
}
|
|
56
32
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
33
|
+
export async function loadPublishedPage(path, options) {
|
|
34
|
+
if (isInternalPath(path, options?.internalPathPrefixes)) {
|
|
35
|
+
return { status: "missing" };
|
|
36
|
+
}
|
|
37
|
+
return readPublishedPage(path);
|
|
38
|
+
}
|
|
63
39
|
export const loadRouteTemplateKeys = cache(async () => {
|
|
64
40
|
await initP1();
|
|
65
41
|
return listRouteTemplateKeysFromDatabase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published-page.js","sourceRoot":"","sources":["../src/published-page.ts"],"names":[],"mappings":"
|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UAAU,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AACnC,CAAC;AASD,MAAM,iBAAiB,GAAG,KAAK,CAC7B,KAAK,EAAE,IAAY,EAAgC,EAAE;IACnD,IAAI,CAAC;QACH,MAAM,MAAM,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;AACH,CAAC,CACF,CAAC;AAQF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,OAAkC;IAElC,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,oBAAoB,CAAC,EAAE,CAAC;QACxD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAQD,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC,KAAK,IAAuB,EAAE;IACvE,MAAM,MAAM,EAAE,CAAC;IACf,OAAO,iCAAiC,EAAE,CAAC;AAC7C,CAAC,CAAC,CAAC"}
|
package/dist/routes/broker.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
export declare function postBrokerLogin(request: Request, apiKey: string | undefined, baseUrl: string | undefined, siteUrl?: string, redirectUrl?: string, prompt?: string): Promise<NextResponse<any>>;
|
|
3
3
|
export declare function postBrokerRedeem(request: Request, apiKey: string | undefined, baseUrl: string | undefined): Promise<NextResponse<any>>;
|
|
4
|
+
/**
|
|
5
|
+
* Unlike login and redeem, this carries no API key: logout authenticates with
|
|
6
|
+
* the broker JWT the browser already holds. The hop exists so a proxy-mode app
|
|
7
|
+
* can keep a same-origin connect-src, matching how login and redeem are routed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function postBrokerLogout(request: Request, baseUrl: string | undefined): Promise<NextResponse<any>>;
|
|
4
10
|
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/routes/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsB3C,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,8BA+EhB;AA6BD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,8BA0C5B"}
|
|
1
|
+
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/routes/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsB3C,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,8BA+EhB;AA6BD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,8BA0C5B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,8BA0C5B"}
|
package/dist/routes/broker.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
|
-
// Route Handler `request.url` reflects the Node server's own bind address
|
|
3
|
-
// (e.g. localhost:3000), not the Host the browser actually requested, once a
|
|
4
|
-
// reverse proxy is involved -- but its scheme is unaffected by that, so only
|
|
5
|
-
// the host needs replacing.
|
|
6
|
-
//
|
|
7
|
-
// Deliberately reads `host`, NOT `x-forwarded-host`: on Pantheon, `Host` is
|
|
8
|
-
// what the edge routes on, so a request only reaches this container with a
|
|
9
|
-
// Host that resolves to this site -- an arbitrary Host 404s upstream.
|
|
10
|
-
// `X-Forwarded-Host` is not similarly validated; it passes through from the
|
|
11
|
-
// client unchanged, so trusting it here would let anyone redirect a login
|
|
12
|
-
// to an attacker-controlled origin (confirmed empirically, not theoretical).
|
|
13
2
|
function deriveOriginFromRequest(request) {
|
|
14
3
|
const host = request.headers.get("host");
|
|
15
4
|
const requestUrl = new URL(request.url);
|
|
@@ -49,10 +38,6 @@ export async function postBrokerLogin(request, apiKey, baseUrl, siteUrl, redirec
|
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
40
|
const effectiveRedirectUrl = redirectUrl ?? actualOrigin + basePath;
|
|
52
|
-
// PCC-3531: the fallback above yields localhost on a deployed site because this
|
|
53
|
-
// server cannot see its own public origin. The browser can, so pass its origin
|
|
54
|
-
// upstream as a proposal for CCR to validate. Skipped when a target is
|
|
55
|
-
// configured, keeping those requests byte-identical to before.
|
|
56
41
|
const hasExplicitTarget = redirectUrl !== undefined || siteUrlValue !== undefined;
|
|
57
42
|
const proposedOrigin = hasExplicitTarget
|
|
58
43
|
? undefined
|
|
@@ -70,18 +55,12 @@ export async function postBrokerLogin(request, apiKey, baseUrl, siteUrl, redirec
|
|
|
70
55
|
if (!response.ok) {
|
|
71
56
|
return NextResponse.json(body, { status: response.status });
|
|
72
57
|
}
|
|
73
|
-
// Log then strip: this route is public, so echoing the warning would let anyone
|
|
74
|
-
// probe whether an origin is registered for a site. The browser never reads it.
|
|
75
58
|
const { warning, ...clientBody } = body;
|
|
76
59
|
if (typeof warning === "string" && warning !== "") {
|
|
77
60
|
console.warn(`[P1AuthHandler] ${warning}`);
|
|
78
61
|
}
|
|
79
62
|
return NextResponse.json(clientBody);
|
|
80
63
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Still untrusted after this — CCR validates against the site's registered
|
|
83
|
-
* origins. Malformed values are dropped rather than forwarded upstream.
|
|
84
|
-
*/
|
|
85
64
|
async function readProposedOrigin(request) {
|
|
86
65
|
let parsed;
|
|
87
66
|
try {
|
|
@@ -95,8 +74,6 @@ async function readProposedOrigin(request) {
|
|
|
95
74
|
return undefined;
|
|
96
75
|
}
|
|
97
76
|
try {
|
|
98
|
-
// Re-deriving the origin and requiring an exact match rejects anything
|
|
99
|
-
// carrying a path or credentials.
|
|
100
77
|
const url = new URL(candidate);
|
|
101
78
|
return url.origin === candidate ? candidate : undefined;
|
|
102
79
|
}
|
|
@@ -132,4 +109,29 @@ export async function postBrokerRedeem(request, apiKey, baseUrl) {
|
|
|
132
109
|
}
|
|
133
110
|
return NextResponse.json(body);
|
|
134
111
|
}
|
|
112
|
+
export async function postBrokerLogout(request, baseUrl) {
|
|
113
|
+
if (!baseUrl) {
|
|
114
|
+
return NextResponse.json({ error: "Server configuration error" }, { status: 500 });
|
|
115
|
+
}
|
|
116
|
+
const authorization = request.headers.get("authorization");
|
|
117
|
+
if (authorization === null) {
|
|
118
|
+
return NextResponse.json({ error: "Authentication required" }, { status: 401 });
|
|
119
|
+
}
|
|
120
|
+
const origin = request.headers.get("origin");
|
|
121
|
+
const response = await fetch(`${baseUrl}/broker/logout`, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: {
|
|
124
|
+
"Content-Type": "application/json",
|
|
125
|
+
"Authorization": authorization,
|
|
126
|
+
...(origin !== null ? { "Origin": origin } : {}),
|
|
127
|
+
},
|
|
128
|
+
body: await request.text(),
|
|
129
|
+
});
|
|
130
|
+
const body = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
return NextResponse.json(body, { status: response.status });
|
|
133
|
+
}
|
|
134
|
+
const { warning: _warning, ...clientBody } = body;
|
|
135
|
+
return NextResponse.json(clientBody);
|
|
136
|
+
}
|
|
135
137
|
//# sourceMappingURL=broker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/routes/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/routes/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAa3C,SAAS,uBAAuB,CAAC,OAAgB;IAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,UAAU,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAgB,EAChB,MAA0B,EAC1B,OAA2B,EAC3B,OAAgB,EAChB,WAAoB,EACpB,MAAe;IAEf,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC,IAAI,CACtB,EAAE,KAAK,EAAE,4BAA4B,EAAE,EACvC,EAAE,MAAM,EAAE,GAAG,EAAE,C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OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,aAAa;YAC9B,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjD;QACD,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,EAAE;KAC3B,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAE7E,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;IAID,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,IAG5C,CAAC;IAEF,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -21,12 +21,12 @@ export async function getDatasourceContext(request, options) {
|
|
|
21
21
|
const referencedDatasourceIds = new Set([id]);
|
|
22
22
|
const token = extractBearerToken(request);
|
|
23
23
|
const client = token ? createAuthenticatedClient(token) : null;
|
|
24
|
-
const
|
|
24
|
+
const ccrQueryFetchers = await createCssQueryFetchers({
|
|
25
25
|
client,
|
|
26
26
|
branchId,
|
|
27
27
|
filterIds: referencedDatasourceIds,
|
|
28
28
|
});
|
|
29
|
-
const allFetchers = [...(options.builtinFetchers ?? []), ...
|
|
29
|
+
const allFetchers = [...(options.builtinFetchers ?? []), ...ccrQueryFetchers];
|
|
30
30
|
const context = await loadRemoteDatasourceContext({
|
|
31
31
|
searchParams: Object.fromEntries(url.searchParams.entries()),
|
|
32
32
|
pagePath: path,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import { normalizePath, listRoutes, listRouteTemplateKeysFromDatabase, getPageEditorPreviewParams, buildRemoteDatasourceRegistry, listRemoteDatasourcesForPage, cssQueriesToDatasourceDefinitions, getSharedSiteId, getSharedBranchId, createAuthenticatedClient, runWithAuthToken, } from "@pantheon-systems/puck-css/server";
|
|
3
3
|
import { extractBearerToken } from "../auth-utils";
|
|
4
|
-
async function
|
|
4
|
+
async function fetchCcrQueryDefinitions(request, branchOverride) {
|
|
5
5
|
const siteId = getSharedSiteId();
|
|
6
6
|
const branchId = branchOverride || getSharedBranchId();
|
|
7
7
|
const token = extractBearerToken(request);
|
|
@@ -18,7 +18,7 @@ async function fetchCssQueryDefinitions(request, branchOverride) {
|
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
-
console.warn("[P1] Editor context:
|
|
21
|
+
console.warn("[P1] Editor context: query lookup failed:", message);
|
|
22
22
|
return [];
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -30,9 +30,6 @@ export async function getEditorContext(request, options) {
|
|
|
30
30
|
if (path === null) {
|
|
31
31
|
return NextResponse.json({ error: "invalid_path" }, { status: 400 });
|
|
32
32
|
}
|
|
33
|
-
// Unlike getRoutes, a missing token degrades rather than 401s: the editor
|
|
34
|
-
// falls back to an unauthenticated fetch and treats any error response as
|
|
35
|
-
// fatal, so rejecting here would break auth-optional deployments.
|
|
36
33
|
const token = extractBearerToken(request);
|
|
37
34
|
const run = (fn) => token ? runWithAuthToken(token, fn) : fn();
|
|
38
35
|
return run(() => buildEditorContext(request, options, path, branchId));
|
|
@@ -44,12 +41,10 @@ async function buildEditorContext(request, options, path, branchId) {
|
|
|
44
41
|
Promise.resolve(getPageEditorPreviewParams(path)),
|
|
45
42
|
Promise.resolve(listRemoteDatasourcesForPage(path)),
|
|
46
43
|
]);
|
|
47
|
-
|
|
48
|
-
// that call, and getSharedBranchId() returns null until it completes.
|
|
49
|
-
const cssQueryDefinitions = await fetchCssQueryDefinitions(request, branchId);
|
|
44
|
+
const ccrQueryDefinitions = await fetchCcrQueryDefinitions(request, branchId);
|
|
50
45
|
const remoteDatasourceRegistry = [
|
|
51
46
|
...buildRemoteDatasourceRegistry(options.builtinDatasourceRegistry ?? [], userDefs.global, userDefs.page),
|
|
52
|
-
...
|
|
47
|
+
...ccrQueryDefinitions,
|
|
53
48
|
];
|
|
54
49
|
return NextResponse.json({
|
|
55
50
|
remoteDatasourceContext: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-context.js","sourceRoot":"","sources":["../../src/routes/editor-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,aAAa,EACb,UAAU,EACV,iCAAiC,EACjC,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,iCAAiC,EACjC,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAK3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOnD,KAAK,UAAU,wBAAwB,CAAC,OAAgB,EAAE,cAA8B;IACtF,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,cAAc,IAAI,iBAAiB,EAAE,CAAC;IACvD,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAC;IAEpC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,MAAM,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO,EAAE,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,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AC,CAAC;AACzE,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,OAAgB,EAChB,OAA6B,EAC7B,IAAY,EACZ,QAAuB;IAEvB,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,CAAC,GAC7D,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,UAAU,EAAE;QACZ,iCAAiC,EAAE;QACnC,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAC;QACjD,OAAO,CAAC,OAAO,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC;KACpD,CAAC,CAAC;IAIL,MAAM,mBAAmB,GAAG,MAAM,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE9E,MAAM,wBAAwB,GAAG;QAC/B,GAAG,6BAA6B,CAC9B,OAAO,CAAC,yBAAyB,IAAI,EAAE,EACvC,QAAQ,CAAC,MAAM,EACf,QAAQ,CAAC,IAAI,CACd;QACD,GAAG,mBAAmB;KACvB,CAAC;IAEF,OAAO,YAAY,CAAC,IAAI,CAAC;QACvB,uBAAuB,EAAE,EAAE;QAC3B,MAAM;QACN,iBAAiB;QACjB,kBAAkB;QAClB,wBAAwB;KACzB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/routes/publish.js
CHANGED
|
@@ -2,11 +2,6 @@ import { revalidatePath } from "next/cache";
|
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
3
|
import { isRouteTemplatePath, normalizePath, listOverridePathsForBase, persistPublishedPage, } from "@pantheon-systems/puck-css/server";
|
|
4
4
|
export { postPublish as POST };
|
|
5
|
-
/**
|
|
6
|
-
* Dynamic segment rendering public pages, as Next.js names it for
|
|
7
|
-
* revalidatePath. Overridable for an app whose catch-all directory is not
|
|
8
|
-
* `[...puckPath]`.
|
|
9
|
-
*/
|
|
10
5
|
export const DEFAULT_PUBLIC_PAGE_SEGMENT = "/[...puckPath]";
|
|
11
6
|
export async function postPublish(request, { publicPageSegment = DEFAULT_PUBLIC_PAGE_SEGMENT } = {}) {
|
|
12
7
|
const payload = (await request.json());
|
|
@@ -20,11 +15,6 @@ export async function postPublish(request, { publicPageSegment = DEFAULT_PUBLIC_
|
|
|
20
15
|
for (const p of await listOverridePathsForBase(path)) {
|
|
21
16
|
revalidatePath(p);
|
|
22
17
|
}
|
|
23
|
-
// Instance URLs that resolve by template fall-through alone (/jedi/5 against
|
|
24
|
-
// /jedi/:id) have no store entry, so listOverridePathsForBase cannot
|
|
25
|
-
// enumerate them. Invalidating the catch-all segment is the only way to
|
|
26
|
-
// reach them; without it they serve pre-edit content until revalidate
|
|
27
|
-
// expires.
|
|
28
18
|
revalidatePath(publicPageSegment, "page");
|
|
29
19
|
}
|
|
30
20
|
return NextResponse.json({ status: "ok" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/routes/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,WAAW,IAAI,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/routes/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,WAAW,IAAI,IAAI,EAAE,CAAC;AAO/B,MAAM,CAAC,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AAE5D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,EAAE,iBAAiB,GAAG,2BAA2B,KAAqC,EAAE;IAExF,MAAM,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAiC,CAAC;IAEvE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,cAAc,CAAC,IAAI,CAAC,CAAC;IAErB,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,KAAK,MAAM,CAAC,IAAI,MAAM,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,cAAc,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QAMD,cAAc,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -14,7 +14,7 @@ export declare function postRemoteDatasources(request: Request): Promise<NextRes
|
|
|
14
14
|
error: string;
|
|
15
15
|
}> | NextResponse<{
|
|
16
16
|
ok: boolean;
|
|
17
|
-
scope: "
|
|
17
|
+
scope: "page" | "global";
|
|
18
18
|
path: string;
|
|
19
19
|
id: string;
|
|
20
20
|
}>>;
|
|
@@ -23,7 +23,7 @@ export declare function deleteRemoteDatasources(request: Request): Promise<NextR
|
|
|
23
23
|
error: string;
|
|
24
24
|
}> | NextResponse<{
|
|
25
25
|
ok: boolean;
|
|
26
|
-
scope: "
|
|
26
|
+
scope: "page" | "global";
|
|
27
27
|
path: string;
|
|
28
28
|
id: string;
|
|
29
29
|
}>>;
|
package/dist/server.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { createP1AuthHandler, type P1AuthHandlerConfig } from "./auth-handler";
|
|
|
3
3
|
export { createP1Pages, type P1PagesConfig } from "./pages-handler";
|
|
4
4
|
export { createCssQueryFetchers, type CreateCssQueryFetchersOptions } from "./css-query-fetchers";
|
|
5
5
|
export { createP1Middleware, type P1MiddlewareConfig } from "./middleware";
|
|
6
|
-
export {
|
|
6
|
+
export { createPublishedPage, type CreatePublishedPageConfig, type PublishedPageClientProps, type PublishedPageMetadata, } from "./create-published-page";
|
|
7
|
+
export { loadPublishedPage, loadRouteTemplateKeys, type LoadPublishedPageOptions, type PublishedPageResult, } from "./published-page";
|
|
7
8
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,KAAK,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,KAAK,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -3,5 +3,6 @@ export { createP1AuthHandler } from "./auth-handler";
|
|
|
3
3
|
export { createP1Pages } from "./pages-handler";
|
|
4
4
|
export { createCssQueryFetchers } from "./css-query-fetchers";
|
|
5
5
|
export { createP1Middleware } from "./middleware";
|
|
6
|
+
export { createPublishedPage, } from "./create-published-page";
|
|
6
7
|
export { loadPublishedPage, loadRouteTemplateKeys, } from "./published-page";
|
|
7
8
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAA4B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAsC,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAA4B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAsC,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,EACL,mBAAmB,GAIpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GAGtB,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pantheon-systems/p1-next-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Next.js SDK for P1 editor integration",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"server-only": "^0.0.1",
|
|
38
|
-
"@pantheon-systems/css-client": "0.
|
|
39
|
-
"@pantheon-systems/puck-css": "0.
|
|
38
|
+
"@pantheon-systems/css-client": "0.14.0",
|
|
39
|
+
"@pantheon-systems/puck-css": "0.14.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@puckeditor/core": ">=0.21.0",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@testing-library/dom": "^10.4.1",
|
|
49
49
|
"@testing-library/react": "^16.3.2",
|
|
50
|
+
"@types/node": "^20.19.30",
|
|
50
51
|
"@types/react": "^19.2.14",
|
|
51
52
|
"eslint": "^9.27.0",
|
|
52
53
|
"jsdom": "^24.1.3",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
},
|
|
57
58
|
"homepage": "https://github.com/pantheon-systems/p1-platform/tree/main/packages/p1-next-sdk",
|
|
58
59
|
"scripts": {
|
|
59
|
-
"build": "pnpm run clean && tsc",
|
|
60
|
+
"build": "pnpm run clean && tsc --emitDeclarationOnly && tsc --declaration false --declarationMap false --removeComments",
|
|
60
61
|
"clean": "rm -rf dist *.tsbuildinfo",
|
|
61
62
|
"lint": "eslint src",
|
|
62
63
|
"lint:fix": "eslint src --fix",
|