@plentymarkets/shop-core 1.9.9 → 1.10.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
|
@@ -20,6 +20,9 @@ export const httpClient = async (url, params, config) => {
|
|
|
20
20
|
if (response.headers["x-csrf-token"] && response.data) {
|
|
21
21
|
response.data.csrfToken = response.headers["x-csrf-token"];
|
|
22
22
|
}
|
|
23
|
+
if (import.meta.server && response.headers["set-cookie"]) {
|
|
24
|
+
response.data.setCookie = response.headers["set-cookie"];
|
|
25
|
+
}
|
|
23
26
|
return response.data;
|
|
24
27
|
} catch (error) {
|
|
25
28
|
handleHttpError(error);
|
|
@@ -1,46 +1,84 @@
|
|
|
1
1
|
import { initSDK, buildModule, middlewareModule } from "@vue-storefront/sdk";
|
|
2
2
|
import { httpClient } from "./sdk.client.js";
|
|
3
|
-
import { useCookie, useNuxtApp, useRequestHeaders, useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useCookie, useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
4
4
|
import { useCsrfToken } from "./useCsrfToken.js";
|
|
5
5
|
export const useSdk = () => {
|
|
6
|
+
const nuxtApp = useNuxtApp();
|
|
7
|
+
if (nuxtApp._sdk) {
|
|
8
|
+
return nuxtApp._sdk;
|
|
9
|
+
}
|
|
6
10
|
const runtimeConfig = useRuntimeConfig();
|
|
7
11
|
const moduleConfig = runtimeConfig.public.shopCore;
|
|
8
12
|
const { $router, $i18n } = useNuxtApp();
|
|
9
|
-
const locale = $i18n.locale.value;
|
|
10
|
-
const referrerId = $router.currentRoute.value.query?.ReferrerID?.toString() ?? "";
|
|
11
|
-
const noCache = runtimeConfig.public.noCache || $router.currentRoute.value.query?.noCache?.toString() || "";
|
|
12
|
-
const configId = runtimeConfig.public.configId?.toString();
|
|
13
|
-
const pwaHashCookie = useCookie("pwa");
|
|
14
13
|
const { token } = useCsrfToken();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const requestHeaders = useRequestHeaders(["cookie"]);
|
|
15
|
+
const ssrCookie = useState("ssr-cookie", () => requestHeaders.cookie ?? "");
|
|
16
|
+
const getFreshHeaders = () => {
|
|
17
|
+
const locale = $i18n.locale.value;
|
|
18
|
+
const referrerId = $router.currentRoute.value.query?.ReferrerID?.toString() ?? "";
|
|
19
|
+
const noCache = runtimeConfig.public.noCache || $router.currentRoute.value.query?.noCache?.toString() || "";
|
|
20
|
+
const configId = runtimeConfig.public.configId?.toString();
|
|
21
|
+
const pwaHashCookie = useCookie("pwa");
|
|
22
|
+
return {
|
|
23
|
+
...configId && { "x-config-id": configId },
|
|
24
|
+
...token.value && { "x-csrf-token": token.value },
|
|
25
|
+
...pwaHashCookie.value && { "x-pwa-edit-hash": pwaHashCookie.value },
|
|
26
|
+
...locale && { locale },
|
|
27
|
+
...referrerId && { referrerID: referrerId },
|
|
28
|
+
...noCache && { noCache },
|
|
29
|
+
...useRequestHeaders(),
|
|
30
|
+
...import.meta.server && ssrCookie.value && { cookie: ssrCookie.value }
|
|
31
|
+
};
|
|
23
32
|
};
|
|
33
|
+
const headersProxy = new Proxy(
|
|
34
|
+
{},
|
|
35
|
+
{
|
|
36
|
+
get(_target, prop, receiver) {
|
|
37
|
+
return Reflect.get(getFreshHeaders(), prop, receiver);
|
|
38
|
+
},
|
|
39
|
+
ownKeys() {
|
|
40
|
+
return Reflect.ownKeys(getFreshHeaders());
|
|
41
|
+
},
|
|
42
|
+
getOwnPropertyDescriptor() {
|
|
43
|
+
return {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
24
50
|
const sdkConfig = {
|
|
25
51
|
plentysystems: buildModule(
|
|
26
52
|
middlewareModule,
|
|
27
53
|
{
|
|
28
54
|
apiUrl: moduleConfig.apiUrl + "/plentysystems",
|
|
29
55
|
defaultRequestConfig: {
|
|
30
|
-
headers
|
|
56
|
+
headers: headersProxy
|
|
31
57
|
},
|
|
32
58
|
httpClient
|
|
33
59
|
},
|
|
34
60
|
() => ({
|
|
35
61
|
subscribers: {
|
|
36
62
|
"*_after": (payload) => {
|
|
63
|
+
const { ssrContext } = useNuxtApp();
|
|
37
64
|
if (payload.csrfToken) {
|
|
38
65
|
token.value = payload.csrfToken;
|
|
39
66
|
}
|
|
67
|
+
if (import.meta.server && payload.setCookie && ssrContext?.event?.node?.res) {
|
|
68
|
+
const cookieValue = Array.isArray(payload.setCookie) ? payload.setCookie[0] : payload.setCookie;
|
|
69
|
+
const newCookie = cookieValue.split(";")[0];
|
|
70
|
+
if (newCookie) {
|
|
71
|
+
ssrCookie.value = newCookie;
|
|
72
|
+
}
|
|
73
|
+
ssrContext.event.node.res.setHeader("Access-Control-Expose-Headers", "Set-Cookie");
|
|
74
|
+
ssrContext.event.node.res.setHeader("Set-Cookie", payload.setCookie);
|
|
75
|
+
}
|
|
40
76
|
}
|
|
41
77
|
}
|
|
42
78
|
})
|
|
43
79
|
)
|
|
44
80
|
};
|
|
45
|
-
|
|
81
|
+
const sdk = initSDK(sdkConfig);
|
|
82
|
+
nuxtApp._sdk = sdk;
|
|
83
|
+
return sdk;
|
|
46
84
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plentymarkets/shop-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Core module for PlentyONE Shop",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@plentymarkets/shop-api": "^0.
|
|
45
|
+
"@plentymarkets/shop-api": "^0.138.0",
|
|
46
46
|
"@vue-storefront/sdk": "^3.4.1",
|
|
47
47
|
"js-sha256": "^0.11.0",
|
|
48
48
|
"resolve": "^1.22.10"
|