@websline/cms-view-utils 1.1.1 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/cms-view-utils",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -10,7 +10,6 @@
10
10
  ".": "./src/index.js",
11
11
  "./server": "./src/server.js",
12
12
  "./components/*": "./src/components/*",
13
- "./utils/*": "./src/utils/*",
14
13
  "./preview-bridge": "./dist/previewBridge.global.js",
15
14
  "./edit-scroll": "./dist/editScroll.global.js",
16
15
  "./dist/*": "./dist/*"
@@ -0,0 +1,20 @@
1
+ const fetchSimilarPackages = async ({ excludeId, limit, locale }) => {
2
+ const params = new URLSearchParams();
3
+
4
+ if (excludeId != null && excludeId !== "") {
5
+ params.set("excludeId", excludeId);
6
+ }
7
+
8
+ if (limit != null) {
9
+ params.set("limit", limit);
10
+ }
11
+
12
+ const query = params.toString();
13
+ const url = `/api/cms/api/public/abm-packages/${locale}${query ? `?${query}` : ""}`;
14
+
15
+ const response = await fetch(url, { method: "GET" });
16
+
17
+ return response.json();
18
+ };
19
+
20
+ export { fetchSimilarPackages };
@@ -0,0 +1,20 @@
1
+ const fetchSimilarRooms = async ({ excludeId, limit, locale }) => {
2
+ const params = new URLSearchParams();
3
+
4
+ if (excludeId != null && excludeId !== "") {
5
+ params.set("excludeId", excludeId);
6
+ }
7
+
8
+ if (limit != null) {
9
+ params.set("limit", limit);
10
+ }
11
+
12
+ const query = params.toString();
13
+ const url = `/api/cms/api/public/abm-rooms/${locale}${query ? `?${query}` : ""}`;
14
+
15
+ const response = await fetch(url, { method: "GET" });
16
+
17
+ return response.json();
18
+ };
19
+
20
+ export { fetchSimilarRooms };
@@ -1,5 +1,5 @@
1
1
  import jwt from "jsonwebtoken";
2
- import { HttpError } from "./errors.js";
2
+ import { HttpError } from "../shared/errors.js";
3
3
 
