@parhelia/next 1.0.12903 → 1.0.13030
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/README.md +3 -8
- package/package.json +18 -4
- package/src/sitecore.d.ts +23 -0
- package/src/sitecore.js +69 -0
package/README.md
CHANGED
|
@@ -50,20 +50,15 @@ rendered `/logo.svg` on the server and `/parhelia/proxy/<head name>/logo.svg` in
|
|
|
50
50
|
HTML and a hydration mismatch. A head that lists the package in `serverExternalPackages` keeps it external (Next.js
|
|
51
51
|
refuses a package in both lists) and renders on the server with what the server's own environment sets.
|
|
52
52
|
|
|
53
|
-
`probe/run-probe.mjs` proves it on a real build: it copies the package into a head's `node_modules` (as
|
|
54
|
-
`scripts/e2e/contentful-site/install-parhelia-next.mjs` does), builds and starts it below a rendering-proxy path with
|
|
55
|
-
webpack and Turbopack, and compares the server's HTML with what the browser computes after hydration
|
|
56
|
-
(`node probe/run-probe.mjs` from this folder after the frontend install; ports 11091-11092, `--port` moves them).
|
|
57
|
-
|
|
58
53
|
A CMS's own helpers live in its entry (`@parhelia/next/contentful`). The root still re-exports `contentfulLivePreviewOrigins`
|
|
59
54
|
and `CONTENTFUL_APP_ORIGINS` for heads built before the entry existed (deprecated; removed in 2.0).
|
|
60
55
|
|
|
61
56
|
## Everything else: `@parhelia/head` and `@parhelia/react`
|
|
62
57
|
|
|
63
|
-
This package is the Next.js adapter over [`@parhelia/head`](
|
|
58
|
+
This package is the Next.js adapter over [`@parhelia/head`](https://www.npmjs.com/package/@parhelia/head), which holds everything a head renders with
|
|
64
59
|
whatever its framework (the frame-mode marker and empty-component hints, the rendered identity `/identity`, the editor signal
|
|
65
|
-
`/server`, rich-text sanitising `/rich-text`, the in-place refresh `/refresh`, the CMS entries `/contentful
|
|
66
|
-
`/
|
|
60
|
+
`/server`, rich-text sanitising `/rich-text`, the in-place refresh `/refresh`, the CMS entries `/contentful` and
|
|
61
|
+
`/umbraco`), and [`@parhelia/react`](https://www.npmjs.com/package/@parhelia/react), its React components (`ParheliaBridge`,
|
|
67
62
|
`ParheliaBridgeScript`, `ParheliaSlot`, `useParheliaRefresh`). Every entry of this package but `/config` is the same-named
|
|
68
63
|
entry of `@parhelia/head`, and the root also re-exports `@parhelia/react`: the very same bindings, so existing imports keep
|
|
69
64
|
working; read their documentation there. `withParhelia` transpiles all three packages, so the server render reads the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parhelia/next",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Serve a Next.js rendering head in the Parhelia editor: withParhelia() for next.config.js (/config), plus the React bindings of @parhelia/react and everything of @parhelia/head under the same entries (the editing bridge, slot markers, the in-place refresh, the rendered-content identity, the editor signal a head's server checks, rich-text sanitising, per-CMS marker helpers).",
|
|
3
|
+
"version": "1.0.13030",
|
|
4
|
+
"description": "Serve a Next.js rendering head in the Parhelia editor: withParhelia() for next.config.js (/config), plus the React bindings of @parhelia/react and everything of @parhelia/head under the same entries (the editing bridge, slot markers, the in-place refresh, the rendered-content identity, the editor signal a head's server checks, rich-text sanitising, per-CMS marker helpers), and withParheliaEditingRender() for a SitecoreAI editing host (/sitecore).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./src/typo3.d.ts",
|
|
39
39
|
"default": "./src/typo3.js"
|
|
40
40
|
},
|
|
41
|
+
"./sitecore": {
|
|
42
|
+
"types": "./src/sitecore.d.ts",
|
|
43
|
+
"default": "./src/sitecore.js"
|
|
44
|
+
},
|
|
41
45
|
"./refresh": {
|
|
42
46
|
"types": "./src/refresh.d.ts",
|
|
43
47
|
"default": "./src/refresh.js"
|
|
@@ -71,6 +75,9 @@
|
|
|
71
75
|
"typo3": [
|
|
72
76
|
"./src/typo3.d.ts"
|
|
73
77
|
],
|
|
78
|
+
"sitecore": [
|
|
79
|
+
"./src/sitecore.d.ts"
|
|
80
|
+
],
|
|
74
81
|
"refresh": [
|
|
75
82
|
"./src/refresh.d.ts"
|
|
76
83
|
],
|
|
@@ -96,16 +103,23 @@
|
|
|
96
103
|
"test": "vitest run"
|
|
97
104
|
},
|
|
98
105
|
"dependencies": {
|
|
99
|
-
"@parhelia/head": "1.0.
|
|
100
|
-
"@parhelia/react": "1.0.
|
|
106
|
+
"@parhelia/head": "1.0.13030",
|
|
107
|
+
"@parhelia/react": "1.0.13030"
|
|
101
108
|
},
|
|
102
109
|
"peerDependencies": {
|
|
110
|
+
"next": ">=15.5",
|
|
103
111
|
"react": ">=18"
|
|
104
112
|
},
|
|
113
|
+
"peerDependenciesMeta": {
|
|
114
|
+
"next": {
|
|
115
|
+
"optional": true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
105
118
|
"devDependencies": {
|
|
106
119
|
"@types/node": "*",
|
|
107
120
|
"@types/react": "19.2.18",
|
|
108
121
|
"jsdom": "^30.0.1",
|
|
122
|
+
"next": "16.4.2",
|
|
109
123
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
110
124
|
"vitest": "^4.1.11"
|
|
111
125
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "@parhelia/head/sitecore";
|
|
2
|
+
|
|
3
|
+
/** How Parhelia's canvas render is answered. */
|
|
4
|
+
export type ParheliaEditingRenderOptions = {
|
|
5
|
+
/** The CM's origin, which serves the editing bridge; `PARHELIA_SITECORE_ORIGIN` without one. */
|
|
6
|
+
sitecoreOrigin?: string;
|
|
7
|
+
/** The site when the CM's layout data names none (for example `sitecore.config`'s `defaultSite`). */
|
|
8
|
+
defaultSite?: string;
|
|
9
|
+
/** The language when the CM's request names none; `en` without one. */
|
|
10
|
+
defaultLanguage?: string;
|
|
11
|
+
/** Another address of the editing bridge than the CM's own. */
|
|
12
|
+
bridgeUrl?: string;
|
|
13
|
+
/** The page's name in the bridge's tag (`data-parhelia-source`); `sitecore` without one. */
|
|
14
|
+
source?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type RequestOf<H> = H extends { GET: (req: infer R) => unknown } ? R : Request;
|
|
18
|
+
|
|
19
|
+
/** The SDK's editing render handlers with a `POST` that also answers the CM's render request for Parhelia's canvas. */
|
|
20
|
+
export declare function withParheliaEditingRender<H extends { GET: (req: never) => Response | Promise<Response> }>(
|
|
21
|
+
handlers: H,
|
|
22
|
+
options?: ParheliaEditingRenderOptions,
|
|
23
|
+
): Omit<H, "POST"> & { POST: (req: RequestOf<H>) => Promise<Response> };
|
package/src/sitecore.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@parhelia/next/sitecore` is `@parhelia/head/sitecore`, plus {@link withParheliaEditingRender}: a SitecoreAI editing host's
|
|
3
|
+
* editing render route that also renders Parhelia's canvas. In `src/app/api/editing/render/route.ts`:
|
|
4
|
+
*
|
|
5
|
+
* import { createEditingRenderRouteHandlers } from '@sitecore-content-sdk/nextjs/route-handler';
|
|
6
|
+
* import { withParheliaEditingRender } from '@parhelia/next/sitecore';
|
|
7
|
+
*
|
|
8
|
+
* export const { GET, POST, OPTIONS } = withParheliaEditingRender(createEditingRenderRouteHandlers({}));
|
|
9
|
+
*
|
|
10
|
+
* Pages' requests carry an `Origin` and reach the Content SDK's handlers untouched. The CM's render request for the canvas is a
|
|
11
|
+
* server-to-server `POST` without one: it is rendered through the SDK's own `GET` in edit mode, and the page gets the editing
|
|
12
|
+
* bridge, loaded from the CM that `PARHELIA_SITECORE_ORIGIN` names.
|
|
13
|
+
*/
|
|
14
|
+
import { NextRequest } from "next/server.js";
|
|
15
|
+
|
|
16
|
+
import { addParheliaBridge, isParheliaRender, readSitecoreRenderRequest, sitecoreEditingQuery } from "@parhelia/head/sitecore";
|
|
17
|
+
|
|
18
|
+
export * from "@parhelia/head/sitecore";
|
|
19
|
+
|
|
20
|
+
const MISSING_ORIGIN =
|
|
21
|
+
"<html><body>Set PARHELIA_SITECORE_ORIGIN to the CM's origin, so the page can load Parhelia's editing bridge</body></html>";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The SDK's editing render handlers with a `POST` that also answers the CM's render request for Parhelia's canvas.
|
|
25
|
+
* @template {{ GET: (req: any) => Response | Promise<Response>, POST?: (req: any) => Response | Promise<Response> }} H
|
|
26
|
+
* @param {H} handlers
|
|
27
|
+
* @param {{ sitecoreOrigin?: string, defaultSite?: string, defaultLanguage?: string, bridgeUrl?: string, source?: string }} [options]
|
|
28
|
+
*/
|
|
29
|
+
export function withParheliaEditingRender(handlers, options = {}) {
|
|
30
|
+
/** @param {Request} req */
|
|
31
|
+
const POST = async (req) => {
|
|
32
|
+
if (req.headers.get("origin")) return handlers.POST ? handlers.POST(req) : new Response(null, { status: 405 });
|
|
33
|
+
|
|
34
|
+
const body = await req.json().catch(() => undefined);
|
|
35
|
+
const read = readSitecoreRenderRequest(body, {
|
|
36
|
+
fallbackQuery: new URL(req.url).searchParams,
|
|
37
|
+
defaultSite: options.defaultSite,
|
|
38
|
+
defaultLanguage: options.defaultLanguage,
|
|
39
|
+
});
|
|
40
|
+
if (!read.ok) return Response.json({ html: read.html }, { status: read.status });
|
|
41
|
+
|
|
42
|
+
const withBridge = isParheliaRender(read.request);
|
|
43
|
+
const sitecoreOrigin = options.sitecoreOrigin ?? process.env.PARHELIA_SITECORE_ORIGIN;
|
|
44
|
+
if (withBridge && !sitecoreOrigin) return Response.json({ html: MISSING_ORIGIN }, { status: 500 });
|
|
45
|
+
|
|
46
|
+
const url = new URL(req.url);
|
|
47
|
+
url.search = sitecoreEditingQuery(read.request).toString();
|
|
48
|
+
const headers = new Headers(req.headers);
|
|
49
|
+
headers.delete("content-length");
|
|
50
|
+
headers.delete("content-type");
|
|
51
|
+
const rendered = await handlers.GET(new NextRequest(url, { headers }));
|
|
52
|
+
if (!rendered.ok) return rendered;
|
|
53
|
+
|
|
54
|
+
const html = await rendered.text();
|
|
55
|
+
const page =
|
|
56
|
+
withBridge && sitecoreOrigin
|
|
57
|
+
? addParheliaBridge(html, { sitecoreOrigin, bridgeUrl: options.bridgeUrl, source: options.source })
|
|
58
|
+
: html;
|
|
59
|
+
const responseHeaders = new Headers(rendered.headers);
|
|
60
|
+
responseHeaders.delete("content-length");
|
|
61
|
+
responseHeaders.set("content-type", "application/json; charset=utf-8");
|
|
62
|
+
return new Response(JSON.stringify({ html: page }), {
|
|
63
|
+
status: rendered.status,
|
|
64
|
+
statusText: rendered.statusText,
|
|
65
|
+
headers: responseHeaders,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
return { ...handlers, POST };
|
|
69
|
+
}
|