@plentymarkets/shop-core 1.21.14 → 1.22.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.21.14",
4
+ "version": "1.22.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -113,6 +113,7 @@ export type ShopCoreConfig = ${genInlineTypeImport(projectRootResolver.resolve("
113
113
  filePath: buildDirectoryResolver.resolve("ModuleComponentRendering.vue")
114
114
  });
115
115
  addPlugin(resolver.resolve("./runtime/plugins/sdk"));
116
+ addPlugin(resolver.resolve("./runtime/plugins/cache-control.server.ts"));
116
117
  addImports({
117
118
  name: "useSdk",
118
119
  as: "useSdk",
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Server-only plugin that sets Cache-Control response headers per request.
3
+ */
4
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
5
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { defineNuxtPlugin, useCookie, useRequestEvent, useRuntimeConfig } from "#imports";
2
+ import { setResponseHeader } from "h3";
3
+ import { getCacheControlMeta } from "../utils/cacheHelper.js";
4
+ import { isServer } from "../utils/runtime.js";
5
+ export default defineNuxtPlugin({
6
+ name: "shop-core:cache-control",
7
+ enforce: "post",
8
+ setup(nuxtApp) {
9
+ if (!isServer()) return;
10
+ const event = useRequestEvent();
11
+ if (!event) return;
12
+ const runtimeConfig = useRuntimeConfig();
13
+ const pwaCookie = useCookie("pwa");
14
+ const cacheControlValue = getCacheControlMeta(nuxtApp.$router);
15
+ const isPreview = !!pwaCookie.value || !!runtimeConfig.public.isPreview;
16
+ if (cacheControlValue && !isPreview) {
17
+ setResponseHeader(event, "Cache-Control", cacheControlValue);
18
+ } else {
19
+ setResponseHeader(event, "Cache-Control", "no-cache, no-store, must-revalidate");
20
+ setResponseHeader(event, "Pragma", "no-cache");
21
+ setResponseHeader(event, "Expires", "0");
22
+ }
23
+ }
24
+ });
@@ -6,6 +6,7 @@ import { createSdkLogger } from "../utils/sdk/sdk.logger.js";
6
6
  import { createSdkRequestHeaders, getI18nLocale } from "../utils/sdk/sdk.request.headers.js";
7
7
  import { handleSdkResponse } from "../utils/sdk/sdk.response.headers.js";
8
8
  import { setSSRMetrics } from "../utils/ssrMetricsHelper.js";
9
+ import { getCacheControlMeta } from "../utils/cacheHelper.js";
9
10
  export default defineNuxtPlugin((nuxtApp) => {
10
11
  const runtimeConfig = useRuntimeConfig();
11
12
  const moduleConfig = runtimeConfig.public.shopCore;
@@ -17,7 +18,7 @@ export default defineNuxtPlugin((nuxtApp) => {
17
18
  );
18
19
  const noCache = runtimeConfig.public.noCache || nuxtApp.$router.currentRoute.value.query?.noCache?.toString() || "";
19
20
  const referrerId = nuxtApp.$router.currentRoute.value.query?.ReferrerID?.toString() ?? "";
20
- const shouldSkipCookiesSSR = nuxtApp.$router.currentRoute.value.meta?.skipCookiesSSR ?? false;
21
+ const isCacheable = getCacheControlMeta(nuxtApp.$router);
21
22
  const { token: csrfToken } = useCsrfToken();
22
23
  const ssrCookie = ref([]);
23
24
  logger.log("\u{1F680} initializing SDK plugin");
@@ -35,7 +36,7 @@ export default defineNuxtPlugin((nuxtApp) => {
35
36
  noCache,
36
37
  requestHeaders,
37
38
  ssrCookie: ssrCookie.value,
38
- shouldSkipCookiesSSR
39
+ shouldSkipCookiesSSR: !!isCacheable
39
40
  });
40
41
  logger.verbose(`\u{1F4EC} prepared headers: `, JSON.stringify(headers));
41
42
  return {
@@ -7,8 +7,12 @@ declare module '#app' {
7
7
  };
8
8
  }
9
9
  interface PageMeta {
10
- /** When true, the x-without-session-cookie header is sent for all SDK requests on this page during SSR. */
11
- skipCookiesSSR?: boolean;
10
+ /** Cache-Control header value to set for this page, e.g. { type: 'public', maxAge: 30, staleWhileRevalidate: 900 } */
11
+ cacheControl?: {
12
+ maxAge: number;
13
+ staleWhileRevalidate: number;
14
+ type: 'public' | 'private'
15
+ };
12
16
  }
13
17
  }
14
18
 
@@ -0,0 +1 @@
1
+ export declare const getCacheControlMeta: (route: any) => string | false;
@@ -0,0 +1,7 @@
1
+ export const getCacheControlMeta = (route) => {
2
+ const cacheControl = route?.currentRoute?.value?.meta?.cacheControl;
3
+ if (!cacheControl || typeof cacheControl !== "object") return false;
4
+ const { type, maxAge, staleWhileRevalidate } = cacheControl;
5
+ if (typeof type !== "string" || typeof maxAge !== "number" || typeof staleWhileRevalidate !== "number") return false;
6
+ return `${type}, max-age=${maxAge}, stale-while-revalidate=${staleWhileRevalidate}`;
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.21.14",
3
+ "version": "1.22.0",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",