@plentymarkets/shop-core 1.6.8 → 1.7.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.d.mts +2 -1
- package/dist/module.d.ts +2 -1
- package/dist/module.json +1 -1
- package/dist/runtime/composables/__tests__/useSdk.spec.js +53 -0
- package/dist/runtime/composables/sdk.client.js +6 -32
- package/dist/runtime/composables/useSdk.d.ts +5 -1
- package/dist/runtime/composables/useSdk.js +38 -8
- package/dist/types.d.mts +6 -0
- package/dist/types.d.ts +6 -0
- package/package.json +11 -6
package/dist/module.d.mts
CHANGED
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
|
@@ -2,6 +2,7 @@ import { describe } from "node:test";
|
|
|
2
2
|
import { expect, it, vi } from "vitest";
|
|
3
3
|
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
4
4
|
import { useSdk } from "../useSdk.js";
|
|
5
|
+
import { ref, reactive } from "vue";
|
|
5
6
|
const { useRuntimeConfig } = vi.hoisted(() => {
|
|
6
7
|
return {
|
|
7
8
|
useRuntimeConfig: vi.fn().mockImplementation(() => {
|
|
@@ -15,6 +16,58 @@ const { useRuntimeConfig } = vi.hoisted(() => {
|
|
|
15
16
|
})
|
|
16
17
|
};
|
|
17
18
|
});
|
|
19
|
+
const { useNuxtApp } = vi.hoisted(() => {
|
|
20
|
+
return {
|
|
21
|
+
useNuxtApp: vi.fn().mockImplementation(() => {
|
|
22
|
+
return {
|
|
23
|
+
$router: {
|
|
24
|
+
currentRoute: {
|
|
25
|
+
value: {
|
|
26
|
+
query: {
|
|
27
|
+
ReferrerID: "123",
|
|
28
|
+
noCache: "true"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
$i18n: {
|
|
34
|
+
locale: {
|
|
35
|
+
value: "en"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const { useCookie } = vi.hoisted(() => {
|
|
43
|
+
return {
|
|
44
|
+
useCookie: vi.fn().mockImplementation(() => {
|
|
45
|
+
return {
|
|
46
|
+
value: "pwa-edit-hash"
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const { useState } = vi.hoisted(() => {
|
|
52
|
+
return {
|
|
53
|
+
useState: vi.fn().mockImplementation(() => {
|
|
54
|
+
return reactive({
|
|
55
|
+
value: {
|
|
56
|
+
token: ref("csrf-token")
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
mockNuxtImport("useCookie", () => {
|
|
63
|
+
return useCookie;
|
|
64
|
+
});
|
|
65
|
+
mockNuxtImport("useState", () => {
|
|
66
|
+
return useState;
|
|
67
|
+
});
|
|
68
|
+
mockNuxtImport("useNuxtApp", () => {
|
|
69
|
+
return useNuxtApp;
|
|
70
|
+
});
|
|
18
71
|
mockNuxtImport("useRuntimeConfig", () => {
|
|
19
72
|
return useRuntimeConfig;
|
|
20
73
|
});
|
|
@@ -1,34 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { ApiError } from "@plentymarkets/shop-api";
|
|
3
|
-
import { useCsrfToken } from "./useCsrfToken.js";
|
|
4
|
-
import { tryUseNuxtApp, useCookie, useNuxtApp, useRuntimeConfig } from "#imports";
|
|
5
|
-
const createHttpClient = () => {
|
|
6
|
-
const client = axios.create({ withCredentials: true });
|
|
7
|
-
if (tryUseNuxtApp()) {
|
|
8
|
-
const { token } = useCsrfToken();
|
|
9
|
-
const { $router, $i18n } = useNuxtApp();
|
|
10
|
-
const locale = $i18n.locale.value;
|
|
11
|
-
const runtimeConfig = useRuntimeConfig();
|
|
12
|
-
const referrerId = $router.currentRoute.value.query?.ReferrerID?.toString() ?? "";
|
|
13
|
-
const noCache = runtimeConfig.public.noCache || $router.currentRoute.value.query?.noCache?.toString() || "";
|
|
14
|
-
const configId = runtimeConfig.public.configId;
|
|
15
|
-
const pwaHashCookie = useCookie("pwa");
|
|
16
|
-
client.interceptors.request.use((request) => {
|
|
17
|
-
if (token.value) request.headers["x-csrf-token"] = token.value;
|
|
18
|
-
if (referrerId) request.headers["referrerID"] = referrerId;
|
|
19
|
-
if (noCache) request.headers["noCache"] = noCache;
|
|
20
|
-
if (configId) request.headers["x-config-id"] = configId;
|
|
21
|
-
if (pwaHashCookie.value) request.headers["x-pwa-edit-hash"] = pwaHashCookie.value;
|
|
22
|
-
request.headers["locale"] = locale;
|
|
23
|
-
return request;
|
|
24
|
-
});
|
|
25
|
-
client.interceptors.response.use((response) => {
|
|
26
|
-
if (response.headers["x-csrf-token"]) token.value = response.headers["x-csrf-token"];
|
|
27
|
-
return response;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return client;
|
|
31
|
-
};
|
|
32
3
|
const handleHttpError = (error) => {
|
|
33
4
|
const axiosError = error;
|
|
34
5
|
const data = axiosError?.response?.data?.data || axiosError?.response?.data;
|
|
@@ -44,9 +15,12 @@ const handleHttpError = (error) => {
|
|
|
44
15
|
};
|
|
45
16
|
export const httpClient = async (url, params, config) => {
|
|
46
17
|
try {
|
|
47
|
-
const client =
|
|
48
|
-
const
|
|
49
|
-
|
|
18
|
+
const client = axios.create({ withCredentials: true });
|
|
19
|
+
const response = await client(url, { ...config, data: params });
|
|
20
|
+
if (response.headers["x-csrf-token"] && response.data) {
|
|
21
|
+
response.data.csrfToken = response.headers["x-csrf-token"];
|
|
22
|
+
}
|
|
23
|
+
return response.data;
|
|
50
24
|
} catch (error) {
|
|
51
25
|
handleHttpError(error);
|
|
52
26
|
}
|
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
import { initSDK, buildModule, middlewareModule } from "@vue-storefront/sdk";
|
|
2
2
|
import { httpClient } from "./sdk.client.js";
|
|
3
|
-
import { useRequestHeaders, useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useCookie, useNuxtApp, useRequestHeaders, useRuntimeConfig } from "#imports";
|
|
4
|
+
import { useCsrfToken } from "./useCsrfToken.js";
|
|
4
5
|
export const useSdk = () => {
|
|
5
|
-
const
|
|
6
|
+
const runtimeConfig = useRuntimeConfig();
|
|
7
|
+
const moduleConfig = runtimeConfig.public.shopCore;
|
|
8
|
+
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
|
+
const { token } = useCsrfToken();
|
|
15
|
+
const headers = {
|
|
16
|
+
...configId && { "x-config-id": configId },
|
|
17
|
+
...token.value && { "x-csrf-token": token.value },
|
|
18
|
+
...pwaHashCookie.value && { "x-pwa-edit-hash": pwaHashCookie.value },
|
|
19
|
+
...locale && { locale },
|
|
20
|
+
...referrerId && { referrerID: referrerId },
|
|
21
|
+
...noCache && { noCache },
|
|
22
|
+
...useRequestHeaders()
|
|
23
|
+
};
|
|
6
24
|
const sdkConfig = {
|
|
7
|
-
plentysystems: buildModule(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
plentysystems: buildModule(
|
|
26
|
+
middlewareModule,
|
|
27
|
+
{
|
|
28
|
+
apiUrl: moduleConfig.apiUrl + "/plentysystems",
|
|
29
|
+
defaultRequestConfig: {
|
|
30
|
+
headers
|
|
31
|
+
},
|
|
32
|
+
httpClient
|
|
11
33
|
},
|
|
12
|
-
|
|
13
|
-
|
|
34
|
+
() => ({
|
|
35
|
+
subscribers: {
|
|
36
|
+
"*_after": (payload) => {
|
|
37
|
+
if (payload.csrfToken) {
|
|
38
|
+
token.value = payload.csrfToken;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
)
|
|
14
44
|
};
|
|
15
45
|
return initSDK(sdkConfig);
|
|
16
46
|
};
|
package/dist/types.d.mts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.js'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
1
7
|
export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
1
7
|
export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plentymarkets/shop-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Core module for PlentyONE Shop",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
|
-
"go": "
|
|
29
|
+
"go": "npm run dev:prepare && npm run prepack",
|
|
30
30
|
"prepack": "nuxt-module-build build",
|
|
31
31
|
"dev": "nuxi dev playground",
|
|
32
32
|
"dev:build": "nuxi build playground",
|
|
@@ -42,12 +42,15 @@
|
|
|
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.120.0",
|
|
46
46
|
"@vue-storefront/sdk": "^3.4.1",
|
|
47
47
|
"js-sha256": "^0.11.0",
|
|
48
48
|
"mitt": "^3.0.1",
|
|
49
49
|
"resolve": "^1.22.10"
|
|
50
50
|
},
|
|
51
|
+
"overrides": {
|
|
52
|
+
"prettier": "^3.6.2"
|
|
53
|
+
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@nuxt/devtools": "^1.7.0",
|
|
53
56
|
"@nuxt/eslint-config": "^0.7.6",
|
|
@@ -57,7 +60,7 @@
|
|
|
57
60
|
"@nuxt/test-utils": "^3.19.0",
|
|
58
61
|
"@nuxtjs/i18n": "9.5.4",
|
|
59
62
|
"@types/node": "latest",
|
|
60
|
-
"@vitest/coverage-v8": "2.
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
61
64
|
"@vue-storefront/eslint-config": "^4.1.0",
|
|
62
65
|
"@vue/test-utils": "^2.4.6",
|
|
63
66
|
"changelogen": "^0.5.7",
|
|
@@ -65,9 +68,11 @@
|
|
|
65
68
|
"eslint-config-prettier": "^9.1.0",
|
|
66
69
|
"eslint-plugin-vuejs-accessibility": "^2.4.1",
|
|
67
70
|
"happy-dom": "^16.8.1",
|
|
68
|
-
"
|
|
71
|
+
"nuxi": "3.17.2",
|
|
72
|
+
"nuxt": "3.17.4",
|
|
73
|
+
"prettier": "^3.6.2",
|
|
69
74
|
"typescript": "~5.7.3",
|
|
70
|
-
"vitest": "^2.
|
|
75
|
+
"vitest": "^3.2.4",
|
|
71
76
|
"vue-tsc": "^2.2.8"
|
|
72
77
|
}
|
|
73
78
|
}
|