Skip to content

Commit

Permalink
feat!: override components and composables (#452)
Browse files Browse the repository at this point in the history
* feat!: overwrite components and composables

* feat: switch api client for cart composables, proper type support and schema overrides

* feat(composables): expose `useContext` as public api to help override composables

* refactor: new api client in useSalutations

Co-authored-by: Maciek Kucmus <[email protected]>

* refactor: useListing using new api client types

* fix: product card thumbnail

* refactor: product listing result

* chore: fix linting errors

* fix: tests

* refactor: useUser using new api client

* refactor: useSessionContext

* refactor: usenewsletter

* refactor: more composables

* chore: update tests

* refactor: more composables

* refactor: more composables - pair programming

Co-authored-by: Maciej D <[email protected]>

* fix: tests

* refactor: fix more types

* chore: link to issue

* refactor: api errors handling, more types transferred

* refactor: remove old api client from dependencies of main template

* feat(composables): useNavigationSearch.ts, useWishlist.ts, useLandingSearch.ts (#441)

* feat: add useNavigationSearch test

* feat: add useWishlist test

* feat: add useLandingSearch test

* feat: add useLandingSearch test

* feat: add defineComponent

* feat: add mockImplementation type

* feat: add useCmsMeta test

* feat(composables): useNavigationSearch.ts, useWishlist.ts, useLandingSearch.ts

* refactor: useSetup helper for composables testing and remove old api client dependency from composables package

* refactor(nuxt-module): proper setup for new composables structure

* feat: proper exporting nuxt layer as separate import

* chore: move OPenAPI todos into schema file

* chore: move OPenAPI todos into schema file

* refactor: use checkout example transformation

* chore: error link format

* chore: improve build

* chore: fix e2e test

* chore: add single changeset to fill out later

---------

Co-authored-by: Maciek Kucmus <[email protected]>
Co-authored-by: mkucmus <[email protected]>
Co-authored-by: Maciej D <[email protected]>
Co-authored-by: Maciej D <[email protected]>
  • Loading branch information
5 people authored Nov 27, 2023
1 parent 0d1cafd commit e2c225f
Show file tree
Hide file tree
Showing 355 changed files with 7,582 additions and 4,876 deletions.
7 changes: 7 additions & 0 deletions .changeset/six-bikes-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@shopware-pwa/nuxt3-module": major
"@shopware-pwa/composables-next": major
"@shopware-pwa/cms-base": major
---

Created Nuxt layer for `composables` and `cms-base`. This way overriding any part of that is now possible.
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@shopware-pwa/api-client": "workspace:*",
"@shopware-pwa/composables-next": "workspace:*",
"@shopware-pwa/helpers-next": "workspace:*",
"@shopware-pwa/types": "workspace:*",
"flexsearch": "^0.7.31",
"markdown-it": "^13.0.2",
"vitepress": "1.0.0-beta.7",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/framework/composables/shared-composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example:
## How do I know which one is shared and what should I do with that?

We're adding information that the composable is shared into the description with a link to this documentation page.
There is no need to do anything with this information. The only difference is in [overwriting](#overwrite-extend-shared-composable)
There is no need to do anything with this information. The only difference is in [overwriting](./overwriting-composables.md)

## Overwrite/extend shared composable

Expand Down
4 changes: 4 additions & 0 deletions apps/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ nav:

Shopware Composable Frontends is Shopware's toolkit for creating platform-agnostic custom storefronts. The demo store implementation is based on Vue.js and Nuxt3.

## Quick Links

- **Announcements**: To keep yourself up to date with the latest news regarding the project, please regularly check our Github Discussions page: [shopware/frontends/dicsussions](https://github.com/shopware/frontends/discussions). Especially the [Announcements](https://github.com/shopware/frontends/discussions/categories/announcements) category.

## How Shopware Frontends work?

Frontends is a collection of multiple packages that you can use to implement your custom storefront project.
Expand Down
6 changes: 5 additions & 1 deletion examples/adyen-dropin-component/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default defineNuxtConfig({
extends: [
"@shopware-pwa/composables-next/nuxt-layer",
"@shopware-pwa/cms-base",
],
runtimeConfig: {
public: {
loginData: {
Expand All @@ -23,6 +27,6 @@ export default defineNuxtConfig({
css: [
"@unocss/reset/tailwind-compat.css", // needed to reset styles see https://unocss.dev/guide/style-reset (@unocss/reset)
],
modules: ["@shopware-pwa/nuxt3-module", "@unocss/nuxt"],
modules: ["@unocss/nuxt", "@shopware-pwa/nuxt3-module"],
devtools: { enabled: true },
});
6 changes: 4 additions & 2 deletions examples/adyen-dropin-component/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"private": true,
"name": "adyen-dropin-playground",
"name": "example-adyen-dropin-playground",
"type": "module",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"devDependencies": {
"@adyen/adyen-web": "^5.53.2",
"@adyen/adyen-web": "^5.53.3",
"@shopware/api-client": "canary",
"@shopware-pwa/composables-next": "canary",
"@shopware-pwa/nuxt3-module": "canary",
"@shopware-pwa/types": "canary",
"@unocss/nuxt": "^0.57.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/blank-playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useSessionContext } from "@shopware-pwa/composables-next";
import { useSessionContext } from "@shopware-pwa/composables-next/dist";
const { refreshSessionContext, sessionContext } = useSessionContext();
refreshSessionContext();
Expand Down
2 changes: 1 addition & 1 deletion examples/blank-playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, ref } from "vue";
import { createShopwareContext } from "@shopware-pwa/composables-next";
import { createShopwareContext } from "@shopware-pwa/composables-next/dist";
import { createInstance } from "@shopware-pwa/api-client";
import Cookies from "js-cookie";

Expand Down
8 changes: 4 additions & 4 deletions examples/commercial-quick-order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ In order to use the example, you need to:
```
VITE_SHOPWARE_API="https://201023-quick-order.swstage.store/"
VITE_SHOPWARE_ACCESS_KEY="SWSCBHFSNTVMAWNZDNFKSHLAYW"
```
```

- Have a customer account with B2B Quick Order feature activated.

Expand All @@ -45,16 +45,16 @@ or...

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/shopware/frontends/tree/main/examples/commercial-quick-order?file=README.md)

⚠️ Remember to prepare your app first, see __Configuration__ chapter above.
⚠️ Remember to prepare your app first, see **Configuration** chapter above.

## 📁 Import file feature


file upload can be tested in that format:

```
product_number,quantity
SW10096.3,2
SW10079,5
```

You can use [products.csv](./products.csv)
You can use [products.csv](./products.csv)
2 changes: 1 addition & 1 deletion examples/commercial-quick-order/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useSessionContext,
useShopwareContext,
useUser,
} from "@shopware-pwa/composables-next";
} from "@shopware-pwa/composables-next/dist";
import { addCartItems } from "@shopware-pwa/api-client";
import { onClickOutside, useDebounceFn } from "@vueuse/core";
Expand Down
2 changes: 1 addition & 1 deletion examples/commercial-quick-order/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, ref } from "vue";
import { createShopwareContext } from "@shopware-pwa/composables-next";
import { createShopwareContext } from "@shopware-pwa/composables-next/dist";
import { createInstance } from "@shopware-pwa/api-client";
import Cookies from "js-cookie";

Expand Down
14 changes: 7 additions & 7 deletions examples/commercial-quick-order/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { fileURLToPath, URL } from 'node:url'
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});
1 change: 1 addition & 0 deletions examples/express-checkout/imports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@shopware-pwa/composables-next";
15 changes: 8 additions & 7 deletions examples/express-checkout/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { fileURLToPath, URL } from 'node:url'
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
"@": fileURLToPath(new URL("./src", import.meta.url)),
"#imports": fileURLToPath(new URL("./imports.d.ts", import.meta.url)),
},
},
});
2 changes: 1 addition & 1 deletion examples/login-form/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useUser } from "@shopware-pwa/composables-next";
import { useUser } from "@shopware-pwa/composables-next/dist";
import type { ClientApiError, ShopwareError } from "@shopware-pwa/types";
import { reactive, ref } from "vue";
const { logout, login, isLoggedIn, user } = useUser();
Expand Down
2 changes: 1 addition & 1 deletion examples/login-form/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, ref } from "vue";
import { createShopwareContext } from "@shopware-pwa/composables-next";
import { createShopwareContext } from "@shopware-pwa/composables-next/dist";
import { createInstance } from "@shopware-pwa/api-client";
import Cookies from "js-cookie";

Expand Down
2 changes: 1 addition & 1 deletion examples/mollie-credit-card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mollie: {

```html
<script setup lang="ts">
import { useCheckout } from "@shopware-pwa/composables-next";
import { useCheckout } from "@shopware-pwa/composables-next/dist";
const { selectedPaymentMethod } = useCheckout();
// the name may vary, so first, please check what comes from API
const showMollieCreditCardComponent = computed(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script setup lang="ts">
import { useShopwareContext, useUser } from "@shopware-pwa/composables-next";
import {
useShopwareContext,
useUser,
} from "@shopware-pwa/composables-next/dist";
const { apiInstance } = useShopwareContext();
const { user } = useUser();
import type { MollieLocale } from "../../types";
Expand Down
3 changes: 2 additions & 1 deletion examples/mollie-credit-card/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "esnext"
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"extends": "./playground/.nuxt/tsconfig.json"
}
36 changes: 36 additions & 0 deletions examples/new-api-client/shopware.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declare module "#shopware" {
import type { createAPIClient } from "@shopware/api-client";
import type {
operationPaths as defaultOperationPaths,
operations as defaultOperations,
components as defaultComponents,
} from "@shopware/api-client/api-types";
import type {
RequestParameters as DefaultRequestParameters,
RequestReturnType as DefaultRequestReturnType,
} from "@shopware/api-client";

type changedComponents = defaultComponents;
// example how to extend Cart schema:
// type changedComponents = components & {
// schemas: {
// Cart: defaultComponents["schemas"]["Cart"] & {
// myspecialfield: "hello field";
// };
// };
// };

export type operations = defaultOperations<changedComponents>;
export type operationPaths = defaultOperationPaths;
export type Schemas = changedComponents["schemas"];

// we're exporting our own Api Client definition as it depends on our own instance
export type ApiClient = ReturnType<
typeof createAPIClient<operations, operationPaths>
>;
export type RequestParameters<T extends keyof operations> =
DefaultRequestParameters<T, operations>;

export type RequestReturnType<T extends keyof operations> =
DefaultRequestReturnType<T, operations>;
}
5 changes: 3 additions & 2 deletions examples/new-api-client/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { apiClient, ApiReturnType } from "./apiClient";
import { apiClient } from "./apiClient";
import HelloWorld from "./components/HelloWorld.vue";
import LoginForm from "./components/LoginForm.vue";
import AdminLoginForm from "./components/AdminLoginForm.vue";
import { adminApiClient } from "./adminApiClient";
import { ApiClientError } from "@shopware/api-client";
import type { RequestReturnType } from "#shopware";
const productsResponse = ref<ApiReturnType<"readProduct">>();
const productsResponse = ref<RequestReturnType<"readProduct">>();
onMounted(async () => {
await apiClient.invoke("readContext get /context", {});
Expand Down
20 changes: 3 additions & 17 deletions examples/new-api-client/src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import {
RequestParameters,
RequestReturnType,
createAPIClient,
} from "@shopware/api-client";
import type {
operationPaths,
operations,
components,
} from "@shopware/api-client/api-types";
import { RequestParameters, createAPIClient } from "@shopware/api-client";
import type { operationPaths, operations } from "#shopware";
import Cookies from "js-cookie";

export const apiClient = createAPIClient<operations, operationPaths>({
Expand All @@ -24,14 +16,8 @@ export const apiClient = createAPIClient<operations, operationPaths>({
},
});

export type ApiSchemas = components["schemas"];
export type ApiRequestParams<OPERATION_NAME extends keyof operations> =
RequestParameters<OPERATION_NAME, operations>;
export type ApiReturnType<OPERATION_NAME extends keyof operations> =
RequestReturnType<OPERATION_NAME, operations>;

// predefine navigation loading method with depth settings
export const readNavigation = (params: ApiRequestParams<"readNavigation">) =>
export const readNavigation = (params: RequestParameters<"readNavigation">) =>
apiClient.invoke(
"readNavigation post /navigation/{activeId}/{rootId} sw-include-seo-urls",
{
Expand Down
8 changes: 7 additions & 1 deletion examples/new-api-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"noEmit": true,
"types": ["vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"include": [
"src/**/*.ts",
"**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"shopware.d.ts"
],
"references": [{ "path": "./tsconfig.node.json" }]
}
2 changes: 1 addition & 1 deletion examples/product-detail-page/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useProductSearch } from "@shopware-pwa/composables-next";
import { useProductSearch } from "@shopware-pwa/composables-next/dist";
import type { Product } from "@shopware-pwa/types";
import ProductView from "@/components/ProductView.vue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useAddToCart,
useProductPrice,
usePrice,
} from "@shopware-pwa/composables-next";
} from "@shopware-pwa/composables-next/dist";
import type { Product } from "@shopware-pwa/types";
const props = defineProps<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useProductPrice,
usePrice,
useProductAssociations,
} from "@shopware-pwa/composables-next";
} from "@shopware-pwa/composables-next/dist";
import ProductCard from "./ProductCard.vue";
const props = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion examples/product-detail-page/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, ref } from "vue";
import { createShopwareContext } from "@shopware-pwa/composables-next";
import { createShopwareContext } from "@shopware-pwa/composables-next/dist";
import { createInstance } from "@shopware-pwa/api-client";
import Cookies from "js-cookie";

Expand Down
2 changes: 1 addition & 1 deletion examples/responsive-images/src/components/Image.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed } from "vue";
import { useProductSearch } from "@shopware-pwa/composables-next";
import { useProductSearch } from "@shopware-pwa/composables-next/dist";
const { search } = useProductSearch();
// look for some product
Expand Down
2 changes: 1 addition & 1 deletion examples/responsive-images/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp, ref } from "vue";
import { createShopwareContext } from "@shopware-pwa/composables-next";
import { createShopwareContext } from "@shopware-pwa/composables-next/dist";
import { createInstance } from "@shopware-pwa/api-client";
import Cookies from "js-cookie";

Expand Down
16 changes: 5 additions & 11 deletions examples/responsive-images/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
{
"include": [
"src/**/*"
],
"include": ["src/**/*"],
"compilerOptions": {
"module": "esnext",
"paths": {
"@/*": [
"./src/*" // set path `@/*` as alias of `src/*`
]
},
"esModuleInterop": true,
"lib": [
"esnext",
"DOM"
],
"types": [
"vite/client"
]
"lib": ["esnext", "DOM"],
"types": ["vite/client"]
}
}
}
Loading

3 comments on commit e2c225f

@vercel
Copy link

@vercel vercel bot commented on e2c225f Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app

@vercel
Copy link

@vercel vercel bot commented on e2c225f Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eyecatchup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change actually broke the build of the vue demo store (due to broken imports).

Local build:
Bildschirmfoto 2023-11-27 um 22 14 34

StackBlitz build:
Bildschirmfoto 2023-11-27 um 22 16 14

Please sign in to comment.