@plentymarkets/shop-core 1.10.1 → 1.10.3
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 +3 -3
- package/dist/runtime/composables/sdk.client.js +1 -1
- package/dist/runtime/composables/useCookieBar.js +5 -3
- package/dist/runtime/composables/useSdk.js +2 -5
- package/dist/runtime/utils/runtime.d.ts +1 -1
- package/dist/runtime/utils/sdk.helper.d.ts +8 -0
- package/dist/runtime/utils/sdk.helper.js +15 -0
- package/dist/types.d.mts +3 -5
- package/package.json +10 -11
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -10
- package/dist/runtime/composables/__tests__/useCookieBar.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useCookieBar.spec.js +0 -210
- package/dist/runtime/composables/__tests__/useCookieConsent.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useCookieConsent.spec.js +0 -47
- package/dist/runtime/composables/__tests__/useCsrfToken.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useCsrfToken.spec.js +0 -9
- package/dist/runtime/composables/__tests__/useNotification.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useNotification.spec.js +0 -117
- package/dist/runtime/composables/__tests__/usePlentyEvent.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/usePlentyEvent.spec.js +0 -73
- package/dist/runtime/composables/__tests__/useRegisterCookie.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useRegisterCookie.spec.js +0 -129
- package/dist/runtime/composables/__tests__/useSdk.spec.d.ts +0 -1
- package/dist/runtime/composables/__tests__/useSdk.spec.js +0 -79
- package/dist/types.d.ts +0 -7
package/dist/module.json
CHANGED
|
@@ -20,7 +20,7 @@ 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"]) {
|
|
23
|
+
if (import.meta.server && response.headers["set-cookie"] && response.data && typeof response.data === "object" && response.data !== null) {
|
|
24
24
|
response.data.setCookie = response.headers["set-cookie"];
|
|
25
25
|
}
|
|
26
26
|
return response.data;
|
|
@@ -89,9 +89,11 @@ export const useCookieBar = () => {
|
|
|
89
89
|
const browserCookie = document.cookie.split(";");
|
|
90
90
|
browserCookie.forEach((cookie2) => {
|
|
91
91
|
const cookiePair = cookie2.split("=");
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
if (cookiePair[0]) {
|
|
93
|
+
const name = cookiePair[0].trim();
|
|
94
|
+
if (new RegExp(cookieName).test(name)) {
|
|
95
|
+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
|
|
96
|
+
}
|
|
95
97
|
}
|
|
96
98
|
});
|
|
97
99
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { initSDK, buildModule, middlewareModule } from "@vue-storefront/sdk";
|
|
2
2
|
import { httpClient } from "./sdk.client.js";
|
|
3
|
+
import { updateSsrCookie } from "../utils/sdk.helper.js";
|
|
3
4
|
import { useCookie, useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
4
5
|
import { useCsrfToken } from "./useCsrfToken.js";
|
|
5
6
|
export const useSdk = () => {
|
|
@@ -65,11 +66,7 @@ export const useSdk = () => {
|
|
|
65
66
|
token.value = payload.csrfToken;
|
|
66
67
|
}
|
|
67
68
|
if (import.meta.server && payload.setCookie && ssrContext?.event?.node?.res) {
|
|
68
|
-
|
|
69
|
-
const newCookie = cookieValue.split(";")[0];
|
|
70
|
-
if (newCookie) {
|
|
71
|
-
ssrCookie.value = newCookie;
|
|
72
|
-
}
|
|
69
|
+
updateSsrCookie(ssrCookie, payload.setCookie);
|
|
73
70
|
ssrContext.event.node.res.setHeader("Access-Control-Expose-Headers", "Set-Cookie");
|
|
74
71
|
ssrContext.event.node.res.setHeader("Set-Cookie", payload.setCookie);
|
|
75
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isClient: () => boolean
|
|
1
|
+
export declare const isClient: () => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
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)
|
|
5
|
+
*/
|
|
6
|
+
export declare const updateSsrCookie: (ssrCookie: {
|
|
7
|
+
value: string;
|
|
8
|
+
}, setCookie: string | string[]) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
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()}`;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
if (setCookie.split(";")[0]) {
|
|
12
|
+
ssrCookie.value = setCookie.split(";")[0]?.trim() ?? "";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from '../dist/runtime/types/index.js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export { default } from './module.mjs'
|
|
4
4
|
|
|
5
|
-
export type ModuleOptions
|
|
6
|
-
|
|
7
|
-
export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module.js'
|
|
5
|
+
export { type ModuleOptions } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plentymarkets/shop-core",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
4
4
|
"description": "Core module for PlentyONE Shop",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,13 +15,12 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
18
|
+
"require": "./dist/module.mjs",
|
|
19
|
+
"types": "./dist/types.d.mts",
|
|
20
|
+
"import": "./dist/module.mjs"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
"main": "./dist/module.
|
|
24
|
-
"types": "./dist/types.d.ts",
|
|
23
|
+
"main": "./dist/module.mjs",
|
|
25
24
|
"files": [
|
|
26
25
|
"dist"
|
|
27
26
|
],
|
|
@@ -53,9 +52,9 @@
|
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@nuxt/devtools": "^1.7.0",
|
|
55
54
|
"@nuxt/eslint-config": "^0.7.6",
|
|
56
|
-
"@nuxt/kit": "^
|
|
57
|
-
"@nuxt/module-builder": "^0.
|
|
58
|
-
"@nuxt/schema": "^
|
|
55
|
+
"@nuxt/kit": "^4.1.3",
|
|
56
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
57
|
+
"@nuxt/schema": "^4.1.3",
|
|
59
58
|
"@nuxt/test-utils": "^3.19.0",
|
|
60
59
|
"@nuxtjs/i18n": "9.5.4",
|
|
61
60
|
"@types/node": "latest",
|
|
@@ -68,9 +67,9 @@
|
|
|
68
67
|
"eslint-plugin-vuejs-accessibility": "^2.4.1",
|
|
69
68
|
"happy-dom": "^16.8.1",
|
|
70
69
|
"nuxi": "3.17.2",
|
|
71
|
-
"nuxt": "
|
|
70
|
+
"nuxt": "^4.1.3",
|
|
72
71
|
"prettier": "^3.6.2",
|
|
73
|
-
"typescript": "~5.
|
|
72
|
+
"typescript": "~5.9.2",
|
|
74
73
|
"vitest": "^3.2.4",
|
|
75
74
|
"vue-tsc": "^2.2.8"
|
|
76
75
|
}
|
package/dist/module.cjs
DELETED
package/dist/module.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
export { Cookie, CookieGroup, CookieGroupFromNuxtConfig, Events, JsonCookie, Notification, PaymentButtonComponent, PaymentButtonComponentProps } from '../dist/runtime/types/index.js';
|
|
3
|
-
|
|
4
|
-
interface ModuleOptions {
|
|
5
|
-
apiUrl: string;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
8
|
-
|
|
9
|
-
export { _default as default };
|
|
10
|
-
export type { ModuleOptions };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "nuxt/app";
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
3
|
-
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
4
|
-
import { useCookieBar } from "../useCookieBar.js";
|
|
5
|
-
import { useCookieConsent } from "../useCookieConsent.js";
|
|
6
|
-
import { ref } from "vue";
|
|
7
|
-
const { useCookie } = vi.hoisted(() => ({
|
|
8
|
-
useCookie: vi.fn().mockReturnValue({})
|
|
9
|
-
}));
|
|
10
|
-
const { useRouter } = vi.hoisted(() => ({
|
|
11
|
-
useRouter: vi.fn().mockReturnValue({
|
|
12
|
-
go: vi.fn()
|
|
13
|
-
})
|
|
14
|
-
}));
|
|
15
|
-
mockNuxtImport("useCookie", () => useCookie);
|
|
16
|
-
mockNuxtImport("useRouter", () => useRouter);
|
|
17
|
-
describe("useCookieBar", () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
const cookieInit = {
|
|
20
|
-
configHash: "",
|
|
21
|
-
barTitle: "Test",
|
|
22
|
-
barDescription: "Test",
|
|
23
|
-
groups: [
|
|
24
|
-
{
|
|
25
|
-
id: 0,
|
|
26
|
-
name: "CookieBar.essentials.label",
|
|
27
|
-
showMore: false,
|
|
28
|
-
description: "CookieBar.essentials.description",
|
|
29
|
-
cookies: [
|
|
30
|
-
{
|
|
31
|
-
name: "CookieBar.essentials.cookies.payPal.name",
|
|
32
|
-
Provider: "CookieBar.essentials.cookies.payPal.provider",
|
|
33
|
-
Status: "CookieBar.essentials.cookies.payPal.status",
|
|
34
|
-
PrivacyPolicy: "/PrivacyPolicy",
|
|
35
|
-
Lifespan: "Session"
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: 1,
|
|
41
|
-
name: "marketing",
|
|
42
|
-
accepted: false,
|
|
43
|
-
showMore: false,
|
|
44
|
-
description: "Marketing cookies description",
|
|
45
|
-
cookies: [
|
|
46
|
-
{
|
|
47
|
-
name: "testCookie",
|
|
48
|
-
accepted: false,
|
|
49
|
-
Lifespan: "100",
|
|
50
|
-
script: [],
|
|
51
|
-
Provider: "TestProvider",
|
|
52
|
-
Status: "Inactive",
|
|
53
|
-
PrivacyPolicy: "/PrivacyPolicy"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "externalScript",
|
|
57
|
-
accepted: false,
|
|
58
|
-
Lifespan: "100",
|
|
59
|
-
script: ["https://cdn02.plentymarkets.com/mevofvd5omld/frontend/test-cookie-external-script.js"],
|
|
60
|
-
Provider: "TestProvider",
|
|
61
|
-
Status: "Inactive",
|
|
62
|
-
PrivacyPolicy: "/PrivacyPolicy"
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
|
-
const { public: config } = useRuntimeConfig();
|
|
69
|
-
config.cookieGroups = cookieInit;
|
|
70
|
-
});
|
|
71
|
-
it("initializes cookies correctly", () => {
|
|
72
|
-
const { initializeCookies, data, setConsent } = useCookieBar();
|
|
73
|
-
initializeCookies();
|
|
74
|
-
setConsent();
|
|
75
|
-
expect(data.value.groups[0].cookies[0].accepted).toBe(true);
|
|
76
|
-
expect(data.value.groups[1].cookies[0].accepted).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
it("changes visibility state correctly", () => {
|
|
79
|
-
const { changeVisibilityState, visible } = useCookieBar();
|
|
80
|
-
changeVisibilityState();
|
|
81
|
-
expect(visible.value).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
it("accept all cookies state correctly", () => {
|
|
84
|
-
const { setAllCookiesState, data } = useCookieBar();
|
|
85
|
-
setAllCookiesState(true);
|
|
86
|
-
const allCookiesAccepted = data.value.groups[1].cookies.every((cookie) => {
|
|
87
|
-
return cookie.accepted;
|
|
88
|
-
});
|
|
89
|
-
expect(allCookiesAccepted).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
it("decline all cookies state correctly", () => {
|
|
92
|
-
const { setAllCookiesState, data } = useCookieBar();
|
|
93
|
-
setAllCookiesState(false);
|
|
94
|
-
const allCookiesDeclined = data.value.groups[1].cookies.every((cookie) => {
|
|
95
|
-
return !cookie.accepted;
|
|
96
|
-
});
|
|
97
|
-
expect(allCookiesDeclined).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
it("removes cookies correctly", () => {
|
|
100
|
-
document.cookie = "testCookie=testValue";
|
|
101
|
-
const cookie = {
|
|
102
|
-
name: "testCookie",
|
|
103
|
-
Lifespan: "Session",
|
|
104
|
-
Provider: "testProvider",
|
|
105
|
-
Status: "testStatus",
|
|
106
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
107
|
-
cookieNames: ["testCookie"]
|
|
108
|
-
};
|
|
109
|
-
const { removeCookies } = useCookieBar();
|
|
110
|
-
removeCookies(cookie);
|
|
111
|
-
expect(document.cookie).not.toContain("testCookie=testValue");
|
|
112
|
-
});
|
|
113
|
-
it("should set state read from browser-cookie", () => {
|
|
114
|
-
const browserCookies = {
|
|
115
|
-
hash: "",
|
|
116
|
-
groups: {
|
|
117
|
-
"CookieBar.essentials.label": {
|
|
118
|
-
"CookieBar.essentials.cookies.payPal.name": true
|
|
119
|
-
},
|
|
120
|
-
marketing: {
|
|
121
|
-
testCookie: true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
useCookie.mockImplementation((name) => {
|
|
126
|
-
if (name === "consent-cookie") return ref(browserCookies);
|
|
127
|
-
return ref(null);
|
|
128
|
-
});
|
|
129
|
-
const { initializeCookies, data } = useCookieBar();
|
|
130
|
-
initializeCookies();
|
|
131
|
-
expect(data.value.groups[1].cookies[0].accepted).toBe(true);
|
|
132
|
-
});
|
|
133
|
-
it("should reload the page if a consent cookie is revoked", () => {
|
|
134
|
-
const { setConsent, initializeCookies, data } = useCookieBar();
|
|
135
|
-
const RouterGoSpy = vi.fn();
|
|
136
|
-
useRouter.mockReturnValue({ go: RouterGoSpy });
|
|
137
|
-
useCookie.mockImplementation((name) => {
|
|
138
|
-
if (name === "consent-cookie") {
|
|
139
|
-
return ref({
|
|
140
|
-
hash: "abc123",
|
|
141
|
-
groups: {
|
|
142
|
-
marketing: {
|
|
143
|
-
testCookie: true
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return ref(null);
|
|
149
|
-
});
|
|
150
|
-
initializeCookies();
|
|
151
|
-
data.value.groups[1].cookies[0].accepted = false;
|
|
152
|
-
setConsent();
|
|
153
|
-
expect(RouterGoSpy).toHaveBeenCalledTimes(1);
|
|
154
|
-
});
|
|
155
|
-
it("should not reload the page if a consent cookie is accepted", () => {
|
|
156
|
-
const { setConsent, initializeCookies } = useCookieBar();
|
|
157
|
-
const RouterGoSpy = vi.fn();
|
|
158
|
-
useRouter.mockReturnValue({
|
|
159
|
-
go: RouterGoSpy
|
|
160
|
-
});
|
|
161
|
-
initializeCookies();
|
|
162
|
-
setConsent();
|
|
163
|
-
expect(RouterGoSpy).toHaveBeenCalledTimes(0);
|
|
164
|
-
});
|
|
165
|
-
it("should load external scripts", () => {
|
|
166
|
-
const { initializeCookies, data, setConsent } = useCookieBar();
|
|
167
|
-
const scriptSpy = vi.fn();
|
|
168
|
-
const script = document.createElement("script");
|
|
169
|
-
scriptSpy.mockReturnValue(script);
|
|
170
|
-
document.createElement = scriptSpy;
|
|
171
|
-
initializeCookies();
|
|
172
|
-
data.value.groups[1].cookies[1].accepted = true;
|
|
173
|
-
setConsent();
|
|
174
|
-
expect(scriptSpy).toHaveBeenCalledTimes(1);
|
|
175
|
-
expect(scriptSpy).toHaveBeenCalledWith("script");
|
|
176
|
-
expect(scriptSpy().src).toBe(
|
|
177
|
-
"https://cdn02.plentymarkets.com/mevofvd5omld/frontend/test-cookie-external-script.js"
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
it("accepts the specific cookie correctly", () => {
|
|
181
|
-
const { data, accept } = useCookieBar();
|
|
182
|
-
const { consent } = useCookieConsent("testCookie");
|
|
183
|
-
accept("testCookie");
|
|
184
|
-
expect(data.value.groups[1].cookies[0].accepted).toBe(true);
|
|
185
|
-
expect(consent.value).toBe(true);
|
|
186
|
-
});
|
|
187
|
-
it("should show the cookie bar if hash is missing", () => {
|
|
188
|
-
const browserCookies = { groups: {} };
|
|
189
|
-
useCookie.mockImplementation((name) => {
|
|
190
|
-
if (name === "consent-cookie") return ref(browserCookies);
|
|
191
|
-
return ref(null);
|
|
192
|
-
});
|
|
193
|
-
const { initializeCookies, visible } = useCookieBar();
|
|
194
|
-
initializeCookies();
|
|
195
|
-
expect(visible.value).toBe(true);
|
|
196
|
-
});
|
|
197
|
-
it("should show the cookie bar if hash does not match", () => {
|
|
198
|
-
const browserCookies = {
|
|
199
|
-
hash: "mismatchedHash",
|
|
200
|
-
groups: {}
|
|
201
|
-
};
|
|
202
|
-
useCookie.mockImplementation((name) => {
|
|
203
|
-
if (name === "consent-cookie") return ref(browserCookies);
|
|
204
|
-
return ref(null);
|
|
205
|
-
});
|
|
206
|
-
const { initializeCookies, visible } = useCookieBar();
|
|
207
|
-
initializeCookies();
|
|
208
|
-
expect(visible.value).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
-
import { useRuntimeConfig } from "nuxt/app";
|
|
3
|
-
import { useCookieConsent } from "../useCookieConsent.js";
|
|
4
|
-
import { useCookieBar } from "../useCookieBar.js";
|
|
5
|
-
describe("useCookieConsent", () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
const cookieInit = {
|
|
8
|
-
barTitle: "Test",
|
|
9
|
-
barDescription: "Test",
|
|
10
|
-
groups: [
|
|
11
|
-
{
|
|
12
|
-
id: 0,
|
|
13
|
-
name: "CookieBar.essentials.label",
|
|
14
|
-
showMore: false,
|
|
15
|
-
description: "CookieBar.essentials.description",
|
|
16
|
-
cookies: [
|
|
17
|
-
{
|
|
18
|
-
name: "CookieBar.essentials.cookies.payPal.name",
|
|
19
|
-
Provider: "CookieBar.essentials.cookies.payPal.provider",
|
|
20
|
-
Status: "CookieBar.essentials.cookies.payPal.status",
|
|
21
|
-
PrivacyPolicy: "/PrivacyPolicy",
|
|
22
|
-
Lifespan: "Session"
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "marketing",
|
|
28
|
-
cookies: [
|
|
29
|
-
{
|
|
30
|
-
name: "testCookie",
|
|
31
|
-
accepted: false,
|
|
32
|
-
script: []
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
const { public: config } = useRuntimeConfig();
|
|
39
|
-
config.cookieGroups = cookieInit;
|
|
40
|
-
const { initializeCookies } = useCookieBar();
|
|
41
|
-
initializeCookies();
|
|
42
|
-
});
|
|
43
|
-
it("initializes consent state correctly", () => {
|
|
44
|
-
const { consent } = useCookieConsent("CookieBar.essentials.cookies.payPal.name");
|
|
45
|
-
expect(consent.value).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { useCsrfToken } from "../useCsrfToken.js";
|
|
3
|
-
describe("useCsrfToken", () => {
|
|
4
|
-
it("should set and csrf token", () => {
|
|
5
|
-
const { token } = useCsrfToken();
|
|
6
|
-
token.value = "test";
|
|
7
|
-
expect(token.value).toBe("test");
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { useNotification } from "../useNotification.js";
|
|
3
|
-
describe("useNotification", () => {
|
|
4
|
-
afterEach(() => {
|
|
5
|
-
const { clear } = useNotification();
|
|
6
|
-
clear();
|
|
7
|
-
});
|
|
8
|
-
it("should return the correct initial state", () => {
|
|
9
|
-
const { data, send } = useNotification();
|
|
10
|
-
expect(data.value).toEqual([]);
|
|
11
|
-
expect(send).toBeInstanceOf(Function);
|
|
12
|
-
});
|
|
13
|
-
it("should add a notification", () => {
|
|
14
|
-
const { data, send } = useNotification();
|
|
15
|
-
send({
|
|
16
|
-
message: "Test alert error with a longer message",
|
|
17
|
-
type: "negative",
|
|
18
|
-
persist: true
|
|
19
|
-
});
|
|
20
|
-
expect(data.value.length).toBe(1);
|
|
21
|
-
});
|
|
22
|
-
it("should remove a notification", () => {
|
|
23
|
-
const { data, send } = useNotification();
|
|
24
|
-
send({
|
|
25
|
-
message: "Test alert error with a longer message",
|
|
26
|
-
type: "negative"
|
|
27
|
-
});
|
|
28
|
-
expect(data.value.length).toBe(1);
|
|
29
|
-
if (data.value[0].dismiss) {
|
|
30
|
-
data.value[0].dismiss();
|
|
31
|
-
}
|
|
32
|
-
expect(data.value.length).toBe(0);
|
|
33
|
-
});
|
|
34
|
-
it("should clear all notifications", () => {
|
|
35
|
-
const { data, send, clear } = useNotification();
|
|
36
|
-
for (let i = 0; i < 5; i++) {
|
|
37
|
-
send({
|
|
38
|
-
message: "Test alert error with a longer message",
|
|
39
|
-
type: "negative"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
expect(data.value.length).toBe(5);
|
|
43
|
-
clear();
|
|
44
|
-
expect(data.value.length).toBe(0);
|
|
45
|
-
});
|
|
46
|
-
it("should remove the oldest notification when the maximum number of notifications is reached", async () => {
|
|
47
|
-
const { data, send } = useNotification();
|
|
48
|
-
for (let i = 0; i < 6; i++) {
|
|
49
|
-
send({
|
|
50
|
-
message: `Message ${i}`,
|
|
51
|
-
type: "positive"
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
expect(data.value[0].message).toBe("Message 1");
|
|
55
|
-
expect(data.value.length).toBe(5);
|
|
56
|
-
});
|
|
57
|
-
it("should remove a notification after default timeout (5000ms)", async () => {
|
|
58
|
-
const { data, send } = useNotification();
|
|
59
|
-
send({
|
|
60
|
-
message: "Test positive message",
|
|
61
|
-
type: "positive"
|
|
62
|
-
});
|
|
63
|
-
expect(data.value.length).toBe(1);
|
|
64
|
-
await new Promise((resolve) => {
|
|
65
|
-
setTimeout(resolve, 4e3);
|
|
66
|
-
});
|
|
67
|
-
expect(data.value.length).toBe(1);
|
|
68
|
-
await new Promise((resolve) => {
|
|
69
|
-
setTimeout(resolve, 1100);
|
|
70
|
-
});
|
|
71
|
-
expect(data.value.length).toBe(0);
|
|
72
|
-
});
|
|
73
|
-
it("should not remove a negative notification after 10ms", async () => {
|
|
74
|
-
const { data, send } = useNotification();
|
|
75
|
-
send({
|
|
76
|
-
message: "Test negative message",
|
|
77
|
-
type: "negative",
|
|
78
|
-
dismissTimeout: 10
|
|
79
|
-
});
|
|
80
|
-
expect(data.value.length).toBe(1);
|
|
81
|
-
await new Promise((resolve) => {
|
|
82
|
-
setTimeout(resolve, 10);
|
|
83
|
-
});
|
|
84
|
-
expect(data.value.length).toBe(1);
|
|
85
|
-
});
|
|
86
|
-
it("should not remove a persist notification after 10ms", async () => {
|
|
87
|
-
const { data, send } = useNotification();
|
|
88
|
-
send({
|
|
89
|
-
message: "Test persist message",
|
|
90
|
-
type: "positive",
|
|
91
|
-
persist: true,
|
|
92
|
-
dismissTimeout: 10
|
|
93
|
-
});
|
|
94
|
-
expect(data.value.length).toBe(1);
|
|
95
|
-
await new Promise((resolve) => {
|
|
96
|
-
setTimeout(resolve, 10);
|
|
97
|
-
});
|
|
98
|
-
expect(data.value.length).toBe(1);
|
|
99
|
-
});
|
|
100
|
-
it("should call the action function of a notification", () => {
|
|
101
|
-
const { data, send } = useNotification();
|
|
102
|
-
const action = vi.fn();
|
|
103
|
-
send({
|
|
104
|
-
message: "Test alert error with a longer message",
|
|
105
|
-
type: "negative",
|
|
106
|
-
persist: true,
|
|
107
|
-
action: {
|
|
108
|
-
text: "action",
|
|
109
|
-
onClick: action
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
if (data.value[0].action) {
|
|
113
|
-
data.value[0].action.onClick();
|
|
114
|
-
}
|
|
115
|
-
expect(action).toHaveBeenCalled();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi, vitest } from "vitest";
|
|
2
|
-
import { usePlentyEvent } from "../usePlentyEvent.js";
|
|
3
|
-
describe("usePlentyEvent", () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
const { clear } = usePlentyEvent();
|
|
6
|
-
clear();
|
|
7
|
-
vitest.clearAllMocks();
|
|
8
|
-
});
|
|
9
|
-
it("should register an event", () => {
|
|
10
|
-
const { on, emit } = usePlentyEvent();
|
|
11
|
-
const callback = vi.fn();
|
|
12
|
-
on("frontend:login", callback);
|
|
13
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
14
|
-
expect(callback).toHaveBeenCalledWith({ user: { id: 1 } });
|
|
15
|
-
});
|
|
16
|
-
it("should turn off an event", () => {
|
|
17
|
-
const { on, off, emit } = usePlentyEvent();
|
|
18
|
-
const callback = vi.fn();
|
|
19
|
-
on("frontend:login", callback);
|
|
20
|
-
off("frontend:login", callback);
|
|
21
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
22
|
-
expect(callback).not.toHaveBeenCalled();
|
|
23
|
-
});
|
|
24
|
-
it("should register an event only once", () => {
|
|
25
|
-
const { once, emit } = usePlentyEvent();
|
|
26
|
-
const callback = vi.fn();
|
|
27
|
-
once("frontend:login", callback);
|
|
28
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
29
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
30
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
31
|
-
});
|
|
32
|
-
it("should clear all events", () => {
|
|
33
|
-
const { on, emit, clear } = usePlentyEvent();
|
|
34
|
-
const callback = vi.fn();
|
|
35
|
-
on("frontend:login", callback);
|
|
36
|
-
clear();
|
|
37
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
38
|
-
expect(callback).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it("should throw error in event listener without breaking", () => {
|
|
41
|
-
const { on, emit } = usePlentyEvent();
|
|
42
|
-
const errorCallback = vi.fn(() => {
|
|
43
|
-
throw new Error("Test error");
|
|
44
|
-
});
|
|
45
|
-
const callback = vi.fn();
|
|
46
|
-
on("frontend:login", errorCallback);
|
|
47
|
-
on("frontend:login", callback);
|
|
48
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
49
|
-
expect(errorCallback).toHaveBeenCalled();
|
|
50
|
-
expect(callback).toHaveBeenCalledWith({ user: { id: 1 } });
|
|
51
|
-
});
|
|
52
|
-
it("should not turn off event if its a different callback", () => {
|
|
53
|
-
const { on, off, emit } = usePlentyEvent();
|
|
54
|
-
const callback1 = vi.fn();
|
|
55
|
-
const callback2 = vi.fn();
|
|
56
|
-
on("frontend:login", callback1);
|
|
57
|
-
off("frontend:login", callback2);
|
|
58
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
59
|
-
expect(callback1).toHaveBeenCalled();
|
|
60
|
-
expect(callback2).not.toHaveBeenCalled();
|
|
61
|
-
});
|
|
62
|
-
it("should remove all listeners for an event if no callback is provided to off", () => {
|
|
63
|
-
const { on, off, emit } = usePlentyEvent();
|
|
64
|
-
const callback1 = vi.fn();
|
|
65
|
-
const callback2 = vi.fn();
|
|
66
|
-
on("frontend:login", callback1);
|
|
67
|
-
on("frontend:login", callback2);
|
|
68
|
-
off("frontend:login");
|
|
69
|
-
emit("frontend:login", { user: { id: 1 } });
|
|
70
|
-
expect(callback1).not.toHaveBeenCalled();
|
|
71
|
-
expect(callback2).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "nuxt/app";
|
|
2
|
-
import { describe, it, vi, expect } from "vitest";
|
|
3
|
-
import { useRegisterCookie } from "../useRegisterCookie.js";
|
|
4
|
-
vi.mock("nuxt/app", () => ({
|
|
5
|
-
useRuntimeConfig: vi.fn()
|
|
6
|
-
}));
|
|
7
|
-
vi.mock("../../utils/runtime", () => ({
|
|
8
|
-
isClient: vi.fn(() => false)
|
|
9
|
-
}));
|
|
10
|
-
describe("useRegisterCookie", () => {
|
|
11
|
-
it("adds a cookie to the specified group", () => {
|
|
12
|
-
const { add } = useRegisterCookie();
|
|
13
|
-
const runtimeConfig = {
|
|
14
|
-
public: {
|
|
15
|
-
cookieGroups: {
|
|
16
|
-
groups: [
|
|
17
|
-
{
|
|
18
|
-
name: "marketing",
|
|
19
|
-
cookies: []
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
useRuntimeConfig.mockReturnValue(runtimeConfig);
|
|
26
|
-
const cookie = {
|
|
27
|
-
name: "testCookie",
|
|
28
|
-
Provider: "testProvider",
|
|
29
|
-
Status: "testStatus",
|
|
30
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
31
|
-
Lifespan: "Session",
|
|
32
|
-
cookieNames: ["testCookieName"],
|
|
33
|
-
accepted: true
|
|
34
|
-
};
|
|
35
|
-
add(cookie, "marketing");
|
|
36
|
-
expect(runtimeConfig.public.cookieGroups.groups[0].cookies).toContainEqual(cookie);
|
|
37
|
-
});
|
|
38
|
-
it("does not add a cookie if it already exists in the group", () => {
|
|
39
|
-
const { add } = useRegisterCookie();
|
|
40
|
-
const runtimeConfig = {
|
|
41
|
-
public: {
|
|
42
|
-
cookieGroups: {
|
|
43
|
-
groups: [
|
|
44
|
-
{
|
|
45
|
-
name: "marketing",
|
|
46
|
-
cookies: [
|
|
47
|
-
{
|
|
48
|
-
name: "testCookie",
|
|
49
|
-
Provider: "testProvider",
|
|
50
|
-
Status: "testStatus",
|
|
51
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
52
|
-
Lifespan: "Session",
|
|
53
|
-
cookieNames: ["testCookieName"],
|
|
54
|
-
accepted: true
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
useRuntimeConfig.mockReturnValue(runtimeConfig);
|
|
63
|
-
const cookie = {
|
|
64
|
-
name: "testCookie",
|
|
65
|
-
Provider: "testProvider",
|
|
66
|
-
Status: "testStatus",
|
|
67
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
68
|
-
Lifespan: "Session",
|
|
69
|
-
cookieNames: ["testCookieName"],
|
|
70
|
-
accepted: true
|
|
71
|
-
};
|
|
72
|
-
add(cookie, "marketing");
|
|
73
|
-
expect(runtimeConfig.public.cookieGroups.groups[0].cookies.length).toBe(1);
|
|
74
|
-
});
|
|
75
|
-
it("does not add a cookie if the group does not exist", () => {
|
|
76
|
-
const { add } = useRegisterCookie();
|
|
77
|
-
const runtimeConfig = {
|
|
78
|
-
public: {
|
|
79
|
-
cookieGroups: {
|
|
80
|
-
groups: [
|
|
81
|
-
{
|
|
82
|
-
name: "analytics",
|
|
83
|
-
cookies: []
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
useRuntimeConfig.mockReturnValue(runtimeConfig);
|
|
90
|
-
const cookie = {
|
|
91
|
-
name: "testCookie",
|
|
92
|
-
Provider: "testProvider",
|
|
93
|
-
Status: "testStatus",
|
|
94
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
95
|
-
Lifespan: "Session",
|
|
96
|
-
cookieNames: ["testCookieName"],
|
|
97
|
-
accepted: true
|
|
98
|
-
};
|
|
99
|
-
add(cookie, "marketing");
|
|
100
|
-
expect(runtimeConfig.public.cookieGroups.groups[0].cookies.length).toBe(0);
|
|
101
|
-
});
|
|
102
|
-
it("add empty cookie array if group does not have cookies", () => {
|
|
103
|
-
const { add } = useRegisterCookie();
|
|
104
|
-
const runtimeConfig = {
|
|
105
|
-
public: {
|
|
106
|
-
cookieGroups: {
|
|
107
|
-
groups: [
|
|
108
|
-
{
|
|
109
|
-
name: "marketing",
|
|
110
|
-
cookies: []
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
useRuntimeConfig.mockReturnValue(runtimeConfig);
|
|
117
|
-
const cookie = {
|
|
118
|
-
name: "testCookie",
|
|
119
|
-
Provider: "testProvider",
|
|
120
|
-
Status: "testStatus",
|
|
121
|
-
PrivacyPolicy: "https://example.com/privacy",
|
|
122
|
-
Lifespan: "Session",
|
|
123
|
-
cookieNames: ["testCookieName"],
|
|
124
|
-
accepted: true
|
|
125
|
-
};
|
|
126
|
-
add(cookie, "marketing");
|
|
127
|
-
expect(runtimeConfig.public.cookieGroups.groups[0].cookies).toContainEqual(cookie);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { describe } from "node:test";
|
|
2
|
-
import { expect, it, vi } from "vitest";
|
|
3
|
-
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
4
|
-
import { useSdk } from "../useSdk.js";
|
|
5
|
-
import { ref, reactive } from "vue";
|
|
6
|
-
const { useRuntimeConfig } = vi.hoisted(() => {
|
|
7
|
-
return {
|
|
8
|
-
useRuntimeConfig: vi.fn().mockImplementation(() => {
|
|
9
|
-
return {
|
|
10
|
-
public: {
|
|
11
|
-
shopCore: {
|
|
12
|
-
apiUrl: "https://example.com"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
})
|
|
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
|
-
});
|
|
71
|
-
mockNuxtImport("useRuntimeConfig", () => {
|
|
72
|
-
return useRuntimeConfig;
|
|
73
|
-
});
|
|
74
|
-
describe("useSdk", () => {
|
|
75
|
-
it("should return sdk", () => {
|
|
76
|
-
const sdk = useSdk();
|
|
77
|
-
expect(sdk.plentysystems.getCategoryTree).toBeDefined();
|
|
78
|
-
});
|
|
79
|
-
});
|
package/dist/types.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
export { type Cookie, type CookieGroup, type CookieGroupFromNuxtConfig, type Events, type JsonCookie, type Notification, type PaymentButtonComponent, type PaymentButtonComponentProps } from './module'
|