@websline/cms-view-utils 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/cms-view-utils",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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;
@@ -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 };
@@ -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";
@@ -32,7 +32,7 @@ const createRobotsHandler =
32
32
  status: 200,
33
33
  headers: {
34
34
  "Content-Type": "text/plain; charset=utf-8",
35
- "Cache-Control": "public, max-age=3600, s-maxage=3600",
35
+ "Cache-Control": "no-store",
36
36
  },
37
37
  });
38
38
  };
@@ -1,6 +1,6 @@
1
- import { fetchSitemap } from "./fetchSitemap.js";
1
+ import { fetchSitemap } from "../cms/fetchSitemap.js";
2
2
  import { buildSitemapXml } from "./sitemapXml.js";
3
- import { HttpError } from "./errors.js";
3
+ import { HttpError } from "../shared/errors.js";
4
4
 
5
5
  const resolveSiteUrl = (request) => {
6
6
  const url = new URL(request.url);
@@ -20,7 +20,7 @@ const createSitemapHandler =
20
20
  status: 200,
21
21
  headers: {
22
22
  "Content-Type": "application/xml; charset=utf-8",
23
- "Cache-Control": "public, max-age=3600, s-maxage=3600",
23
+ "Cache-Control": "no-store",
24
24
  },
25
25
  });
26
26
  } catch (error) {
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";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes