@simpleview/cms-foundation 0.0.8 → 0.0.10

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.
@@ -0,0 +1,36 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import React, { Component } from "react";
3
+ class ErrorBoundary extends Component {
4
+ constructor(props) {
5
+ super(props);
6
+ this.state = {
7
+ hasError: false
8
+ };
9
+ }
10
+ static getDerivedStateFromError(error) {
11
+ return {
12
+ hasError: true,
13
+ error
14
+ };
15
+ }
16
+ componentDidCatch(error, errorInfo) {
17
+ console.error("ErrorBoundary caught an error:", error, errorInfo);
18
+ this.setState({
19
+ error,
20
+ errorInfo
21
+ });
22
+ if (this.props.onError) {
23
+ this.props.onError(error, errorInfo);
24
+ }
25
+ }
26
+ render() {
27
+ if (this.state.hasError) {
28
+ return /* @__PURE__ */ jsx("div", { children: "An unexpected error occured." });
29
+ }
30
+ return this.props.children;
31
+ }
32
+ }
33
+ export {
34
+ ErrorBoundary
35
+ };
36
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/ErrorBoundary/ErrorBoundary.tsx"],
4
+ "sourcesContent": ["import React, { Component } from \"react\";\r\nimport type { ReactNode, ErrorInfo } from \"react\";\r\nimport type {\r\n\tErrorBoundaryProps,\r\n\tErrorBoundaryState,\r\n} from \"./ErrorBoundary.types\";\r\n\r\nexport class ErrorBoundary extends Component<\r\n\tErrorBoundaryProps,\r\n\tErrorBoundaryState\r\n> {\r\n\tconstructor(props: ErrorBoundaryProps) {\r\n\t\tsuper(props);\r\n\t\tthis.state = {\r\n\t\t\thasError: false,\r\n\t\t};\r\n\t}\r\n\r\n\tstatic getDerivedStateFromError(error: Error): ErrorBoundaryState {\r\n\t\treturn {\r\n\t\t\thasError: true,\r\n\t\t\terror,\r\n\t\t};\r\n\t}\r\n\r\n\tcomponentDidCatch(error: Error, errorInfo: ErrorInfo): void {\r\n\t\t// Log the error to an error reporting service\r\n\t\tconsole.error(\"ErrorBoundary caught an error:\", error, errorInfo);\r\n\r\n\t\t// Update state with error info\r\n\t\tthis.setState({\r\n\t\t\terror,\r\n\t\t\terrorInfo,\r\n\t\t});\r\n\r\n\t\t// Call the onError callback if provided\r\n\t\tif (this.props.onError) {\r\n\t\t\tthis.props.onError(error, errorInfo);\r\n\t\t}\r\n\t}\r\n\r\n\trender(): ReactNode {\r\n\t\tif (this.state.hasError) {\r\n\t\t\treturn <div>An unexpected error occured.</div>;\r\n\t\t}\r\n\r\n\t\treturn this.props.children;\r\n\t}\r\n}\r\n"],
5
+ "mappings": "AA2CU;AA3CV,OAAO,SAAS,iBAAiB;AAO1B,MAAM,sBAAsB,UAGjC;AAAA,EACD,YAAY,OAA2B;AACtC,UAAM,KAAK;AACX,SAAK,QAAQ;AAAA,MACZ,UAAU;AAAA,IACX;AAAA,EACD;AAAA,EAEA,OAAO,yBAAyB,OAAkC;AACjE,WAAO;AAAA,MACN,UAAU;AAAA,MACV;AAAA,IACD;AAAA,EACD;AAAA,EAEA,kBAAkB,OAAc,WAA4B;AAE3D,YAAQ,MAAM,kCAAkC,OAAO,SAAS;AAGhE,SAAK,SAAS;AAAA,MACb;AAAA,MACA;AAAA,IACD,CAAC;AAGD,QAAI,KAAK,MAAM,SAAS;AACvB,WAAK,MAAM,QAAQ,OAAO,SAAS;AAAA,IACpC;AAAA,EACD;AAAA,EAEA,SAAoB;AACnB,QAAI,KAAK,MAAM,UAAU;AACxB,aAAO,oBAAC,SAAI,0CAA4B;AAAA,IACzC;AAEA,WAAO,KAAK,MAAM;AAAA,EACnB;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=ErrorBoundary.types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./ErrorBoundary";
2
+ export * from "./ErrorBoundary.types";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/ErrorBoundary/index.ts"],
4
+ "sourcesContent": ["export * from \"./ErrorBoundary\";\r\nexport * from \"./ErrorBoundary.types\";\r\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Layout/Layout.tsx"],
4
- "sourcesContent": ["import { Links, Meta, Scripts, ScrollRestoration } from \"react-router\";\n\nconst allowIndexing = process.env.NODE_ENV === \"production\";\n\ninterface LayoutProps {\n\tchildren: React.ReactNode;\n}\n\nexport function Layout({ children }: LayoutProps) {\n\treturn (\n\t\t<html lang=\"en\">\n\t\t\t<head>\n\t\t\t\t<Meta />\n\t\t\t\t<meta charSet=\"utf-8\" />\n\t\t\t\t<meta\n\t\t\t\t\tname=\"viewport\"\n\t\t\t\t\tcontent=\"width=device-width,initial-scale=1\"\n\t\t\t\t/>\n\t\t\t\t{allowIndexing && (\n\t\t\t\t\t<meta name=\"robots\" content=\"noindex, nofollow\" />\n\t\t\t\t)}\n\t\t\t\t<Links />\n\t\t\t</head>\n\t\t\t<body>\n\t\t\t\t{children}\n\t\t\t\t<ScrollRestoration />\n\t\t\t\t<Scripts />\n\t\t\t</body>\n\t\t</html>\n\t);\n}\n"],
5
- "mappings": "AAWG,SACC,KADD;AAXH,SAAS,OAAO,MAAM,SAAS,yBAAyB;AAExD,MAAM,gBAAgB,QAAQ,IAAI,aAAa;AAMxC,SAAS,OAAO,EAAE,SAAS,GAAgB;AACjD,SACC,qBAAC,UAAK,MAAK,MACV;AAAA,yBAAC,UACA;AAAA,0BAAC,QAAK;AAAA,MACN,oBAAC,UAAK,SAAQ,SAAQ;AAAA,MACtB;AAAA,QAAC;AAAA;AAAA,UACA,MAAK;AAAA,UACL,SAAQ;AAAA;AAAA,MACT;AAAA,MACC,iBACA,oBAAC,UAAK,MAAK,UAAS,SAAQ,qBAAoB;AAAA,MAEjD,oBAAC,SAAM;AAAA,OACR;AAAA,IACA,qBAAC,UACC;AAAA;AAAA,MACD,oBAAC,qBAAkB;AAAA,MACnB,oBAAC,WAAQ;AAAA,OACV;AAAA,KACD;AAEF;",
4
+ "sourcesContent": ["import { Links, Meta, Scripts, ScrollRestoration } from \"react-router\";\n\n// FIXME: This is not ideal as its client-level and we really need site-level\nconst allowIndexing = process.env.NODE_ENV === \"production\";\n\ninterface LayoutProps {\n\tchildren: React.ReactNode;\n}\n\nexport function Layout({ children }: LayoutProps) {\n\treturn (\n\t\t<html lang=\"en\">\n\t\t\t<head>\n\t\t\t\t<Meta />\n\t\t\t\t<meta charSet=\"utf-8\" />\n\t\t\t\t<meta\n\t\t\t\t\tname=\"viewport\"\n\t\t\t\t\tcontent=\"width=device-width,initial-scale=1\"\n\t\t\t\t/>\n\t\t\t\t{allowIndexing && (\n\t\t\t\t\t<meta name=\"robots\" content=\"noindex, nofollow\" />\n\t\t\t\t)}\n\t\t\t\t<Links />\n\t\t\t</head>\n\t\t\t<body>\n\t\t\t\t{children}\n\t\t\t\t<ScrollRestoration />\n\t\t\t\t<Scripts />\n\t\t\t</body>\n\t\t</html>\n\t);\n}\n"],
5
+ "mappings": "AAYG,SACC,KADD;AAZH,SAAS,OAAO,MAAM,SAAS,yBAAyB;AAGxD,MAAM,gBAAgB,QAAQ,IAAI,aAAa;AAMxC,SAAS,OAAO,EAAE,SAAS,GAAgB;AACjD,SACC,qBAAC,UAAK,MAAK,MACV;AAAA,yBAAC,UACA;AAAA,0BAAC,QAAK;AAAA,MACN,oBAAC,UAAK,SAAQ,SAAQ;AAAA,MACtB;AAAA,QAAC;AAAA;AAAA,UACA,MAAK;AAAA,UACL,SAAQ;AAAA;AAAA,MACT;AAAA,MACC,iBACA,oBAAC,UAAK,MAAK,UAAS,SAAQ,qBAAoB;AAAA,MAEjD,oBAAC,SAAM;AAAA,OACR;AAAA,IACA,qBAAC,UACC;AAAA;AAAA,MACD,oBAAC,qBAAkB;AAAA,MACnB,oBAAC,WAAQ;AAAA,OACV;AAAA,KACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -4,6 +4,8 @@ import { usePreview } from "../Preview/PreviewPageWrapper";
4
4
  import { SectionItemCiv } from "./SectionItemCiv";
