@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2023 Shopware
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# shopware/frontends - composables
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@shopware/composables)
|
|
4
|
+
[](https://github.com/shopware/frontends/tree/main/packages/composables)
|
|
5
|
+
[](https://github.com/shopware/frontends/issues?q=is%3Aopen+is%3Aissue+label%3Acomposables)
|
|
6
|
+
[](#)
|
|
7
|
+
|
|
8
|
+
Set of Vue.js composition functions that can be used in any Vue.js project. They provide state management, UI logic and data fetching and are the base for all guides in our [building section](https://frontends.shopware.com/getting-started/page-elements/navigation.html).
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- `createShopwareContext` method to create a Vue 3 plugin to install
|
|
13
|
+
- State management
|
|
14
|
+
- Logic for UI
|
|
15
|
+
- Communication with Store-API via [api-client](https://www.npmjs.com/package/@shopware/api-client) package
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Install npm packages (composables & api-client):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using pnpm
|
|
23
|
+
pnpm add @shopware/composables @shopware/api-client @shopware/api-gen
|
|
24
|
+
|
|
25
|
+
# Using yarn
|
|
26
|
+
yarn add @shopware/composables @shopware/api-client @shopware/api-gen
|
|
27
|
+
|
|
28
|
+
# Using npm
|
|
29
|
+
npm i @shopware/composables @shopware/api-client @shopware/api-gen
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Now generate your types ysing the [CLI](https://www.npmjs.com/package/@shopware/api-gen):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm shopware-api-gen generate --apiType=store
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Initialize the [api-client](https://www.npmjs.com/package/@shopware/api-client) instance:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { createAPIClient } from "@shopware/api-client";
|
|
42
|
+
import type { operations } from "#shopware";
|
|
43
|
+
|
|
44
|
+
export const apiClient = createAPIClient<operations>({
|
|
45
|
+
baseURL: "https://your-api-instance.com",
|
|
46
|
+
accessToken: "your-sales-channel-access-token",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// and then provide it in the Vue app
|
|
50
|
+
app.provide("apiClient", apiClient);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Now, we can create a Vue 3 plugin to install a Shopware context in an app:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { createShopwareContext } from "@shopware/composables";
|
|
57
|
+
|
|
58
|
+
// app variable in type of App
|
|
59
|
+
const shopwareContext = createShopwareContext(app, {
|
|
60
|
+
devStorefrontUrl: "https://your-sales-channel-configured-domain.com",
|
|
61
|
+
});
|
|
62
|
+
// register a plugin in a Vue instance
|
|
63
|
+
app.use(shopwareContext);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Exclude `@shopware/composables` package from [pre-building](https://vite.dev/guide/dep-pre-bundling.html#customizing-the-behavior) process:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// vite.config.js or .ts
|
|
70
|
+
...
|
|
71
|
+
optimizeDeps: {
|
|
72
|
+
exclude: ["@shopware/composables"],
|
|
73
|
+
},
|
|
74
|
+
...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
> The example does not provide the session handling and that means you need to do few additional steps if you need to keep your session after the page reload (see the chapter below with 🍪)
|
|
80
|
+
|
|
81
|
+
## Basic usage
|
|
82
|
+
|
|
83
|
+
Now you can use any composable function in your setup function:
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<script setup>
|
|
87
|
+
import { useUser, useSessionContext } from "@shopware/composables/dist";
|
|
88
|
+
|
|
89
|
+
const { login } = useUser();
|
|
90
|
+
const { refreshSessionContext, sessionContext } = useSessionContext();
|
|
91
|
+
refreshSessionContext();
|
|
92
|
+
</script>
|
|
93
|
+
<template>
|
|
94
|
+
<pre>{{ sessionContext }}</pre>
|
|
95
|
+
<button @click="login({
|
|
96
|
+
username: "some-user",
|
|
97
|
+
password: "secret-passwd"
|
|
98
|
+
})">
|
|
99
|
+
Try to login!
|
|
100
|
+
</button>
|
|
101
|
+
</template>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Session persistence with 🍪
|
|
105
|
+
|
|
106
|
+
By default, the API-Client is stateless, but accepts an optional context token as a parameter while initializing an instance. In order to keep a session, install some cookie parser to work with cookies easier:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Using pnpm
|
|
110
|
+
pnpm add js-cookie
|
|
111
|
+
|
|
112
|
+
# Using yarn
|
|
113
|
+
yarn add js-cookie
|
|
114
|
+
|
|
115
|
+
# Using npm
|
|
116
|
+
npm i js-cookie
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Let's get back to the step where the `api-client` was initialized:
|
|
120
|
+
|
|
121
|
+
<!-- automd:file src="examples/b2b-quote-management/src/apiClient.ts" code -->
|
|
122
|
+
|
|
123
|
+
```ts [apiClient.ts]
|
|
124
|
+
import { createAPIClient } from "@shopware/api-client";
|
|
125
|
+
import Cookies from "js-cookie";
|
|
126
|
+
import type { operations } from "#shopware";
|
|
127
|
+
|
|
128
|
+
const shopwareEndpoint = "https://demo-frontends.shopware.store/store-api";
|
|
129
|
+
|
|
130
|
+
export const apiClient = createAPIClient<operations>({
|
|
131
|
+
baseURL: shopwareEndpoint,
|
|
132
|
+
accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
|
|
133
|
+
contextToken: Cookies.get("sw-context-token"),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
apiClient.hook("onContextChanged", (newContextToken) => {
|
|
137
|
+
Cookies.set("sw-context-token", newContextToken, {
|
|
138
|
+
expires: 365, // days
|
|
139
|
+
path: "/",
|
|
140
|
+
sameSite: "lax",
|
|
141
|
+
secure: shopwareEndpoint.startsWith("https://"),
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
<!-- /automd -->
|
|
147
|
+
|
|
148
|
+
Thanks to this, the session will be kept to the corresponding `sw-context-token` saved in the cookie, so it can be reachable also in the SSR. Check the example to see it in action:
|
|
149
|
+
|
|
150
|
+
[](https://stackblitz.com/github/shopware/frontends/tree/main/examples/blank-playground?file=src%2Fmain.ts)
|
|
151
|
+
|
|
152
|
+
## TypeScript support
|
|
153
|
+
|
|
154
|
+
All composable functions are fully typed with TypeScript and they are registed globally in Nuxt.js application, so the type hinting will help you to work with all of them.
|
|
155
|
+
|
|
156
|
+
## Links
|
|
157
|
+
|
|
158
|
+
- [📘 Documentation](https://frontends.shopware.com)
|
|
159
|
+
|
|
160
|
+
- [👥 Community Slack](https://shopwarecommunity.slack.com) (`#composable-frontends` & `#shopware-pwa` channel)
|
|
161
|
+
|
|
162
|
+
<!-- AUTO GENERATED CHANGELOG -->
|
|
163
|
+
|
|
164
|
+
## Changelog
|
|
165
|
+
|
|
166
|
+
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/composables/CHANGELOG.md)
|
|
167
|
+
|
|
168
|
+
### Latest changes: 0.0.0-canary-20250116155626
|
|
169
|
+
|
|
170
|
+
### Minor Changes
|
|
171
|
+
|
|
172
|
+
- [#1596](https://github.com/shopware/frontends/pull/1596) [`3a79106`](https://github.com/shopware/frontends/commit/3a791065d04152255095965e3fb12ea538a22639) Thanks [@patzick](https://github.com/patzick)! - Changed `@shopware-pwa/composables` package to `@shopware/composables`. Just rename it in package.json file and run install.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../src";
|