@plasmicapp/nextjs-app-router 1.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Plasmic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ This package provides helpers for doing extractPlasmicQueryData() with Next.js App Router.
2
+
3
+ We normally use react-ssr-prepass to fake-render a React tree to gather data requirements. We can't do so in RSC mode, because all the client components are imported as placeholders, so we cannot fake-render them.
4
+
5
+ The idea here is to use the dev server's SSR instead! At SSR time (instead of RSC time), we do have access to imported client components. So... we could do pre-rendering there, gather the data needs, and respond with them. At RSC time, we hit the SSR endpoint, and parse out the data needs.
6
+
7
+ So...
8
+
9
+ 1. Create a `app/plasmic-ssr/[[...catchall]]/page.tsx` route, whose purpose is to perform SSR. It looks something like...
10
+
11
+ ```
12
+ import { ExtractPlasmicQueryData } from "@plasmicapp/nextjs-app-router";
13
+
14
+ export default async function CatchallPrepass(props: {
15
+ params?: Params;
16
+ }) {
17
+ const { params } = props;
18
+
19
+ const plasmicPath = params.catchall ? `/${params.catchall.join("/")}` : "/";
20
+ const prefetchedData = await PLASMIC.maybeFetchComponentData(plasmicPath);
21
+ if (!prefetchedData || prefetchedData.entryCompMetas.length === 0) {
22
+ notFound();
23
+ }
24
+
25
+ const pageMeta = prefetchedData.entryCompMetas[0];
26
+
27
+ return (
28
+ <ExtractPlasmicQueryData>
29
+ <PlasmicClientRootProvider
30
+ prefetchedData={prefetchedData}
31
+ pageParams={pageMeta.params}
32
+ >
33
+ <PlasmicComponent
34
+ component={pageMeta.displayName}
35
+ />
36
+ </PlasmicClientRootProvider>
37
+ </ExtractPlasmicQueryData>
38
+ )
39
+ }
40
+ ```
41
+
42
+ `<ExtractPlasmicQueryData />` is a new client component from this package, which basically performs `extractPlasmicQueryData()` on its children, and then renders a `<script data-plasmic-prefetch-id/>` tag with the json of the extracted data.
43
+
44
+ 2. From the real `app/[...catchall]/page.tsx` file, make use of this endpoint to read the extracted data:
45
+
46
+ ```
47
+ import { fetchExtractedQueryData } from "@plasmicapp/nextjs-app-router";
48
+
49
+ export default async function Catchall(props: {
50
+ params?: Params;
51
+ }) {
52
+ const { params } = props;
53
+
54
+ const plasmicPath = params.catchall ? `/${params.catchall.join("/")}` : "/";
55
+ const prefetchedData = await PLASMIC.maybeFetchComponentData(plasmicPath);
56
+
57
+ if (!prefetchedData || prefetchedData.entryCompMetas.length === 0) {
58
+ notFound();
59
+ }
60
+
61
+ const prepassHost = process.env.PLASMIC_PREPASS_HOST ?? process.env.VERCEL_URL ?? `http://localhost:${process.env.PORT ?? 3000}`;
62
+
63
+ const queryData = await fetchExtractedQueryData(`${prepassHost}/plasmic-ssr/${(params?.catchall ?? []).join("/")}`);
64
+
65
+ const pageMeta = prefetchedData.entryCompMetas[0];
66
+
67
+ return (
68
+ <PlasmicClientRootProvider
69
+ prefetchedData={prefetchedData}
70
+ prefetchedQueryData={queryData}
71
+ pageParams={pageMeta.params}
72
+ >
73
+ <PlasmicComponent
74
+ component={pageMeta.displayName}
75
+ />
76
+ </PlasmicClientRootProvider>
77
+ )
78
+ }
79
+ ```
80
+
81
+ Here, `fetchExtractedQueryData()` basically just hits the `/plasmic-ssr/` endpoint, and extracts the data from the json embedded in the `<script/>`.
82
+
83
+ The `prepassHost` to use is read from `PLASMIC_PREPASS_HOST` or `VERCEL_URL`. `VERCEL_URL` is available when your site is deployed on Vercel; it is the generated deployment url.
84
+
85
+ `@plasmicapp/nextjs-app-router` also comes with a `with-plasmic-prepass` command that you can use like this in your package.json:
86
+
87
+ ```
88
+ "script": {
89
+ "build": "with-plasmic-prepass -- next build"
90
+ }
91
+ ```
92
+
93
+ This script will start up the next dev server at some random port (by running npm run dev), run the passed command, and then kill the dev server. It will run the command with the proper `PLASMIC_PREPASS_HOST` env variable, so the user never needs to think about it. You can choose to use a different package.json script command to start the dev server via `with-plasmic-prepass -c prepass -- next build`.
94
+
95
+ Unfortunately another drawback is that the dev server and the build process will step on each other's toes, so you need to direct them to use different output folders. You do it in `next.config.js`:
96
+
97
+ ```
98
+ module.exports = {
99
+ distDir: process.env.PLASMIC_PREPASS_SERVER ? ".next-prepass" : ".next"
100
+ }
101
+ ```
102
+
103
+ The `PLASMIC_PREPASS_SERVER` environment variable will be set by with-plasmic-prepass.
104
+
105
+ So...
106
+
107
+ - At dev time, uses itself for extracting query data (hits `localhost:${PORT}`)
108
+ - At build time, we start a parallel dev server.
109
+ - In production, with revalidation, it will also use itself for extracting query data (using `VERCEL_URL` as the prepass host).
@@ -0,0 +1,18 @@
1
+ import * as React_2 from 'react';
2
+
3
+ /**
4
+ * EXPERIMENTAL
5
+ *
6
+ * A component that serves the same purpose as extractPlasmicQueryData(), but from
7
+ * React server components. This only works from frameworks that support
8
+ * React.useId() and React.use() (like Next.js 13).
9
+ *
10
+ * The children of this component will be run through `extractPlasmicQueryData()`.
11
+ */
12
+ export declare function ExtractPlasmicQueryData(props: {
13
+ children?: React_2.ReactNode;
14
+ }): React_2.JSX.Element | null;
15
+
16
+ export declare function fetchExtractedQueryData(url: string): Promise<any>;
17
+
18
+ export { }
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+
23
+ // src/extracted-data-fetcher.ts
24
+ import { parse as parseHtml } from "node-html-parser";
25
+ function fetchExtractedQueryData(url) {
26
+ return __async(this, null, function* () {
27
+ const res = yield fetch(url);
28
+ if (res.status !== 200) {
29
+ return void 0;
30
+ }
31
+ const html = yield res.text();
32
+ const root = parseHtml(html);
33
+ const script = root.querySelector("script[data-plasmic-prefetch-id]");
34
+ if (script) {
35
+ return JSON.parse(script.innerHTML);
36
+ }
37
+ return void 0;
38
+ });
39
+ }
40
+
41
+ // src/ExtractPlasmicQueryData.tsx
42
+ import { extractPlasmicQueryData } from "@plasmicapp/prepass";
43
+ import * as React from "react";
44
+ function ExtractPlasmicQueryData(props) {
45
+ const { children } = props;
46
+ if (!React.useId || !React.use) {
47
+ throw new Error(
48
+ `You can only use <ExtractPlasmicQueryData /> from server components.`
49
+ );
50
+ }
51
+ const scriptId = `plasmic-prefetch-${React.useId()}`;
52
+ console.log("SCRIPT ID", scriptId);
53
+ if (typeof window === "undefined") {
54
+ const data = React.use(
55
+ extractPlasmicQueryData(/* @__PURE__ */ React.createElement(React.Fragment, null, children))
56
+ );
57
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
58
+ "script",
59
+ {
60
+ type: "application/json",
61
+ dangerouslySetInnerHTML: { __html: JSON.stringify(data) },
62
+ "data-plasmic-prefetch-id": scriptId,
63
+ suppressHydrationWarning: true
64
+ }
65
+ ));
66
+ } else {
67
+ return null;
68
+ }
69
+ }
70
+ export {
71
+ ExtractPlasmicQueryData,
72
+ fetchExtractedQueryData
73
+ };
74
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/extracted-data-fetcher.ts", "../src/ExtractPlasmicQueryData.tsx"],
4
+ "sourcesContent": ["import { parse as parseHtml } from \"node-html-parser\";\n\nexport async function fetchExtractedQueryData(url: string) {\n const res = await fetch(url);\n if (res.status !== 200) {\n return undefined;\n }\n\n const html = await res.text();\n const root = parseHtml(html);\n const script = root.querySelector(\"script[data-plasmic-prefetch-id]\");\n if (script) {\n return JSON.parse(script.innerHTML);\n }\n return undefined;\n}\n", "import { extractPlasmicQueryData } from \"@plasmicapp/prepass\";\nimport * as React from \"react\";\n\n/**\n * EXPERIMENTAL\n *\n * A component that serves the same purpose as extractPlasmicQueryData(), but from\n * React server components. This only works from frameworks that support\n * React.useId() and React.use() (like Next.js 13).\n *\n * The children of this component will be run through `extractPlasmicQueryData()`.\n */\nexport function ExtractPlasmicQueryData(props: { children?: React.ReactNode }) {\n const { children } = props;\n if (!React.useId || !(React as any).use) {\n throw new Error(\n `You can only use <ExtractPlasmicQueryData /> from server components.`\n );\n }\n const scriptId = `plasmic-prefetch-${React.useId()}`;\n console.log(\"SCRIPT ID\", scriptId);\n if (typeof window === \"undefined\") {\n const data: Record<string, any> = (React as any).use(\n extractPlasmicQueryData(<>{children}</>)\n );\n return (\n <>\n <script\n type=\"application/json\"\n dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}\n data-plasmic-prefetch-id={scriptId}\n suppressHydrationWarning={true}\n />\n </>\n );\n } else {\n return null;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,iBAAiB;AAEnC,SAAsB,wBAAwB,KAAa;AAAA;AACzD,UAAM,MAAM,MAAM,MAAM,GAAG;AAC3B,QAAI,IAAI,WAAW,KAAK;AACtB,aAAO;AAAA,IACT;AAEA,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,OAAO,UAAU,IAAI;AAC3B,UAAM,SAAS,KAAK,cAAc,kCAAkC;AACpE,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA;;;ACfA,SAAS,+BAA+B;AACxC,YAAY,WAAW;AAWhB,SAAS,wBAAwB,OAAuC;AAC7E,QAAM,EAAE,SAAS,IAAI;AACrB,MAAI,CAAO,eAAS,CAAgB,WAAK;AACvC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,WAAW,oBAA0B,YAAM;AACjD,UAAQ,IAAI,aAAa,QAAQ;AACjC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,OAA2C;AAAA,MAC/C,wBAAwB,0DAAG,QAAS,CAAG;AAAA,IACzC;AACA,WACE,0DACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,yBAAyB,EAAE,QAAQ,KAAK,UAAU,IAAI,EAAE;AAAA,QACxD,4BAA0B;AAAA,QAC1B,0BAA0B;AAAA;AAAA,IAC5B,CACF;AAAA,EAEJ,OAAO;AACL,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ "use client";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __async = (__this, __arguments, generator) => {
31
+ return new Promise((resolve, reject) => {
32
+ var fulfilled = (value) => {
33
+ try {
34
+ step(generator.next(value));
35
+ } catch (e) {
36
+ reject(e);
37
+ }
38
+ };
39
+ var rejected = (value) => {
40
+ try {
41
+ step(generator.throw(value));
42
+ } catch (e) {
43
+ reject(e);
44
+ }
45
+ };
46
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
47
+ step((generator = generator.apply(__this, __arguments)).next());
48
+ });
49
+ };
50
+
51
+ // src/index.ts
52
+ var src_exports = {};
53
+ __export(src_exports, {
54
+ ExtractPlasmicQueryData: () => ExtractPlasmicQueryData,
55
+ fetchExtractedQueryData: () => fetchExtractedQueryData
56
+ });
57
+ module.exports = __toCommonJS(src_exports);
58
+
59
+ // src/extracted-data-fetcher.ts
60
+ var import_node_html_parser = require("node-html-parser");
61
+ function fetchExtractedQueryData(url) {
62
+ return __async(this, null, function* () {
63
+ const res = yield fetch(url);
64
+ if (res.status !== 200) {
65
+ return void 0;
66
+ }
67
+ const html = yield res.text();
68
+ const root = (0, import_node_html_parser.parse)(html);
69
+ const script = root.querySelector("script[data-plasmic-prefetch-id]");
70
+ if (script) {
71
+ return JSON.parse(script.innerHTML);
72
+ }
73
+ return void 0;
74
+ });
75
+ }
76
+
77
+ // src/ExtractPlasmicQueryData.tsx
78
+ var import_prepass = require("@plasmicapp/prepass");
79
+ var React = __toESM(require("react"));
80
+ function ExtractPlasmicQueryData(props) {
81
+ const { children } = props;
82
+ if (!React.useId || !React.use) {
83
+ throw new Error(
84
+ `You can only use <ExtractPlasmicQueryData /> from server components.`
85
+ );
86
+ }
87
+ const scriptId = `plasmic-prefetch-${React.useId()}`;
88
+ console.log("SCRIPT ID", scriptId);
89
+ if (typeof window === "undefined") {
90
+ const data = React.use(
91
+ (0, import_prepass.extractPlasmicQueryData)(/* @__PURE__ */ React.createElement(React.Fragment, null, children))
92
+ );
93
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
94
+ "script",
95
+ {
96
+ type: "application/json",
97
+ dangerouslySetInnerHTML: { __html: JSON.stringify(data) },
98
+ "data-plasmic-prefetch-id": scriptId,
99
+ suppressHydrationWarning: true
100
+ }
101
+ ));
102
+ } else {
103
+ return null;
104
+ }
105
+ }
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/extracted-data-fetcher.ts", "../src/ExtractPlasmicQueryData.tsx"],
4
+ "sourcesContent": ["export * from \"./extracted-data-fetcher\";\nexport * from \"./ExtractPlasmicQueryData\";\n", "import { parse as parseHtml } from \"node-html-parser\";\n\nexport async function fetchExtractedQueryData(url: string) {\n const res = await fetch(url);\n if (res.status !== 200) {\n return undefined;\n }\n\n const html = await res.text();\n const root = parseHtml(html);\n const script = root.querySelector(\"script[data-plasmic-prefetch-id]\");\n if (script) {\n return JSON.parse(script.innerHTML);\n }\n return undefined;\n}\n", "import { extractPlasmicQueryData } from \"@plasmicapp/prepass\";\nimport * as React from \"react\";\n\n/**\n * EXPERIMENTAL\n *\n * A component that serves the same purpose as extractPlasmicQueryData(), but from\n * React server components. This only works from frameworks that support\n * React.useId() and React.use() (like Next.js 13).\n *\n * The children of this component will be run through `extractPlasmicQueryData()`.\n */\nexport function ExtractPlasmicQueryData(props: { children?: React.ReactNode }) {\n const { children } = props;\n if (!React.useId || !(React as any).use) {\n throw new Error(\n `You can only use <ExtractPlasmicQueryData /> from server components.`\n );\n }\n const scriptId = `plasmic-prefetch-${React.useId()}`;\n console.log(\"SCRIPT ID\", scriptId);\n if (typeof window === \"undefined\") {\n const data: Record<string, any> = (React as any).use(\n extractPlasmicQueryData(<>{children}</>)\n );\n return (\n <>\n <script\n type=\"application/json\"\n dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}\n data-plasmic-prefetch-id={scriptId}\n suppressHydrationWarning={true}\n />\n </>\n );\n } else {\n return null;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAmC;AAEnC,SAAsB,wBAAwB,KAAa;AAAA;AACzD,UAAM,MAAM,MAAM,MAAM,GAAG;AAC3B,QAAI,IAAI,WAAW,KAAK;AACtB,aAAO;AAAA,IACT;AAEA,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,WAAO,wBAAAA,OAAU,IAAI;AAC3B,UAAM,SAAS,KAAK,cAAc,kCAAkC;AACpE,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA;;;ACfA,qBAAwC;AACxC,YAAuB;AAWhB,SAAS,wBAAwB,OAAuC;AAC7E,QAAM,EAAE,SAAS,IAAI;AACrB,MAAI,CAAO,eAAS,CAAgB,WAAK;AACvC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,WAAW,oBAA0B,YAAM;AACjD,UAAQ,IAAI,aAAa,QAAQ;AACjC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,OAA2C;AAAA,UAC/C,wCAAwB,0DAAG,QAAS,CAAG;AAAA,IACzC;AACA,WACE,0DACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,yBAAyB,EAAE,QAAQ,KAAK,UAAU,IAAI,EAAE;AAAA,QACxD,4BAA0B;AAAA,QAC1B,0BAA0B;AAAA;AAAA,IAC5B,CACF;AAAA,EAEJ,OAAO;AACL,WAAO;AAAA,EACT;AACF;",
6
+ "names": ["parseHtml"]
7
+ }
@@ -0,0 +1,3 @@
1
+ export declare function fetchExtractedQueryData(url: string): Promise<any>;
2
+
3
+ export { }
@@ -0,0 +1,42 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/extracted-data-fetcher.ts
23
+ import { parse as parseHtml } from "node-html-parser";
24
+ function fetchExtractedQueryData(url) {
25
+ return __async(this, null, function* () {
26
+ const res = yield fetch(url);
27
+ if (res.status !== 200) {
28
+ return void 0;
29
+ }
30
+ const html = yield res.text();
31
+ const root = parseHtml(html);
32
+ const script = root.querySelector("script[data-plasmic-prefetch-id]");
33
+ if (script) {
34
+ return JSON.parse(script.innerHTML);
35
+ }
36
+ return void 0;
37
+ });
38
+ }
39
+ export {
40
+ fetchExtractedQueryData
41
+ };
42
+ //# sourceMappingURL=react-server.esm.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/extracted-data-fetcher.ts"],
4
+ "sourcesContent": ["import { parse as parseHtml } from \"node-html-parser\";\n\nexport async function fetchExtractedQueryData(url: string) {\n const res = await fetch(url);\n if (res.status !== 200) {\n return undefined;\n }\n\n const html = await res.text();\n const root = parseHtml(html);\n const script = root.querySelector(\"script[data-plasmic-prefetch-id]\");\n if (script) {\n return JSON.parse(script.innerHTML);\n }\n return undefined;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,iBAAiB;AAEnC,SAAsB,wBAAwB,KAAa;AAAA;AACzD,UAAM,MAAM,MAAM,MAAM,GAAG;AAC3B,QAAI,IAAI,WAAW,KAAK;AACtB,aAAO;AAAA,IACT;AAEA,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,OAAO,UAAU,IAAI;AAC3B,UAAM,SAAS,KAAK,cAAc,kCAAkC;AACpE,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/react-server.ts
41
+ var react_server_exports = {};
42
+ __export(react_server_exports, {
43
+ fetchExtractedQueryData: () => fetchExtractedQueryData
44
+ });
45
+ module.exports = __toCommonJS(react_server_exports);
46
+
47
+ // src/extracted-data-fetcher.ts
48
+ var import_node_html_parser = require("node-html-parser");
49
+ function fetchExtractedQueryData(url) {
50
+ return __async(this, null, function* () {
51
+ const res = yield fetch(url);
52
+ if (res.status !== 200) {
53
+ return void 0;
54
+ }
55
+ const html = yield res.text();
56
+ const root = (0, import_node_html_parser.parse)(html);
57
+ const script = root.querySelector("script[data-plasmic-prefetch-id]");
58
+ if (script) {
59
+ return JSON.parse(script.innerHTML);
60
+ }
61
+ return void 0;
62
+ });
63
+ }
64
+ //# sourceMappingURL=react-server.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react-server.ts", "../src/extracted-data-fetcher.ts"],
4
+ "sourcesContent": ["export * from \"./extracted-data-fetcher\";\n", "import { parse as parseHtml } from \"node-html-parser\";\n\nexport async function fetchExtractedQueryData(url: string) {\n const res = await fetch(url);\n if (res.status !== 200) {\n return undefined;\n }\n\n const html = await res.text();\n const root = parseHtml(html);\n const script = root.querySelector(\"script[data-plasmic-prefetch-id]\");\n if (script) {\n return JSON.parse(script.innerHTML);\n }\n return undefined;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAmC;AAEnC,SAAsB,wBAAwB,KAAa;AAAA;AACzD,UAAM,MAAM,MAAM,MAAM,GAAG;AAC3B,QAAI,IAAI,WAAW,KAAK;AACtB,aAAO;AAAA,IACT;AAEA,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,WAAO,wBAAAA,OAAU,IAAI;AAC3B,UAAM,SAAS,KAAK,cAAc,kCAAkC;AACpE,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA;",
6
+ "names": ["parseHtml"]
7
+ }