5
5
  function SectionItem(civ) {
6
6
  const preview = usePreview();
7
+ console.log("SECTION ITEM");
8
+ return null;
7
9
  if (!preview) {
8
10
  return /* @__PURE__ */ jsx(SectionItemCiv, { ...civ });
9
11
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Section/SectionItem.tsx"],
4
- "sourcesContent": ["import type { CivProps } from \"../../types\";\r\nimport { PreviewCivWrapper } from \"../Preview\";\r\nimport { usePreview } from \"../Preview/PreviewPageWrapper\";\r\nimport { SectionItemCiv } from \"./SectionItemCiv\";\r\n\r\nexport function SectionItem(civ: CivProps) {\r\n\tconst preview = usePreview();\r\n\r\n\tif (!preview) {\r\n\t\treturn <SectionItemCiv {...civ} />;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<PreviewCivWrapper civid={civ.civid} {...preview}>\r\n\t\t\t<SectionItemCiv {...civ} />\r\n\t\t</PreviewCivWrapper>\r\n\t);\r\n}\r\n"],
5
- "mappings": "AASS;AART,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAExB,SAAS,YAAY,KAAe;AAC1C,QAAM,UAAU,WAAW;AAE3B,MAAI,CAAC,SAAS;AACb,WAAO,oBAAC,kBAAgB,GAAG,KAAK;AAAA,EACjC;AAEA,SACC,oBAAC,qBAAkB,OAAO,IAAI,OAAQ,GAAG,SACxC,8BAAC,kBAAgB,GAAG,KAAK,GAC1B;AAEF;",
4
+ "sourcesContent": ["import type { CivProps } from \"../../types\";\r\nimport { PreviewCivWrapper } from \"../Preview\";\r\nimport { usePreview } from \"../Preview/PreviewPageWrapper\";\r\nimport { SectionItemCiv } from \"./SectionItemCiv\";\r\n\r\nexport function SectionItem(civ: CivProps) {\r\n\tconst preview = usePreview();\r\n\tconsole.log(\"SECTION ITEM\");\r\n\treturn null;\r\n\tif (!preview) {\r\n\t\treturn <SectionItemCiv {...civ} />;\r\n\t}\r\n\r\n\treturn (\r\n\t\t<PreviewCivWrapper civid={civ.civid} {...preview}>\r\n\t\t\t<SectionItemCiv {...civ} />\r\n\t\t</PreviewCivWrapper>\r\n\t);\r\n}\r\n"],
5
+ "mappings": "AAUS;AATT,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAExB,SAAS,YAAY,KAAe;AAC1C,QAAM,UAAU,WAAW;AAC3B,UAAQ,IAAI,cAAc;AAC1B,SAAO;AACP,MAAI,CAAC,SAAS;AACb,WAAO,oBAAC,kBAAgB,GAAG,KAAK;AAAA,EACjC;AAEA,SACC,oBAAC,qBAAkB,OAAO,IAAI,OAAQ,GAAG,SACxC,8BAAC,kBAAgB,GAAG,KAAK,GAC1B;AAEF;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { useComponentMap } from "../../contexts";
3
3
  function SectionItemCiv(civ) {
4
4
  const map = useComponentMap();
5
+ return null;
5
6
  if (civ === void 0) {
6
7
  return /* @__PURE__ */ jsx(
7
8
  map.Error,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Section/SectionItemCiv.tsx"],
4
- "sourcesContent": ["import { useComponentMap } from \"../../contexts\";\r\nimport type { CivProps } from \"../../types\";\r\n\r\nexport function SectionItemCiv(civ: CivProps) {\r\n\tconst map = useComponentMap();\r\n\r\n\tif (civ === undefined) {\r\n\t\treturn (\r\n\t\t\t<map.Error\r\n\t\t\t\tstatus={500}\r\n\t\t\t\tmessage=\"Is the CMS API running? I bet it isn't \uD83D\uDE09\"\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n\r\n\tconst Component = map.civs[civ.component];\r\n\r\n\tif (Component === undefined) {\r\n\t\treturn <map.Unknown {...civ} />;\r\n\t}\r\n\r\n\treturn <Component {...civ} />;\r\n}\r\n"],
5
- "mappings": "AAQG;AARH,SAAS,uBAAuB;AAGzB,SAAS,eAAe,KAAe;AAC7C,QAAM,MAAM,gBAAgB;AAE5B,MAAI,QAAQ,QAAW;AACtB,WACC;AAAA,MAAC,IAAI;AAAA,MAAJ;AAAA,QACA,QAAQ;AAAA,QACR,SAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AAEA,QAAM,YAAY,IAAI,KAAK,IAAI,SAAS;AAExC,MAAI,cAAc,QAAW;AAC5B,WAAO,oBAAC,IAAI,SAAJ,EAAa,GAAG,KAAK;AAAA,EAC9B;AAEA,SAAO,oBAAC,aAAW,GAAG,KAAK;AAC5B;",
4
+ "sourcesContent": ["import { useComponentMap } from \"../../contexts\";\r\nimport type { CivProps } from \"../../types\";\r\n\r\nexport function SectionItemCiv(civ: CivProps) {\r\n\tconst map = useComponentMap();\r\n\r\n\treturn null;\r\n\r\n\tif (civ === undefined) {\r\n\t\treturn (\r\n\t\t\t<map.Error\r\n\t\t\t\tstatus={500}\r\n\t\t\t\tmessage=\"Is the CMS API running? I bet it isn't \uD83D\uDE09\"\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n\r\n\tconst Component = map.civs[civ.component];\r\n\r\n\tif (Component === undefined) {\r\n\t\treturn <map.Unknown {...civ} />;\r\n\t}\r\n\r\n\treturn <Component {...civ} />;\r\n}\r\n"],
5
+ "mappings": "AAUG;AAVH,SAAS,uBAAuB;AAGzB,SAAS,eAAe,KAAe;AAC7C,QAAM,MAAM,gBAAgB;AAE5B,SAAO;AAEP,MAAI,QAAQ,QAAW;AACtB,WACC;AAAA,MAAC,IAAI;AAAA,MAAJ;AAAA,QACA,QAAQ;AAAA,QACR,SAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AAEA,QAAM,YAAY,IAAI,KAAK,IAAI,SAAS;AAExC,MAAI,cAAc,QAAW;AAC5B,WAAO,oBAAC,IAAI,SAAJ,EAAa,GAAG,KAAK;AAAA,EAC9B;AAEA,SAAO,oBAAC,aAAW,GAAG,KAAK;AAC5B;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,6 @@
1
1
  export * from "./App";
2
2
  export * from "./Error";
3
+ export * from "./ErrorBoundary";
3
4
  export * from "./Layout";
4
5
  export * from "./Preview";
5
6
  export * from "./Section";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/index.ts"],
4
- "sourcesContent": ["export * from \"./App\";\r\nexport * from \"./Error\";\r\nexport * from \"./Layout\";\r\nexport * from \"./Preview\";\r\nexport * from \"./Section\";\r\nexport * from \"./Unknown\";\r\nexport * from \"./Preview\";\r\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from \"./App\";\r\nexport * from \"./Error\";\r\nexport * from \"./ErrorBoundary\";\r\nexport * from \"./Layout\";\r\nexport * from \"./Preview\";\r\nexport * from \"./Section\";\r\nexport * from \"./Unknown\";\r\nexport * from \"./Preview\";\r\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
1
  export interface ErrorProps {
2
- status: number;
2
+ status?: number;
3
3
  message: string;
4
4
  }
@@ -0,0 +1,9 @@
1
+ import { Component } from "react";
2
+ import type { ReactNode, ErrorInfo } from "react";
3
+ import type { ErrorBoundaryProps, ErrorBoundaryState } from "./ErrorBoundary.types";
4
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
5
+ constructor(props: ErrorBoundaryProps);
6
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
7
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
8
+ render(): ReactNode;
9
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactNode, ErrorInfo } from "react";
2
+ export interface ErrorBoundaryState {
3
+ hasError: boolean;
4
+ error?: Error;
5
+ errorInfo?: ErrorInfo;
6
+ }
7
+ export interface ErrorBoundaryProps {
8
+ children: ReactNode;
9
+ fallback?: ReactNode;
10
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./ErrorBoundary";
2
+ export * from "./ErrorBoundary.types";
@@ -1,2 +1,2 @@
1
1
  import type { CivProps } from "../../types";
2
- export declare function SectionItem(civ: CivProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function SectionItem(civ: CivProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,2 +1,2 @@
1
1
  import type { CivProps } from "../../types";
2
- export declare function SectionItemCiv(civ: CivProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function SectionItemCiv(civ: CivProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,5 +1,6 @@
1
1
  export * from "./App";
2
2
  export * from "./Error";
3
+ export * from "./ErrorBoundary";
3
4
  export * from "./Layout";
4
5
  export * from "./Preview";
5
6
  export * from "./Section";
@@ -3,7 +3,7 @@ const previewPath = "/includes/plugins/nav/preview_civs/";
3
3
  async function getPageContent(req) {
4
4
  const incomingUrl = new URL(req.url, "http://placeholder.com");
5
5
  const cmsUrl = getCmsUrl(incomingUrl.host);
6
- if (/\.[^/]+$/.test(incomingUrl.pathname)) {
6
+ if (!incomingUrl.pathname.endsWith("/") || /\.[^/]+$/.test(incomingUrl.pathname)) {
7
7
  cmsUrl.pathname = incomingUrl.pathname + "/content.json";
8
8
  } else {
9
9
  cmsUrl.pathname = incomingUrl.pathname + "content.json";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/getPageContent.ts"],
4
- "sourcesContent": ["import type { CivProps, PageData } from \"../types\";\r\nimport { getCmsUrl } from \"./getCmsUrl\";\r\n\r\nexport type { PageData };\r\n\r\nconst previewPath = \"/includes/plugins/nav/preview_civs/\";\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tconst incomingUrl = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(incomingUrl.host);\r\n\r\n\tif (/\\.[^/]+$/.test(incomingUrl.pathname)) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tlet body: URLSearchParams | undefined = undefined;\r\n\r\n\t\t/**\r\n\t\t * If this is the live preview page, we need to append the search params from the incoming URL\r\n\t\t * and send the CIVs along with the request.\r\n\t\t */\r\n\t\tif (req.method === \"POST\" && incomingUrl.pathname === previewPath) {\r\n\t\t\tincomingUrl.searchParams.forEach((val, key) => {\r\n\t\t\t\tcmsUrl.searchParams.set(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tconst formData = await req.formData();\r\n\t\t\tconst civs = formData.get(\"headless_civs\");\r\n\t\t\tconst data = JSON.parse(atob(civs));\r\n\r\n\t\t\treturn data;\r\n\t\t}\r\n\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst fetchParams: RequestInit = {\r\n\t\t\tmethod,\r\n\t\t\theaders,\r\n\t\t\tbody,\r\n\t\t};\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n}\r\n"],
5
- "mappings": "AACA,SAAS,iBAAiB;AAI1B,MAAM,cAAc;AAEpB,eAAsB,eACrB,KAC8B;AAC9B,QAAM,cAAc,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC7D,QAAM,SAAS,UAAU,YAAY,IAAI;AAEzC,MAAI,WAAW,KAAK,YAAY,QAAQ,GAAG;AAE1C,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C,OAAO;AAEN,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,IACnB,mBACC,IAAI,QAAQ,IAAI,WAAW,KAC3B,IAAI,QAAQ,IAAI,kBAAkB,KAClC;AAAA,IACD,cAAc,IAAI,QAAQ,IAAI,YAAY,KAAK;AAAA,EAChD;AAEA,MAAI;AACH,QAAI,OAAoC;AAMxC,QAAI,IAAI,WAAW,UAAU,YAAY,aAAa,aAAa;AAClE,kBAAY,aAAa,QAAQ,CAAC,KAAK,QAAQ;AAC9C,eAAO,aAAa,IAAI,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,YAAM,WAAW,MAAM,IAAI,SAAS;AACpC,YAAM,OAAO,SAAS,IAAI,eAAe;AACzC,YAAM,OAAO,KAAK,MAAM,KAAK,IAAI,CAAC;AAElC,aAAO;AAAA,IACR;AAEA,UAAM,MAAM,OAAO,SAAS;AAC5B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,cAA2B;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAEA,YAAQ,IAAI,gCAAgC;AAAA,MAC3C;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAED,UAAM,SAAS,MAAM,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;AACrE,WAAO;AAAA,EACR,SAAS,KAAc;AACtB,UAAM,SACJ,KAA4C,UAAU,UACvD;AACD,UAAM,UACJ,KAAgD,UAC9C,cAAc;AAClB,UAAM,IAAI,MAAM,UAAU,MAAM,KAAK,OAAO,EAAE;AAAA,EAC/C;AACD;",
4
+ "sourcesContent": ["import type { CivProps, PageData } from \"../types\";\r\nimport { getCmsUrl } from \"./getCmsUrl\";\r\n\r\nexport type { PageData };\r\n\r\nconst previewPath = \"/includes/plugins/nav/preview_civs/\";\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tconst incomingUrl = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(incomingUrl.host);\r\n\r\n\tif (\r\n\t\t!incomingUrl.pathname.endsWith(\"/\") ||\r\n\t\t/\\.[^/]+$/.test(incomingUrl.pathname)\r\n\t) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = incomingUrl.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tlet body: URLSearchParams | undefined = undefined;\r\n\r\n\t\t/**\r\n\t\t * If this is the live preview page, we need to append the search params from the incoming URL\r\n\t\t * and send the CIVs along with the request.\r\n\t\t */\r\n\t\tif (req.method === \"POST\" && incomingUrl.pathname === previewPath) {\r\n\t\t\tincomingUrl.searchParams.forEach((val, key) => {\r\n\t\t\t\tcmsUrl.searchParams.set(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tconst formData = await req.formData();\r\n\t\t\tconst civs = formData.get(\"headless_civs\");\r\n\t\t\tconst data = JSON.parse(atob(civs));\r\n\r\n\t\t\treturn data;\r\n\t\t}\r\n\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst fetchParams: RequestInit = {\r\n\t\t\tmethod,\r\n\t\t\theaders,\r\n\t\t\tbody,\r\n\t\t};\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n}\r\n"],
5
+ "mappings": "AACA,SAAS,iBAAiB;AAI1B,MAAM,cAAc;AAEpB,eAAsB,eACrB,KAC8B;AAC9B,QAAM,cAAc,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC7D,QAAM,SAAS,UAAU,YAAY,IAAI;AAEzC,MACC,CAAC,YAAY,SAAS,SAAS,GAAG,KAClC,WAAW,KAAK,YAAY,QAAQ,GACnC;AAED,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C,OAAO;AAEN,WAAO,WAAW,YAAY,WAAW;AAAA,EAC1C;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,IACnB,mBACC,IAAI,QAAQ,IAAI,WAAW,KAC3B,IAAI,QAAQ,IAAI,kBAAkB,KAClC;AAAA,IACD,cAAc,IAAI,QAAQ,IAAI,YAAY,KAAK;AAAA,EAChD;AAEA,MAAI;AACH,QAAI,OAAoC;AAMxC,QAAI,IAAI,WAAW,UAAU,YAAY,aAAa,aAAa;AAClE,kBAAY,aAAa,QAAQ,CAAC,KAAK,QAAQ;AAC9C,eAAO,aAAa,IAAI,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,YAAM,WAAW,MAAM,IAAI,SAAS;AACpC,YAAM,OAAO,SAAS,IAAI,eAAe;AACzC,YAAM,OAAO,KAAK,MAAM,KAAK,IAAI,CAAC;AAElC,aAAO;AAAA,IACR;AAEA,UAAM,MAAM,OAAO,SAAS;AAC5B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,cAA2B;AAAA,MAChC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAEA,YAAQ,IAAI,gCAAgC;AAAA,MAC3C;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAED,UAAM,SAAS,MAAM,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;AACrE,WAAO;AAAA,EACR,SAAS,KAAc;AACtB,UAAM,SACJ,KAA4C,UAAU,UACvD;AACD,UAAM,UACJ,KAAgD,UAC9C,cAAc;AAClB,UAAM,IAAI,MAAM,UAAU,MAAM,KAAK,OAAO,EAAE;AAAA,EAC/C;AACD;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleview/cms-foundation",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Provides helper types and components to assist when working with Granicus CMS Reactor.",
5
5
  "packageManager": "yarn@4.6.0+sha224.acd0786f07ffc6c933940eb65fc1d627131ddf5455bddcc295dc90fd",
6
6
  "scripts": {