4
4
  const resolveDraftUuidFromToken = (editorToken) => {
5
5
  if (!editorToken) return undefined;
@@ -1,7 +1,7 @@
1
1
  import { resolveDraftUuidFromToken } from "./editorToken.js";
2
2
  import { buildCmsPageUrl } from "./urlResolver.js";
3
3
  import { buildCmsHeaders } from "./headers.js";
4
- import { HttpError } from "./errors.js";
4
+ import { HttpError } from "../shared/errors.js";
5
5
 
6
6
  const fetchPage = async (context) => {
7
7
  let { path = "" } = context.params;
@@ -0,0 +1,20 @@
1
+ import { buildCmsSiteConfigUrl } from "./urlResolver.js";
2
+ import { buildCmsHeaders } from "./headers.js";
3
+ import { HttpError } from "../shared/errors.js";
4
+
5
+ const fetchSiteConfig = async (request) => {
6
+ const cmsUrl = buildCmsSiteConfigUrl();
7
+
8
+ const response = await fetch(cmsUrl, {
9
+ method: "GET",
10
+ headers: buildCmsHeaders(request),
11
+ });
12
+
13
+ if (!response.ok) {
14
+ throw new HttpError(response.status, "CMS Error");
15
+ }
16
+
17
+ return response.json();
18
+ };
19
+
20
+ export { fetchSiteConfig };
@@ -1,6 +1,6 @@
1
1
  import { buildCmsSitemapUrl } from "./urlResolver.js";
2
2
  import { buildCmsHeaders } from "./headers.js";
3
- import { HttpError } from "./errors.js";
3
+ import { HttpError } from "../shared/errors.js";
4
4
 
5
5
  const fetchSitemap = async (request) => {
6
6
  const cmsUrl = buildCmsSitemapUrl();
@@ -0,0 +1,39 @@
1
+ import { buildCmsHeaders } from "./headers.js";
2
+ import { HttpError } from "../shared/errors.js";
3
+
4
+ const proxyToCms = async (context) => {
5
+ const cmsBase = import.meta.env.CMS_URL;
6
+
7
+ if (!cmsBase) {
8
+ throw new HttpError(500, "CMS proxy not configured");
9
+ }
10
+
11
+ const { path = "" } = context.params;
12
+ const { request } = context;
13
+ const url = new URL(request.url);
14
+ const target = `${cmsBase}/${path}${url.search}`;
15
+
16
+ const response = await fetch(target, {
17
+ method: request.method,
18
+ headers: buildCmsHeaders(request),
19
+ });
20
+
21
+ if (!response.ok) {
22
+ throw new HttpError(response.status, "CMS Error");
23
+ }
24
+
25
+ const data = await response.text();
26
+
27
+ return new Response(data, {
28
+ status: response.status,
29
+ headers: {
30
+ "content-type": response.headers.get("content-type") ?? "application/json",
31
+ },
32
+ });
33
+ };
34
+
35
+ const createCmsProxyHandler = () => {
36
+ return (context) => proxyToCms(context);
37
+ };
38
+
39
+ export { proxyToCms, createCmsProxyHandler };
@@ -0,0 +1,21 @@
1
+ const CMS_BASE_URL = import.meta.env.CMS_URL;
2
+
3
+ const buildCmsPageUrl = ({ draftUuid, path }) => {
4
+ if (draftUuid) {
5
+ return `${CMS_BASE_URL}/api/public/pages/preview/${draftUuid}`;
6
+ }
7
+
8
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
9
+
10
+ return `${CMS_BASE_URL}/api/public/pages${normalizedPath}`;
11
+ };
12
+
13
+ const buildCmsSiteConfigUrl = () => {
14
+ return `${CMS_BASE_URL}/api/public/site-config`;
15
+ };
16
+
17
+ const buildCmsSitemapUrl = () => {
18
+ return `${CMS_BASE_URL}/api/public/sitemap`;
19
+ };
20
+
21
+ export { buildCmsPageUrl, buildCmsSiteConfigUrl, buildCmsSitemapUrl };
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { twMerge as tw } from "tailwind-merge";
3
- import { EVENTS, notifyCMS } from "../utils/notify.js";
3
+ import { EVENTS, notifyCMS } from "../editor/notify.js";
4
4
 
5
5
  let {
6
6
  class: className,
@@ -1,6 +1,6 @@
1
1
  <script>
2
- import { EVENTS, notifyCMS } from "../utils/notify.js";
3
- import { CMS_ACTIONS } from "../utils/cmsActions.js";
2
+ import { EVENTS, notifyCMS } from "../editor/notify.js";
3
+ import { CMS_ACTIONS } from "../editor/cmsActions.js";
4
4
  import Text from "./skeleton/Text.svelte";
5
5
  import Image from "./skeleton/Image.svelte";
6
6
  import Grid from "./skeleton/Grid.svelte";
@@ -0,0 +1,45 @@
1
+ import { fetchSiteConfig } from "../cms/fetchSiteConfig.js";
2
+ import { HttpError } from "../shared/errors.js";
3
+
4
+ const buildRobotsTxt = ({ siteUrl, allowIndexing }) => {
5
+ if (!allowIndexing) {
6
+ return `User-agent: *
7
+ Disallow: /
8
+ `;
9
+ }
10
+
11
+ return `User-agent: *
12
+ Allow: /
13
+
14
+ Sitemap: ${siteUrl}/sitemap.xml
15
+ `;
16
+ };
17
+
18
+ const createRobotsHandler =
19
+ () =>
20
+ async ({ request }) => {
21
+ try {
22
+ const siteConfig = await fetchSiteConfig(request);
23
+ const siteUrl = siteConfig?.url;
24
+ const allowIndexing = siteConfig?.mode === "PRODUCTION";
25
+
26
+ const body = buildRobotsTxt({ siteUrl, allowIndexing });
27
+
28
+ return new Response(body, {
29
+ status: 200,
30
+ headers: {
31
+ "Content-Type": "text/plain; charset=utf-8",
32
+ "Cache-Control": "no-store",
33
+ },
34
+ });
35
+ } catch (error) {
36
+ if (error instanceof HttpError) {
37
+ return new Response(`Robots error: ${error.message}`, {
38
+ status: error.status,
39
+ });
40
+ }
41
+ throw error;
42
+ }
43
+ };
44
+
45
+ export { createRobotsHandler };
@@ -1,20 +1,18 @@
1
- import { fetchSitemap } from "./fetchSitemap.js";
1
+ import { fetchSitemap } from "../cms/fetchSitemap.js";
2
+ import { fetchSiteConfig } from "../cms/fetchSiteConfig.js";
2
3
  import { buildSitemapXml } from "./sitemapXml.js";
3
- import { HttpError } from "./errors.js";
4
-
5
- const resolveSiteUrl = (request) => {
6
- const url = new URL(request.url);
7
- return `${url.protocol}//${url.host}`;
8
- };
4
+ import { HttpError } from "../shared/errors.js";
9
5
 
10
6
  const createSitemapHandler =
11
7
  () =>
12
8
  async ({ request }) => {
13
- const siteUrl = resolveSiteUrl(request);
14
-
15
9
  try {
16
- const entries = await fetchSitemap(request);
17
- const xml = buildSitemapXml(entries, siteUrl);
10
+ const [entries, siteConfig] = await Promise.all([
11
+ fetchSitemap(request),
12
+ fetchSiteConfig(request),
13
+ ]);
14
+
15
+ const xml = buildSitemapXml(entries, siteConfig?.url);
18
16
 
19
17
  return new Response(xml, {
20
18
  status: 200,
package/src/index.js CHANGED
@@ -1,4 +1,6 @@
1
- export { isValid } from "./utils/blockValidation.js";
1
+ export { isValid } from "./editor/blockValidation.js";
2
+ export { fetchSimilarRooms } from "./client/fetchSimilarRooms.js";
3
+ export { fetchSimilarPackages } from "./client/fetchSimilarPackages.js";
2
4
 
3
5
  export { default as AddBlockPlaceholder } from "./components/AddBlockPlaceholder.svelte";
4
6
  export { default as BlockWrapper } from "./components/BlockWrapper.svelte";
@@ -1,4 +1,4 @@
1
- import { fetchPage } from "../utils/fetchPage.js";
1
+ import { fetchPage } from "../cms/fetchPage.js";
2
2
 
3
3
  /**
4
4
  * Returns the CMS page fetch function for use in createCmsMiddleware.
package/src/server.js CHANGED
@@ -1,8 +1,9 @@
1
- export { fetchPage } from "./utils/fetchPage.js";
1
+ export { fetchPage } from "./cms/fetchPage.js";
2
2
 
3
3
  export { createCmsMiddleware } from "./middleware/createCmsMiddleware.js";
4
4
  export { withRequestFilter } from "./middleware/withRequestFilter.js";
5
5
  export { withCmsFetch } from "./middleware/withCmsFetch.js";
6
6
  export { withParaglide } from "./middleware/withParaglide.js";
7
- export { createSitemapHandler } from "./utils/sitemapHandler.js";
8
- export { createRobotsHandler } from "./utils/robotsHandler.js";
7
+ export { createSitemapHandler } from "./handlers/sitemapHandler.js";
8
+ export { createRobotsHandler } from "./handlers/robotsHandler.js";
9
+ export { createCmsProxyHandler } from "./cms/proxyToCms.js";
@@ -1,40 +0,0 @@
1
- const buildRobotsTxt = ({ siteUrl, allowIndexing }) => {
2
- if (!allowIndexing) {
3
- return `User-agent: *
4
- Disallow: /
5
- `;
6
- }
7
-
8
- return `User-agent: *
9
- Allow: /
10
-
11
- Sitemap: ${siteUrl}/sitemap.xml
12
- `;
13
- };
14
-
15
- const resolveSiteUrl = (request) => {
16
- const url = new URL(request.url);
17
- return `${url.protocol}//${url.host}`;
18
- };
19
-
20
- // TODO: replace with CMS setting once available
21
- const resolveAllowIndexing = () => true;
22
-
23
- const createRobotsHandler =
24
- () =>
25
- async ({ request }) => {
26
- const siteUrl = resolveSiteUrl(request);
27
- const allowIndexing = resolveAllowIndexing();
28
-
29
- const body = buildRobotsTxt({ siteUrl, allowIndexing });
30
-
31
- return new Response(body, {
32
- status: 200,
33
- headers: {
34
- "Content-Type": "text/plain; charset=utf-8",
35
- "Cache-Control": "no-store",
36
- },
37
- });
38
- };
39
-
40
- export { createRobotsHandler };
@@ -1,19 +0,0 @@
1
- const buildCmsPageUrl = ({ draftUuid, path }) => {
2
- const base = import.meta.env.CMS_URL;
3
-
4
- if (draftUuid) {
5
- return `${base}/api/public/pages/preview/${draftUuid}`;
6
- }
7
-
8
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
9
-
10
- return `${base}/api/public/pages${normalizedPath}`;
11
- };
12
-
13
- const buildCmsSitemapUrl = () => {
14
- const base = import.meta.env.CMS_URL;
15
-
16
- return `${base}/api/public/sitemap`;
17
- };
18
-
19
- export { buildCmsPageUrl, buildCmsSitemapUrl };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes