@plentymarkets/shop-core 1.12.1 → 1.13.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.12.1",
4
+ "version": "1.13.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Updates the SSR cookie value based on the setCookie payload
3
- * @param ssrCookie - The current SSR cookie state object with a value property
4
- * @param setCookie - The setCookie payload (string or array of strings)
2
+ * Updates the SSR cookie value by merging new `Set-Cookie` headers.
3
+ * @param ssrCookie The reactive reference to the current SSR cookie string.
4
+ * @param newCookie The new `Set-Cookie` header string or an array of them.
5
5
  */
6
6
  export declare const updateSsrCookie: (ssrCookie: {
7
7
  value: string;
8
- }, setCookie: string | string[]) => void;
8
+ }, newCookie: string | string[]) => void;
@@ -1,15 +1,19 @@
1
- export const updateSsrCookie = (ssrCookie, setCookie) => {
2
- ssrCookie.value = "";
3
- if (Array.isArray(setCookie)) {
4
- setCookie.forEach((cookieString) => {
5
- const cookiePair = cookieString.split(";")[0].split("=");
6
- if (cookiePair[0] && cookiePair[1]) {
7
- ssrCookie.value += (ssrCookie.value ? "; " : "") + `${cookiePair[0].trim()}=${cookiePair[1].trim()}`;
1
+ import * as cookie from "cookie";
2
+ export const updateSsrCookie = (ssrCookie, newCookie) => {
3
+ const cookieJar = cookie.parse(ssrCookie.value || "");
4
+ const newCookies = Array.isArray(newCookie) ? newCookie : [newCookie];
5
+ newCookies.forEach((cookieString) => {
6
+ const [nameValue] = cookieString.split(";");
7
+ const [name, ...value] = nameValue?.split("=") ?? [];
8
+ const trimmedName = name?.trim();
9
+ if (trimmedName) {
10
+ const cookieValue = value.join("=").trim();
11
+ if (cookieValue) {
12
+ cookieJar[trimmedName] = cookieValue;
13
+ } else {
14
+ delete cookieJar[trimmedName];
8
15
  }
9
- });
10
- } else {
11
- if (setCookie.split(";")[0]) {
12
- ssrCookie.value = setCookie.split(";")[0]?.trim() ?? "";
13
16
  }
14
- }
17
+ });
18
+ ssrCookie.value = Object.entries(cookieJar).map(([name, value]) => `${name}=${value}`).join("; ");
15
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.12.1",
3
+ "version": "1.13.1",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,6 +43,7 @@
43
43
  "dependencies": {
44
44
  "@plentymarkets/shop-api": "^0.140.0",
45
45
  "@vue-storefront/sdk": "^3.4.1",
46
+ "cookie": "^1.0.2",
46
47
  "js-sha256": "^0.11.0",
47
48
  "resolve": "^1.22.10"
48
49
  },