@shopware/composables 0.0.0-canary-20250116155626
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/LICENSE +21 -0
- package/README.md +172 -0
- package/composables/index.ts +1 -0
- package/dist/index.d.mts +2239 -0
- package/dist/index.d.ts +2239 -0
- package/dist/index.mjs +2686 -0
- package/nuxt.config.ts +14 -0
- package/package.json +83 -0
- package/src/_test/index.ts +1 -0
- package/src/_test/useSetup.ts +43 -0
- package/src/cms/README.md +9 -0
- package/src/cms/cmsAssociations.ts +28 -0
- package/src/cms/index.ts +2 -0
- package/src/cms/useCmsElementConfig.test.ts +145 -0
- package/src/cms/useCmsElementConfig.ts +29 -0
- package/src/cms/useCmsElementImage.test.ts +179 -0
- package/src/cms/useCmsElementImage.ts +103 -0
- package/src/cms/useCmsElementProductBox.test.ts +15 -0
- package/src/cms/useCmsElementProductBox.ts +25 -0
- package/src/createShopwareContext.test.ts +23 -0
- package/src/createShopwareContext.ts +43 -0
- package/src/devtools/plugin.ts +201 -0
- package/src/helpers/ContextError.spec.ts +20 -0
- package/src/helpers/ContextError.ts +6 -0
- package/src/index.test.ts +54 -0
- package/src/index.ts +111 -0
- package/src/mocks/Cart.ts +774 -0
- package/src/mocks/CmsPage.ts +544 -0
- package/src/mocks/CmsProductBox.ts +377 -0
- package/src/mocks/Configurator.ts +123 -0
- package/src/mocks/Country.ts +184 -0
- package/src/mocks/CrossSellingResponse.ts +552 -0
- package/src/mocks/LandingPage.ts +62 -0
- package/src/mocks/Menu.ts +598 -0
- package/src/mocks/Order.ts +1151 -0
- package/src/mocks/Product.ts +473 -0
- package/src/mocks/ProductTierPrices.ts +771 -0
- package/src/mocks/Salutations.ts +51 -0
- package/src/mocks/Search.ts +518 -0
- package/src/types/cmsBlockTypes.ts +80 -0
- package/src/types/cmsElementTypes.ts +381 -0
- package/src/types/cmsSectionTypes.ts +15 -0
- package/src/types/index.ts +52 -0
- package/src/useAddToCart/useAddToCart.test.ts +39 -0
- package/src/useAddToCart/useAddToCart.ts +90 -0
- package/src/useAddress/useAddress.test.ts +134 -0
- package/src/useAddress/useAddress.ts +202 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +137 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +225 -0
- package/src/useBreadcrumbs/useBreadcrumbs.test.ts +71 -0
- package/src/useBreadcrumbs/useBreadcrumbs.ts +89 -0
- package/src/useCart/useCart.test.ts +251 -0
- package/src/useCart/useCart.ts +314 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +122 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.ts +80 -0
- package/src/useCartItem/useCartItem.test.ts +168 -0
- package/src/useCartItem/useCartItem.ts +157 -0
- package/src/useCartNotification/useCartNotification.test.ts +129 -0
- package/src/useCartNotification/useCartNotification.ts +63 -0
- package/src/useCategory/useCategory.test.ts +14 -0
- package/src/useCategory/useCategory.ts +32 -0
- package/src/useCategorySearch/useCategorySearch.test.ts +98 -0
- package/src/useCategorySearch/useCategorySearch.ts +81 -0
- package/src/useCheckout/useCheckout.test.ts +104 -0
- package/src/useCheckout/useCheckout.ts +163 -0
- package/src/useCmsBlock/useCmsBlock.test.ts +25 -0
- package/src/useCmsBlock/useCmsBlock.ts +36 -0
- package/src/useCmsMeta/useCmsMeta.test.ts +17 -0
- package/src/useCmsMeta/useCmsMeta.ts +46 -0
- package/src/useCmsSection/useCmsSection.test.ts +18 -0
- package/src/useCmsSection/useCmsSection.ts +39 -0
- package/src/useCmsTranslations/useCmsTranslations.test.ts +10 -0
- package/src/useCmsTranslations/useCmsTranslations.ts +9 -0
- package/src/useContext/useContext.ts +36 -0
- package/src/useCountries/useCountries.test.ts +64 -0
- package/src/useCountries/useCountries.ts +64 -0
- package/src/useCustomerOrders/useCustomerOrders.test.ts +47 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +89 -0
- package/src/useCustomerPassword/useCustomerPassword.test.ts +164 -0
- package/src/useCustomerPassword/useCustomerPassword.ts +57 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +41 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +45 -0
- package/src/useInternationalization/useInternationalization.test.ts +155 -0
- package/src/useInternationalization/useInternationalization.ts +159 -0
- package/src/useLandingSearch/useLandingSearch.test.ts +30 -0
- package/src/useLandingSearch/useLandingSearch.ts +58 -0
- package/src/useListing/useListing.test.ts +249 -0
- package/src/useListing/useListing.ts +592 -0
- package/src/useLocalWishlist/useLocalWishlist.test.ts +54 -0
- package/src/useLocalWishlist/useLocalWishlist.ts +95 -0
- package/src/useNavigation/useNavigation.test.ts +68 -0
- package/src/useNavigation/useNavigation.ts +83 -0
- package/src/useNavigationContext/useNavigationContext.test.ts +48 -0
- package/src/useNavigationContext/useNavigationContext.ts +39 -0
- package/src/useNavigationSearch/useNavigationSearch.test.ts +110 -0
- package/src/useNavigationSearch/useNavigationSearch.ts +60 -0
- package/src/useNewsletter/useNewsletter.test.ts +55 -0
- package/src/useNewsletter/useNewsletter.ts +109 -0
- package/src/useNotifications/useNotifications.test.ts +56 -0
- package/src/useNotifications/useNotifications.ts +119 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +224 -0
- package/src/useOrderDetails/useOrderDetails.ts +329 -0
- package/src/useOrderPayment/useOrderPayment.test.ts +80 -0
- package/src/useOrderPayment/useOrderPayment.ts +119 -0
- package/src/usePrice/usePrice.test.ts +97 -0
- package/src/usePrice/usePrice.ts +106 -0
- package/src/useProduct/useProduct.test.ts +36 -0
- package/src/useProduct/useProduct.ts +56 -0
- package/src/useProductAssociations/useProductAssociations.spec.ts +105 -0
- package/src/useProductAssociations/useProductAssociations.ts +107 -0
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +77 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +134 -0
- package/src/useProductPrice/useProductPrice.test.ts +126 -0
- package/src/useProductPrice/useProductPrice.ts +131 -0
- package/src/useProductReviews/useProductReviews.test.ts +45 -0
- package/src/useProductReviews/useProductReviews.ts +80 -0
- package/src/useProductSearch/useProductSearch.test.ts +37 -0
- package/src/useProductSearch/useProductSearch.ts +58 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +19 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.ts +67 -0
- package/src/useProductWishlist/useProductWishlist.test.ts +63 -0
- package/src/useProductWishlist/useProductWishlist.ts +74 -0
- package/src/useSalutations/useSalutations.spec.ts +37 -0
- package/src/useSalutations/useSalutations.ts +55 -0
- package/src/useSessionContext/useSessionContext.test.ts +221 -0
- package/src/useSessionContext/useSessionContext.ts +281 -0
- package/src/useShopwareContext/useShopwareContext.test.ts +8 -0
- package/src/useShopwareContext/useShopwareContext.ts +31 -0
- package/src/useSyncWishlist/useSyncWishlist.test.ts +117 -0
- package/src/useSyncWishlist/useSyncWishlist.ts +117 -0
- package/src/useUrlResolver/useUrlResolver.test.ts +25 -0
- package/src/useUrlResolver/useUrlResolver.ts +31 -0
- package/src/useUser/useUser.test.ts +290 -0
- package/src/useUser/useUser.ts +321 -0
- package/src/useWishlist/useWishlist.test.ts +178 -0
- package/src/useWishlist/useWishlist.ts +128 -0
- package/types/api-types.ts +11 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp } from "vue";
|
|
3
|
+
import { createShopwareContext } from "./createShopwareContext";
|
|
4
|
+
|
|
5
|
+
describe("createShopwareContext", () => {
|
|
6
|
+
it("should create a Shopware context with default options", () => {
|
|
7
|
+
const app = createApp({});
|
|
8
|
+
const context = createShopwareContext(app, {});
|
|
9
|
+
context.install(app);
|
|
10
|
+
expect(context).toBeDefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should create a Shopware context with custom options", () => {
|
|
14
|
+
const app = createApp({});
|
|
15
|
+
const options = {
|
|
16
|
+
devStorefrontUrl: "https://devstorefront.com",
|
|
17
|
+
enableDevtools: true,
|
|
18
|
+
};
|
|
19
|
+
const context = createShopwareContext(app, options);
|
|
20
|
+
|
|
21
|
+
expect(context).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currently devtools are not working in Nuxt 3
|
|
3
|
+
* source: https://github.com/nuxt/framework/issues/4325
|
|
4
|
+
* - we don't need them for now as we do not show any significant info for now
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { effectScope, markRaw, reactive } from "vue";
|
|
8
|
+
import type { App, EffectScope } from "vue";
|
|
9
|
+
// import { registerShopwareDevtools } from "./devtools/plugin";
|
|
10
|
+
|
|
11
|
+
export function createShopwareContext(
|
|
12
|
+
app: App,
|
|
13
|
+
options: {
|
|
14
|
+
devStorefrontUrl?: string | null;
|
|
15
|
+
enableDevtools?: boolean;
|
|
16
|
+
},
|
|
17
|
+
) {
|
|
18
|
+
const scope: EffectScope = effectScope(true);
|
|
19
|
+
const state = scope.run(() => {
|
|
20
|
+
return reactive({
|
|
21
|
+
interceptors: {},
|
|
22
|
+
// sharedStore: options.initialStore || reactive({}),
|
|
23
|
+
// shopwareDefaults: options.shopwareDefaults || {},
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const shopwarePlugin = markRaw({
|
|
28
|
+
install(app: App) {
|
|
29
|
+
shopwarePlugin._a = app;
|
|
30
|
+
app.config.globalProperties.$shopware = shopwarePlugin;
|
|
31
|
+
app.provide("shopware", shopwarePlugin);
|
|
32
|
+
},
|
|
33
|
+
_a: app,
|
|
34
|
+
_e: scope,
|
|
35
|
+
devStorefrontUrl: options.devStorefrontUrl,
|
|
36
|
+
state,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (options?.enableDevtools && typeof window !== "undefined") {
|
|
40
|
+
// registerShopwareDevtools(app, shopwarePlugin);
|
|
41
|
+
}
|
|
42
|
+
return shopwarePlugin;
|
|
43
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// TODO fix types in this plugin
|
|
2
|
+
import { setupDevtoolsPlugin } from "@vue/devtools-api";
|
|
3
|
+
import type { DevtoolsPluginApi } from "@vue/devtools-api";
|
|
4
|
+
import { unref } from "vue";
|
|
5
|
+
import type { App, InjectionKey } from "vue";
|
|
6
|
+
|
|
7
|
+
const TIMELINE_EVENT_LAYER_ID = "shopware:events";
|
|
8
|
+
const INSPECTOR_ID = "shopware";
|
|
9
|
+
export const shopwareSymbol = Symbol("shopware") as InjectionKey<string>;
|
|
10
|
+
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
export function registerShopwareDevtools(
|
|
13
|
+
app: App,
|
|
14
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
15
|
+
shopwarePluginInstance: any,
|
|
16
|
+
) {
|
|
17
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
18
|
+
let devtoolsApi: DevtoolsPluginApi<any>;
|
|
19
|
+
let trackId = 0;
|
|
20
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
21
|
+
let currentSharedState: any = null;
|
|
22
|
+
|
|
23
|
+
setupDevtoolsPlugin(
|
|
24
|
+
{
|
|
25
|
+
id: "shopware-frontends",
|
|
26
|
+
label: "Shopware Frontends",
|
|
27
|
+
logo: "https://shopware.com/media/unknown/2d/80/8c/shopware_signet_blue.svg",
|
|
28
|
+
packageName: "shopware-frontends",
|
|
29
|
+
homepage: "shopware.com",
|
|
30
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
31
|
+
app: app as any,
|
|
32
|
+
enableEarlyProxy: true,
|
|
33
|
+
},
|
|
34
|
+
(api) => {
|
|
35
|
+
devtoolsApi = api;
|
|
36
|
+
|
|
37
|
+
api.addTimelineLayer({
|
|
38
|
+
id: TIMELINE_EVENT_LAYER_ID,
|
|
39
|
+
label: "Shopware Frontends",
|
|
40
|
+
color: 1613567,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
api.addInspector({
|
|
44
|
+
id: INSPECTOR_ID,
|
|
45
|
+
label: "Shopware Frontends",
|
|
46
|
+
icon: "shopping_cart",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
api.on.getInspectorTree((payload) => {
|
|
50
|
+
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
|
|
51
|
+
payload.rootNodes = [
|
|
52
|
+
// {
|
|
53
|
+
// id: "shared-state",
|
|
54
|
+
// label: "Shared state",
|
|
55
|
+
// },
|
|
56
|
+
// {
|
|
57
|
+
// id: "interceptors",
|
|
58
|
+
// label: "Interceptors",
|
|
59
|
+
// },
|
|
60
|
+
{
|
|
61
|
+
id: "api-client",
|
|
62
|
+
label: "API client",
|
|
63
|
+
},
|
|
64
|
+
// {
|
|
65
|
+
// id: "api-defaults",
|
|
66
|
+
// label: "API defaults",
|
|
67
|
+
// },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
73
|
+
function displayState(state: any) {
|
|
74
|
+
if (!state) return null;
|
|
75
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
76
|
+
const res: any = {};
|
|
77
|
+
// biome-ignore lint/complexity/noForEach: ignore for now
|
|
78
|
+
Object.keys(state).forEach((refKey) => {
|
|
79
|
+
res[refKey] = unref(currentSharedState[refKey]);
|
|
80
|
+
});
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
api.on.getInspectorState((payload) => {
|
|
85
|
+
if (payload.app === app && payload.inspectorId === INSPECTOR_ID) {
|
|
86
|
+
switch (payload.nodeId) {
|
|
87
|
+
case "api-client":
|
|
88
|
+
payload.state = {
|
|
89
|
+
config: shopwarePluginInstance.apiInstance.config,
|
|
90
|
+
};
|
|
91
|
+
break;
|
|
92
|
+
case "shared-state":
|
|
93
|
+
payload.state = {
|
|
94
|
+
store:
|
|
95
|
+
displayState(currentSharedState) ||
|
|
96
|
+
shopwarePluginInstance.state.sharedStore ||
|
|
97
|
+
payload.app.$sharedStore,
|
|
98
|
+
};
|
|
99
|
+
break;
|
|
100
|
+
case "interceptors":
|
|
101
|
+
payload.state = {
|
|
102
|
+
registered: shopwarePluginInstance.state.interceptors,
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case "api-defaults":
|
|
107
|
+
payload.state = shopwarePluginInstance.state.shopwareDefaults;
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
payload.state = {};
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const devtools = {
|
|
120
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
121
|
+
trackEvent: (label: string, params: any) => {
|
|
122
|
+
const groupId = `track${trackId++}`;
|
|
123
|
+
|
|
124
|
+
// Start
|
|
125
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
126
|
+
const log = (label: string, params: any) => {
|
|
127
|
+
devtoolsApi.addTimelineEvent({
|
|
128
|
+
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
129
|
+
event: {
|
|
130
|
+
time: Date.now(),
|
|
131
|
+
data: {
|
|
132
|
+
label,
|
|
133
|
+
params,
|
|
134
|
+
},
|
|
135
|
+
title: label,
|
|
136
|
+
groupId,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
log(label, params);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
log,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
148
|
+
log: (label: string, params: any) => {
|
|
149
|
+
devtoolsApi.addTimelineEvent({
|
|
150
|
+
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
151
|
+
event: {
|
|
152
|
+
time: Date.now(),
|
|
153
|
+
data: {
|
|
154
|
+
label,
|
|
155
|
+
params,
|
|
156
|
+
},
|
|
157
|
+
title: label,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
162
|
+
warning: (label: string, params: any) => {
|
|
163
|
+
devtoolsApi.addTimelineEvent({
|
|
164
|
+
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
165
|
+
event: {
|
|
166
|
+
time: Date.now(),
|
|
167
|
+
data: {
|
|
168
|
+
label,
|
|
169
|
+
params,
|
|
170
|
+
},
|
|
171
|
+
title: label,
|
|
172
|
+
logType: "warning",
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
177
|
+
error: (label: string, params: any) => {
|
|
178
|
+
devtoolsApi.addTimelineEvent({
|
|
179
|
+
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
180
|
+
event: {
|
|
181
|
+
time: Date.now(),
|
|
182
|
+
data: {
|
|
183
|
+
label,
|
|
184
|
+
params,
|
|
185
|
+
},
|
|
186
|
+
title: label,
|
|
187
|
+
logType: "error",
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
_internal: {
|
|
192
|
+
// biome-ignore lint: not used plugin for now, ignoring type errors
|
|
193
|
+
updateSharedState: (state: any) => {
|
|
194
|
+
currentSharedState = state;
|
|
195
|
+
devtoolsApi.sendInspectorState(INSPECTOR_ID);
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return devtools;
|
|
201
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import ContextError from "./ContextError";
|
|
3
|
+
|
|
4
|
+
describe("contextError", () => {
|
|
5
|
+
it("should ContextError have been thrown with its own message", async () => {
|
|
6
|
+
expect(() => {
|
|
7
|
+
throw new ContextError("Error", "test");
|
|
8
|
+
}).throw("Error test");
|
|
9
|
+
|
|
10
|
+
expect(() => {
|
|
11
|
+
throw new ContextError("Error", "test");
|
|
12
|
+
}).toThrowError();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should ContextError have been thrown", async () => {
|
|
16
|
+
expect(() => {
|
|
17
|
+
throw new ContextError("Error");
|
|
18
|
+
}).toThrowError();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import * as vue from "vue";
|
|
3
|
+
import type { Schemas } from "#shopware";
|
|
4
|
+
import { getDefaultApiParams, resolveCmsComponent } from "./index";
|
|
5
|
+
import CmsPage from "./mocks/CmsPage";
|
|
6
|
+
|
|
7
|
+
vi.mock("vue");
|
|
8
|
+
describe("resolveCmsComponent", () => {
|
|
9
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation((element) => element);
|
|
10
|
+
it("should resolve a cms component", () => {
|
|
11
|
+
const result = resolveCmsComponent(
|
|
12
|
+
CmsPage.cmsPage.sections[0].blocks[0] as unknown as Schemas["CmsBlock"],
|
|
13
|
+
);
|
|
14
|
+
expect(result.componentName).toBe("image-simple-grid");
|
|
15
|
+
expect(result.componentNameToResolve).toBe("CmsBlockImageSimpleGrid");
|
|
16
|
+
expect(result.isResolved).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("getDefaultApiParams", () => {
|
|
20
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
21
|
+
const result = getDefaultApiParams();
|
|
22
|
+
expect(result).toEqual({});
|
|
23
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
24
|
+
"[@shopware-pwa/composables] `getDefaultApiParams` is deprecated and will be removed in the next major release.",
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("cms section component", () => {
|
|
29
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation(() => ({}));
|
|
30
|
+
const result = resolveCmsComponent({
|
|
31
|
+
apiAlias: "cms_section",
|
|
32
|
+
} as unknown as Schemas["CmsBlock"]);
|
|
33
|
+
expect(result.isResolved).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("cms custom component", () => {
|
|
37
|
+
const result = resolveCmsComponent({
|
|
38
|
+
apiAlias: "cms_custom",
|
|
39
|
+
} as unknown as Schemas["CmsBlock"]);
|
|
40
|
+
|
|
41
|
+
expect(result.isResolved).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("component should not be resolved because of the error", () => {
|
|
45
|
+
vi.spyOn(vue, "resolveComponent").mockImplementation(() => {
|
|
46
|
+
throw new Error("error");
|
|
47
|
+
});
|
|
48
|
+
const result = resolveCmsComponent({
|
|
49
|
+
apiAlias: "cms_custom",
|
|
50
|
+
} as unknown as Schemas["CmsBlock"]);
|
|
51
|
+
|
|
52
|
+
expect(result.isResolved).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { pascalCase } from "scule";
|
|
2
|
+
import { resolveComponent } from "vue";
|
|
3
|
+
import type { Schemas } from "#shopware";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A composables library compatible with Vue 3 and Shopware 6.
|
|
7
|
+
*
|
|
8
|
+
* Some more info...
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The `widget-lib` defines the {@link IWidget} interface and {@link Widget} class,
|
|
12
|
+
* which are used to build widgets.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * from "./types";
|
|
18
|
+
export * from "./cms";
|
|
19
|
+
export * from "./createShopwareContext";
|
|
20
|
+
|
|
21
|
+
export * from "./useAddress/useAddress";
|
|
22
|
+
export * from "./useAddToCart/useAddToCart";
|
|
23
|
+
export * from "./useBreadcrumbs/useBreadcrumbs";
|
|
24
|
+
export * from "./useCart/useCart";
|
|
25
|
+
export * from "./useCartItem/useCartItem";
|
|
26
|
+
export * from "./useCategory/useCategory";
|
|
27
|
+
export * from "./useCategorySearch/useCategorySearch";
|
|
28
|
+
export * from "./useCheckout/useCheckout";
|
|
29
|
+
export * from "./useCmsBlock/useCmsBlock";
|
|
30
|
+
export * from "./useCmsMeta/useCmsMeta";
|
|
31
|
+
export * from "./useCmsSection/useCmsSection";
|
|
32
|
+
export * from "./useCmsTranslations/useCmsTranslations";
|
|
33
|
+
export * from "./useContext/useContext";
|
|
34
|
+
export * from "./useCountries/useCountries";
|
|
35
|
+
export * from "./useCustomerOrders/useCustomerOrders";
|
|
36
|
+
export * from "./useCustomerPassword/useCustomerPassword";
|
|
37
|
+
export * from "./useDefaultOrderAssociations/useDefaultOrderAssociations";
|
|
38
|
+
export * from "./useInternationalization/useInternationalization";
|
|
39
|
+
export * from "./useLandingSearch/useLandingSearch";
|
|
40
|
+
export * from "./useListing/useListing";
|
|
41
|
+
export * from "./useLocalWishlist/useLocalWishlist";
|
|
42
|
+
export * from "./useNavigation/useNavigation";
|
|
43
|
+
export * from "./useNavigationContext/useNavigationContext";
|
|
44
|
+
export * from "./useNavigationSearch/useNavigationSearch";
|
|
45
|
+
export * from "./useNewsletter/useNewsletter";
|
|
46
|
+
export * from "./useNotifications/useNotifications";
|
|
47
|
+
export * from "./useOrderDetails/useOrderDetails";
|
|
48
|
+
export * from "./useOrderPayment/useOrderPayment";
|
|
49
|
+
export * from "./usePrice/usePrice";
|
|
50
|
+
export * from "./useProduct/useProduct";
|
|
51
|
+
export * from "./useProductAssociations/useProductAssociations";
|
|
52
|
+
export * from "./useProductConfigurator/useProductConfigurator";
|
|
53
|
+
export * from "./useProductPrice/useProductPrice";
|
|
54
|
+
export * from "./useProductReviews/useProductReviews";
|
|
55
|
+
export * from "./useProductSearch/useProductSearch";
|
|
56
|
+
export * from "./useProductSearchSuggest/useProductSearchSuggest";
|
|
57
|
+
export * from "./useProductWishlist/useProductWishlist";
|
|
58
|
+
export * from "./useSalutations/useSalutations";
|
|
59
|
+
export * from "./useSessionContext/useSessionContext";
|
|
60
|
+
export * from "./useShopwareContext/useShopwareContext";
|
|
61
|
+
export * from "./useSyncWishlist/useSyncWishlist";
|
|
62
|
+
export * from "./useUrlResolver/useUrlResolver";
|
|
63
|
+
export * from "./useUser/useUser";
|
|
64
|
+
export * from "./useWishlist/useWishlist";
|
|
65
|
+
export * from "./useB2bQuoteManagement/useB2bQuoteManagement";
|
|
66
|
+
export * from "./useCartNotification/useCartNotification";
|
|
67
|
+
export * from "./useCartErrorParamsResolver/useCartErrorParamsResolver";
|
|
68
|
+
|
|
69
|
+
export function resolveCmsComponent(
|
|
70
|
+
content: Schemas["CmsSection"] | Schemas["CmsBlock"] | Schemas["CmsSlot"],
|
|
71
|
+
) {
|
|
72
|
+
const componentName = content.type;
|
|
73
|
+
const type =
|
|
74
|
+
content.apiAlias === "cms_block"
|
|
75
|
+
? "Block"
|
|
76
|
+
: content.apiAlias === "cms_section"
|
|
77
|
+
? "Section"
|
|
78
|
+
: "Element";
|
|
79
|
+
|
|
80
|
+
const componentNameToResolve = pascalCase(`Cms-${type}-${componentName}`);
|
|
81
|
+
try {
|
|
82
|
+
const resolvedComponent = resolveComponent(componentNameToResolve);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
componentName,
|
|
86
|
+
componentNameToResolve,
|
|
87
|
+
isResolved: resolvedComponent !== componentName,
|
|
88
|
+
resolvedComponent:
|
|
89
|
+
typeof resolvedComponent !== "string" ? resolvedComponent : undefined,
|
|
90
|
+
};
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return {
|
|
93
|
+
componentName,
|
|
94
|
+
componentNameToResolve,
|
|
95
|
+
resolvedComponent: undefined,
|
|
96
|
+
resolved: false,
|
|
97
|
+
isResolved: false,
|
|
98
|
+
error: (e as Error).message,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// TODO: handle defaults in app
|
|
104
|
+
export function getDefaultApiParams(): {
|
|
105
|
+
[composableName: string]: unknown;
|
|
106
|
+
} {
|
|
107
|
+
console.error(
|
|
108
|
+
"[@shopware-pwa/composables] `getDefaultApiParams` is deprecated and will be removed in the next major release.",
|
|
109
|
+
);
|
|
110
|
+
return {};
|
|
111
|
+
}
|