@teamnovu/kit-shopware-composables 0.0.1 → 0.0.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.
Files changed (34) hide show
  1. package/dist/cart/useCartAddItemMutation.d.ts +12 -0
  2. package/dist/cart/useCartQueryOptions.d.ts +9 -0
  3. package/dist/cart/useCartRemoveItemMutation.d.ts +7 -0
  4. package/dist/cart/useCartUpdateItemMutation.d.ts +12 -0
  5. package/dist/context/useContextOptions.d.ts +9 -0
  6. package/dist/context/useContextUpdate.d.ts +4 -0
  7. package/dist/general/useSeoUrl.d.ts +10 -0
  8. package/dist/index.d.ts +223 -0
  9. package/dist/index.mjs +304 -0
  10. package/dist/inject.d.ts +5 -0
  11. package/dist/keys.d.ts +27 -0
  12. package/dist/products/useCategoryQueryOptions.d.ts +17 -0
  13. package/dist/products/useProductListingQueryOptions.d.ts +19 -0
  14. package/dist/products/useProductListingQueryOptions.test.d.ts +1 -0
  15. package/dist/products/useProductPrice.d.ts +49 -0
  16. package/dist/products/useProductQueryOptions.d.ts +19 -0
  17. package/dist/products/useProductVariantForOptions.d.ts +276 -0
  18. package/dist/types/query.d.ts +7 -0
  19. package/dist/usePagination.d.ts +21 -0
  20. package/dist/util/url.d.ts +2 -0
  21. package/docker/boot_end.sh +0 -0
  22. package/docker/types.sh +0 -0
  23. package/package.json +9 -9
  24. package/src/cart/useCartAddItemMutation.ts +48 -0
  25. package/src/cart/useCartQueryOptions.ts +19 -0
  26. package/src/cart/useCartRemoveItemMutation.ts +32 -0
  27. package/src/cart/useCartUpdateItemMutation.ts +48 -0
  28. package/src/index.ts +8 -0
  29. package/src/keys.ts +4 -0
  30. package/src/products/useProductListingQueryOptions.ts +1 -0
  31. package/src/products/useProductPrice.ts +3 -2
  32. package/src/products/useProductQueryOptions.ts +1 -0
  33. package/src/products/useProductVariantForOptions.ts +8 -2
  34. package/eslint.config.mjs +0 -84
package/dist/keys.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { MaybeRef } from 'vue';
2
+ export declare const contextKeys: {
3
+ all: () => readonly ["context"];
4
+ };
5
+ export declare const categoryKeys: {
6
+ all: () => readonly ["category"];
7
+ lists: () => readonly ["category", "list"];
8
+ list: (body: MaybeRef<unknown>) => readonly ["category", "list", {
9
+ readonly body: unknown;
10
+ }];
11
+ };
12
+ export declare const productKeys: {
13
+ all: () => readonly ["product"];
14
+ lists: () => readonly ["product", "list"];
15
+ list: (url: MaybeRef<string>, body: MaybeRef<unknown>) => readonly ["product", "list", {
16
+ readonly url: MaybeRef<string>;
17
+ readonly body: unknown;
18
+ }];
19
+ details: () => readonly ["product", "detail"];
20
+ detail: (url: MaybeRef<string>, body: MaybeRef<unknown>) => readonly ["product", "detail", {
21
+ readonly url: MaybeRef<string>;
22
+ readonly body: unknown;
23
+ }];
24
+ };
25
+ export declare const cartKeys: {
26
+ get: () => readonly ["cart"];
27
+ };
@@ -0,0 +1,17 @@
1
+ import { operations } from '../../api-types/storeApiTypes.d.ts';
2
+ import { MaybeRef } from 'vue';
3
+ import { OperationBody } from '../types/query';
4
+ import { UndefinedInitialQueryOptions } from '@tanstack/vue-query';
5
+ import { OperationProp } from '@teamnovu/kit-shopware-api-client';
6
+ declare const readCategoryListOperation = "readCategoryList post /category";
7
+ export declare function useCategoryQueryOptions<Operations extends operations>(body?: MaybeRef<OperationBody<Operations, typeof readCategoryListOperation>>): UndefinedInitialQueryOptions<OperationProp<operations & Operations, "readCategoryList post /category", "response">, Error, OperationProp<operations & Operations, "readCategoryList post /category", "response">, readonly ["category", "list", {
8
+ readonly body: unknown;
9
+ }]> & {
10
+ queryKey: readonly ["category", "list", {
11
+ readonly body: unknown;
12
+ }] & {
13
+ [dataTagSymbol]: OperationProp<operations & Operations, "readCategoryList post /category", "response">;
14
+ [dataTagErrorSymbol]: Error;
15
+ };
16
+ };
17
+ export {};
@@ -0,0 +1,19 @@
1
+ import { operations } from '../../api-types/storeApiTypes.d.ts';
2
+ import { MaybeRef } from 'vue';
3
+ import { OperationBody } from '../types/query';
4
+ import { UndefinedInitialQueryOptions } from '@tanstack/vue-query';
5
+ import { OperationProp } from '@teamnovu/kit-shopware-api-client';
6
+ declare const readListingOperation = "readCompactProductListing post /novu/headless/product-listing/{seoUrl}";
7
+ export declare function useProductListingQueryOptions<Operations extends operations>(seoUrl: MaybeRef<string>, body?: MaybeRef<OperationBody<Operations, typeof readListingOperation>>): UndefinedInitialQueryOptions<OperationProp<operations & Operations, "readCompactProductListing post /novu/headless/product-listing/{seoUrl}", "response">, Error, OperationProp<operations & Operations, "readCompactProductListing post /novu/headless/product-listing/{seoUrl}", "response">, readonly ["product", "list", {
8
+ readonly url: MaybeRef<string>;
9
+ readonly body: unknown;
10
+ }]> & {
11
+ queryKey: readonly ["product", "list", {
12
+ readonly url: MaybeRef<string>;
13
+ readonly body: unknown;
14
+ }] & {
15
+ [dataTagSymbol]: OperationProp<operations & Operations, "readCompactProductListing post /novu/headless/product-listing/{seoUrl}", "response">;
16
+ [dataTagErrorSymbol]: Error;
17
+ };
18
+ };
19
+ export {};
@@ -0,0 +1,49 @@
1
+ import { Schemas } from '../../api-types/storeApiTypes.d.ts';
2
+ import { TierPrice } from '@shopware/helpers';
3
+ import { ComputedRef, Ref } from 'vue';
4
+ export type UseProductPriceReturn = {
5
+ /**
6
+ * Whole calculated price object
7
+ */
8
+ price: ComputedRef<Schemas['CalculatedPrice'] | undefined>;
9
+ /**
10
+ * Calculated price value for one selling unit
11
+ */
12
+ totalPrice: ComputedRef<number | undefined>;
13
+ /**
14
+ * Current unit price value
15
+ */
16
+ unitPrice: ComputedRef<number | undefined>;
17
+ /**
18
+ * Can be used if isListPrice is set to true
19
+ */
20
+ referencePrice: ComputedRef<Schemas['CalculatedPrice']['referencePrice'] | undefined>;
21
+ /**
22
+ * determines if `price` contains the minimum tier price
23
+ */
24
+ displayFrom: ComputedRef<boolean>;
25
+ /**
26
+ * cheapest price value for a variant if exists
27
+ */
28
+ displayFromVariants: ComputedRef<number | false | undefined>;
29
+ /**
30
+ * array of TierPrice object
31
+ */
32
+ tierPrices: ComputedRef<TierPrice[]>;
33
+ /**
34
+ * determines whether a discount price is set
35
+ */
36
+ isListPrice: ComputedRef<boolean>;
37
+ /**
38
+ * price for products with regulation price
39
+ */
40
+ regulationPrice: ComputedRef<number | undefined>;
41
+ };
42
+ /**
43
+ * The purpose of the `useProductPrice` function is to abstract the logic
44
+ * to expose most useful helpers for price displaying.
45
+ *
46
+ * @public
47
+ * @category Product
48
+ */
49
+ export declare function useProductPrice(product: Ref<Schemas['Product'] | undefined>): UseProductPriceReturn;
@@ -0,0 +1,19 @@
1
+ import { operations } from '../../api-types/storeApiTypes.d.ts';
2
+ import { MaybeRef } from 'vue';
3
+ import { OperationBody } from '../types/query';
4
+ import { UndefinedInitialQueryOptions } from '@tanstack/vue-query';
5
+ import { OperationProp } from '@teamnovu/kit-shopware-api-client';
6
+ declare const readCustomProductDetailOperation = "readCustomProductDetail post /novu/headless/product/{seoUrl}";
7
+ export declare function useProductQueryOptions<Operations extends operations>(seoUrl: MaybeRef<string>, body?: MaybeRef<OperationBody<Operations, typeof readCustomProductDetailOperation>>): UndefinedInitialQueryOptions<OperationProp<operations & Operations, "readCustomProductDetail post /novu/headless/product/{seoUrl}", "response">, Error, OperationProp<operations & Operations, "readCustomProductDetail post /novu/headless/product/{seoUrl}", "response">, readonly ["product", "detail", {
8
+ readonly url: MaybeRef<string>;
9
+ readonly body: unknown;
10
+ }]> & {
11
+ queryKey: readonly ["product", "detail", {
12
+ readonly url: MaybeRef<string>;
13
+ readonly body: unknown;
14
+ }] & {
15
+ [dataTagSymbol]: OperationProp<operations & Operations, "readCustomProductDetail post /novu/headless/product/{seoUrl}", "response">;
16
+ [dataTagErrorSymbol]: Error;
17
+ };
18
+ };
19
+ export {};
@@ -0,0 +1,276 @@
1
+ import { Schemas, components, GenericRecord } from '../../api-types/storeApiTypes.d.ts';
2
+ import { MaybeRef, ComputedRef } from 'vue';
3
+ type DetailProduct<S extends Schemas> = S['CustomProductDetailResponse']['product'];
4
+ export declare function getProductVariantForOptions<S extends Schemas>(product: DetailProduct<S>, optionIds: string[]): {
5
+ active?: boolean;
6
+ apiAlias: "product";
7
+ readonly available?: boolean;
8
+ readonly availableStock?: number;
9
+ calculatedCheapestPrice?: {
10
+ apiAlias?: "calculated_cheapest_price";
11
+ hasRange?: boolean;
12
+ listPrice?: components["schemas"]["ListPrice"] | null;
13
+ quantity?: number;
14
+ referencePrice?: components["schemas"]["ReferencePrice"] | null;
15
+ regulationPrice?: {
16
+ price: number;
17
+ } | null;
18
+ totalPrice?: number;
19
+ unitPrice?: number;
20
+ variantId?: string | null;
21
+ };
22
+ calculatedMaxPurchase?: number;
23
+ calculatedPrice: components["schemas"]["CalculatedPrice"];
24
+ calculatedPrices: components["schemas"]["CalculatedPrice"][];
25
+ canonicalProduct?: components["schemas"]["Product"];
26
+ canonicalProductId?: string;
27
+ canonicalProductVersionId?: string;
28
+ categories?: components["schemas"]["Category"][];
29
+ categoriesRo?: components["schemas"]["Category"][];
30
+ readonly categoryIds?: string[];
31
+ readonly categoryTree?: string[];
32
+ readonly childCount?: number;
33
+ children?: components["schemas"]["Product"][];
34
+ cmsPage?: components["schemas"]["CmsPage"];
35
+ cmsPageId?: string;
36
+ cmsPageVersionId?: string;
37
+ configuratorSettings?: components["schemas"]["ProductConfiguratorSetting"][];
38
+ cover?: components["schemas"]["ProductMedia"];
39
+ coverId?: string;
40
+ readonly createdAt?: string;
41
+ crossSellings?: components["schemas"]["ProductCrossSelling"][];
42
+ customFields?: GenericRecord;
43
+ deliveryTime?: components["schemas"]["DeliveryTime"];
44
+ deliveryTimeId?: string;
45
+ description?: string;
46
+ readonly displayGroup?: string;
47
+ downloads?: components["schemas"]["ProductDownload"][];
48
+ ean?: string;
49
+ extensions?: {
50
+ novuSeoUrls?: GenericRecord;
51
+ variants?: GenericRecord;
52
+ };
53
+ height?: number;
54
+ id: string;
55
+ isCloseout?: boolean;
56
+ isNew?: boolean;
57
+ keywords?: string;
58
+ length?: number;
59
+ mainCategories?: components["schemas"]["MainCategory"][];
60
+ manufacturer?: components["schemas"]["ProductManufacturer"];
61
+ manufacturerId?: string;
62
+ manufacturerNumber?: string;
63
+ markAsTopseller?: boolean;
64
+ maxPurchase?: number;
65
+ media?: components["schemas"]["ProductMedia"][];
66
+ metaDescription?: string;
67
+ metaTitle?: string;
68
+ minPurchase?: number;
69
+ name: string;
70
+ readonly optionIds?: string[];
71
+ options?: components["schemas"]["PropertyGroupOption"][];
72
+ packUnit?: string;
73
+ packUnitPlural?: string;
74
+ parent?: components["schemas"]["Product"];
75
+ parentId?: string;
76
+ parentVersionId?: string;
77
+ productManufacturerVersionId?: string;
78
+ productMediaVersionId?: string;
79
+ productNumber: string;
80
+ productReviews?: components["schemas"]["ProductReview"][];
81
+ properties?: components["schemas"]["PropertyGroupOption"][];
82
+ readonly propertyIds?: string[];
83
+ purchaseSteps?: number;
84
+ purchaseUnit?: number;
85
+ readonly ratingAverage?: number;
86
+ referenceUnit?: number;
87
+ releaseDate?: string;
88
+ restockTime?: number;
89
+ readonly sales?: number;
90
+ seoCategory: components["schemas"]["Category"];
91
+ seoUrls?: components["schemas"]["SeoUrl"][];
92
+ shippingFree?: boolean;
93
+ sortedProperties?: GenericRecord;
94
+ readonly states?: string[];
95
+ stock: number;
96
+ readonly streamIds?: string[];
97
+ streams?: components["schemas"]["ProductStream"][];
98
+ readonly tagIds?: string[];
99
+ tags?: components["schemas"]["Tag"][];
100
+ tax?: components["schemas"]["Tax"];
101
+ taxId: string;
102
+ translated: {
103
+ canonicalProductId: string;
104
+ canonicalProductVersionId: string;
105
+ cmsPageId: string;
106
+ cmsPageVersionId: string;
107
+ coverId: string;
108
+ deliveryTimeId: string;
109
+ description: string;
110
+ displayGroup: string;
111
+ ean: string;
112
+ keywords: string;
113
+ manufacturerId: string;
114
+ manufacturerNumber: string;
115
+ metaDescription: string;
116
+ metaTitle: string;
117
+ name: string;
118
+ packUnit: string;
119
+ packUnitPlural: string;
120
+ parentId: string;
121
+ parentVersionId: string;
122
+ productManufacturerVersionId: string;
123
+ productMediaVersionId: string;
124
+ productNumber: string;
125
+ releaseDate: string;
126
+ taxId: string;
127
+ unitId: string;
128
+ versionId: string;
129
+ };
130
+ unit?: components["schemas"]["Unit"];
131
+ unitId?: string;
132
+ readonly updatedAt?: string;
133
+ variantListingConfig?: {
134
+ displayParent?: boolean;
135
+ } | null;
136
+ versionId?: string;
137
+ weight?: number;
138
+ width?: number;
139
+ } | undefined;
140
+ export declare function useProductVariantForOptions<S extends Schemas>(product: MaybeRef<DetailProduct<S>>, optionIds: MaybeRef<string[]>): ComputedRef<{
141
+ active?: boolean;
142
+ apiAlias: "product";
143
+ readonly available?: boolean;
144
+ readonly availableStock?: number;
145
+ calculatedCheapestPrice?: {
146
+ apiAlias?: "calculated_cheapest_price";
147
+ hasRange?: boolean;
148
+ listPrice?: components["schemas"]["ListPrice"] | null;
149
+ quantity?: number;
150
+ referencePrice?: components["schemas"]["ReferencePrice"] | null;
151
+ regulationPrice?: {
152
+ price: number;
153
+ } | null;
154
+ totalPrice?: number;
155
+ unitPrice?: number;
156
+ variantId?: string | null;
157
+ };
158
+ calculatedMaxPurchase?: number;
159
+ calculatedPrice: components["schemas"]["CalculatedPrice"];
160
+ calculatedPrices: components["schemas"]["CalculatedPrice"][];
161
+ canonicalProduct?: components["schemas"]["Product"];
162
+ canonicalProductId?: string;
163
+ canonicalProductVersionId?: string;
164
+ categories?: components["schemas"]["Category"][];
165
+ categoriesRo?: components["schemas"]["Category"][];
166
+ readonly categoryIds?: string[];
167
+ readonly categoryTree?: string[];
168
+ readonly childCount?: number;
169
+ children?: components["schemas"]["Product"][];
170
+ cmsPage?: components["schemas"]["CmsPage"];
171
+ cmsPageId?: string;
172
+ cmsPageVersionId?: string;
173
+ configuratorSettings?: components["schemas"]["ProductConfiguratorSetting"][];
174
+ cover?: components["schemas"]["ProductMedia"];
175
+ coverId?: string;
176
+ readonly createdAt?: string;
177
+ crossSellings?: components["schemas"]["ProductCrossSelling"][];
178
+ customFields?: GenericRecord;
179
+ deliveryTime?: components["schemas"]["DeliveryTime"];
180
+ deliveryTimeId?: string;
181
+ description?: string;
182
+ readonly displayGroup?: string;
183
+ downloads?: components["schemas"]["ProductDownload"][];
184
+ ean?: string;
185
+ extensions?: {
186
+ novuSeoUrls?: GenericRecord;
187
+ variants?: GenericRecord;
188
+ };
189
+ height?: number;
190
+ id: string;
191
+ isCloseout?: boolean;
192
+ isNew?: boolean;
193
+ keywords?: string;
194
+ length?: number;
195
+ mainCategories?: components["schemas"]["MainCategory"][];
196
+ manufacturer?: components["schemas"]["ProductManufacturer"];
197
+ manufacturerId?: string;
198
+ manufacturerNumber?: string;
199
+ markAsTopseller?: boolean;
200
+ maxPurchase?: number;
201
+ media?: components["schemas"]["ProductMedia"][];
202
+ metaDescription?: string;
203
+ metaTitle?: string;
204
+ minPurchase?: number;
205
+ name: string;
206
+ readonly optionIds?: string[];
207
+ options?: components["schemas"]["PropertyGroupOption"][];
208
+ packUnit?: string;
209
+ packUnitPlural?: string;
210
+ parent?: components["schemas"]["Product"];
211
+ parentId?: string;
212
+ parentVersionId?: string;
213
+ productManufacturerVersionId?: string;
214
+ productMediaVersionId?: string;
215
+ productNumber: string;
216
+ productReviews?: components["schemas"]["ProductReview"][];
217
+ properties?: components["schemas"]["PropertyGroupOption"][];
218
+ readonly propertyIds?: string[];
219
+ purchaseSteps?: number;
220
+ purchaseUnit?: number;
221
+ readonly ratingAverage?: number;
222
+ referenceUnit?: number;
223
+ releaseDate?: string;
224
+ restockTime?: number;
225
+ readonly sales?: number;
226
+ seoCategory: components["schemas"]["Category"];
227
+ seoUrls?: components["schemas"]["SeoUrl"][];
228
+ shippingFree?: boolean;
229
+ sortedProperties?: GenericRecord;
230
+ readonly states?: string[];
231
+ stock: number;
232
+ readonly streamIds?: string[];
233
+ streams?: components["schemas"]["ProductStream"][];
234
+ readonly tagIds?: string[];
235
+ tags?: components["schemas"]["Tag"][];
236
+ tax?: components["schemas"]["Tax"];
237
+ taxId: string;
238
+ translated: {
239
+ canonicalProductId: string;
240
+ canonicalProductVersionId: string;
241
+ cmsPageId: string;
242
+ cmsPageVersionId: string;
243
+ coverId: string;
244
+ deliveryTimeId: string;
245
+ description: string;
246
+ displayGroup: string;
247
+ ean: string;
248
+ keywords: string;
249
+ manufacturerId: string;
250
+ manufacturerNumber: string;
251
+ metaDescription: string;
252
+ metaTitle: string;
253
+ name: string;
254
+ packUnit: string;
255
+ packUnitPlural: string;
256
+ parentId: string;
257
+ parentVersionId: string;
258
+ productManufacturerVersionId: string;
259
+ productMediaVersionId: string;
260
+ productNumber: string;
261
+ releaseDate: string;
262
+ taxId: string;
263
+ unitId: string;
264
+ versionId: string;
265
+ };
266
+ unit?: components["schemas"]["Unit"];
267
+ unitId?: string;
268
+ readonly updatedAt?: string;
269
+ variantListingConfig?: {
270
+ displayParent?: boolean;
271
+ } | null;
272
+ versionId?: string;
273
+ weight?: number;
274
+ width?: number;
275
+ } | undefined>;
276
+ export {};
@@ -0,0 +1,7 @@
1
+ import { operations } from '../../api-types/storeApiTypes.d.ts';
2
+ import { QueryKey, UseQueryOptions } from '@tanstack/vue-query';
3
+ import { OperationProp } from '@teamnovu/kit-shopware-api-client';
4
+ export type OperationKey = keyof operations;
5
+ export type OperationBody<Operations extends operations, K extends OperationKey> = OperationProp<Operations, K, 'body'>;
6
+ export type OperationResponse<Operations extends operations, K extends OperationKey> = OperationProp<Operations, K, 'response'>;
7
+ export type Options<Operations extends operations, K extends OperationKey, QK extends QueryKey = QueryKey> = UseQueryOptions<OperationResponse<Operations, K>, Error, OperationResponse<Operations, K>, OperationResponse<Operations, K>, QK>;
@@ -0,0 +1,21 @@
1
+ import { Schemas } from '../api-types/storeApiTypes.d.ts';
2
+ import { MaybeRef, Ref, ComputedRef } from 'vue';
3
+ interface PaginationOptions {
4
+ page?: MaybeRef<number>;
5
+ total?: MaybeRef<number>;
6
+ limit?: MaybeRef<number>;
7
+ }
8
+ export declare function usePagination(opts?: PaginationOptions): {
9
+ page: number;
10
+ total: Ref<number, number>;
11
+ limit: Ref<number | undefined, number | undefined>;
12
+ pageCount: ComputedRef<number>;
13
+ isLastPage: ComputedRef<boolean>;
14
+ isFirstPage: ComputedRef<boolean>;
15
+ usePaginationSync: (data: MaybeRef<Schemas["EntitySearchResult"]>) => void;
16
+ queryOptions: ComputedRef<{
17
+ p: number;
18
+ limit: number | undefined;
19
+ }>;
20
+ };
21
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const relativizeSeoUrl: (seoUrl: string) => string;
2
+ export declare const absolutizeSeoUrl: (seoUrl: string) => string;
File without changes
package/docker/types.sh CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-shopware-composables",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A collection of composables for the Shopware API",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",
@@ -13,14 +13,8 @@
13
13
  },
14
14
  "peerDependencies": {
15
15
  "@tanstack/vue-query": "^5.0.0",
16
- "@teamnovu/kit-shopware-api-client": "workspace:*",
17
- "vue": "^3.0.0"
18
- },
19
- "scripts": {
20
- "build": "vite build",
21
- "watch": "NODE_ENV=development vite build --watch",
22
- "gen-types": "bash ./docker/types.sh",
23
- "lint": "eslint --fix --ignore-pattern 'dist/**' ."
16
+ "vue": "^3.0.0",
17
+ "@teamnovu/kit-shopware-api-client": "0.0.3"
24
18
  },
25
19
  "repository": {
26
20
  "type": "git",
@@ -45,5 +39,11 @@
45
39
  "eslint-plugin-import": "^2.31.0",
46
40
  "typescript-eslint": "^8.30.1",
47
41
  "vitest": "^3.1.2"
42
+ },
43
+ "scripts": {
44
+ "build": "vite build",
45
+ "watch": "NODE_ENV=development vite build --watch",
46
+ "gen-types": "bash ./docker/types.sh",
47
+ "lint": "eslint --fix --ignore-pattern 'dist/**' ."
48
48
  }
49
49
  }
@@ -0,0 +1,48 @@
1
+ import { operations } from '#store-types'
2
+ import { MutationOptions, useMutation, useQueryClient } from '@tanstack/vue-query'
3
+ import { useShopwareQueryClient } from '../inject'
4
+ import { cartKeys } from '../keys'
5
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
6
+
7
+ const addCartItemOperation = 'addLineItem post /checkout/cart/line-item' satisfies OperationKey
8
+
9
+ type LineItem<Operations extends operations> = OperationBody<
10
+ Operations,
11
+ typeof addCartItemOperation
12
+ >['items'][number]
13
+
14
+ type LineItemPayload<Operations extends operations> =
15
+ Partial<Omit<LineItem<Operations>, 'id' | 'quantity' | 'type'>> &
16
+ Required<Pick<LineItem<Operations>, 'id' | 'quantity' | 'type'>>
17
+
18
+ type Body<Operations extends operations> = Omit<
19
+ OperationBody<Operations, typeof addCartItemOperation>,
20
+ 'items'
21
+ > & {
22
+ items: LineItemPayload<Operations>[]
23
+ }
24
+
25
+ export function useCartAddItemMutation<Operations extends operations>(
26
+ mutationOptions: MutationOptions<
27
+ OperationResponse<Operations, typeof addCartItemOperation>,
28
+ unknown,
29
+ Body<Operations>
30
+ >,
31
+ ) {
32
+ const client = useShopwareQueryClient<Operations>()
33
+ const queryClient = useQueryClient()
34
+
35
+ return useMutation({
36
+ ...mutationOptions,
37
+ mutationFn: async (body: Body<Operations>) => {
38
+ return client.query(addCartItemOperation, {
39
+ body: body as OperationBody<Operations, typeof addCartItemOperation>,
40
+ })
41
+ },
42
+ onSuccess: (newCart, variables, context) => {
43
+ queryClient.setQueryData(cartKeys.get(), newCart)
44
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
45
+ mutationOptions.onSuccess?.(newCart, variables, context)
46
+ },
47
+ })
48
+ }
@@ -0,0 +1,19 @@
1
+ import { operations } from '#store-types'
2
+ import { queryOptions } from '@tanstack/vue-query'
3
+ import { useShopwareQueryClient } from '../inject'
4
+ import { cartKeys } from '../keys'
5
+ import type { OperationKey } from '../types/query'
6
+
7
+ const readCartOperation = 'readCart get /checkout/cart' satisfies OperationKey
8
+
9
+ export function useCartQueryOptions<Operations extends operations>() {
10
+ const client = useShopwareQueryClient<Operations>()
11
+ const queryKey = cartKeys.get()
12
+
13
+ return queryOptions({
14
+ queryKey,
15
+ queryFn: async () => {
16
+ return client.query(readCartOperation)
17
+ },
18
+ })
19
+ }
@@ -0,0 +1,32 @@
1
+ import { operations } from '#store-types'
2
+ import { MutationOptions, useMutation, useQueryClient } from '@tanstack/vue-query'
3
+ import { useShopwareQueryClient } from '../inject'
4
+ import { cartKeys } from '../keys'
5
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
6
+
7
+ const removeCartItemOperation = 'removeLineItem post /checkout/cart/line-item/delete' satisfies OperationKey
8
+
9
+ export function useCartRemoveItemMutation<Operations extends operations>(
10
+ mutationOptions?: MutationOptions<
11
+ OperationResponse<Operations, typeof removeCartItemOperation>,
12
+ unknown,
13
+ OperationBody<Operations, typeof removeCartItemOperation>
14
+ >,
15
+ ) {
16
+ const client = useShopwareQueryClient<Operations>()
17
+ const queryClient = useQueryClient()
18
+
19
+ return useMutation({
20
+ ...mutationOptions,
21
+ mutationFn: async (body: OperationBody<Operations, typeof removeCartItemOperation>) => {
22
+ return client.query(removeCartItemOperation, {
23
+ body: body as OperationBody<Operations, typeof removeCartItemOperation>,
24
+ })
25
+ },
26
+ onSuccess: (newCart, variables, context) => {
27
+ queryClient.setQueryData(cartKeys.get(), newCart)
28
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
29
+ mutationOptions?.onSuccess?.(newCart, variables, context)
30
+ },
31
+ })
32
+ }
@@ -0,0 +1,48 @@
1
+ import { operations } from '#store-types'
2
+ import { MutationOptions, useMutation, useQueryClient } from '@tanstack/vue-query'
3
+ import { useShopwareQueryClient } from '../inject'
4
+ import { cartKeys } from '../keys'
5
+ import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
6
+
7
+ const updateCartItemOperation = 'updateLineItem patch /checkout/cart/line-item' satisfies OperationKey
8
+
9
+ type LineItem<Operations extends operations> = OperationBody<
10
+ Operations,
11
+ typeof updateCartItemOperation
12
+ >['items'][number]
13
+
14
+ type LineItemPayload<Operations extends operations> =
15
+ Partial<Omit<LineItem<Operations>, 'id' | 'quantity' | 'type'>> &
16
+ Required<Pick<LineItem<Operations>, 'id' | 'quantity' | 'type'>>
17
+
18
+ type Body<Operations extends operations> = Omit<
19
+ OperationBody<Operations, typeof updateCartItemOperation>,
20
+ 'items'
21
+ > & {
22
+ items: LineItemPayload<Operations>[]
23
+ }
24
+
25
+ export function useCartUpdateItemMutation<Operations extends operations>(
26
+ mutationOptions?: MutationOptions<
27
+ OperationResponse<Operations, typeof updateCartItemOperation>,
28
+ unknown,
29
+ Body<Operations>
30
+ >,
31
+ ) {
32
+ const client = useShopwareQueryClient<Operations>()
33
+ const queryClient = useQueryClient()
34
+
35
+ return useMutation({
36
+ ...mutationOptions,
37
+ mutationFn: async (body: Body<Operations>) => {
38
+ return client.query(updateCartItemOperation, {
39
+ body: body as OperationBody<Operations, typeof updateCartItemOperation>,
40
+ })
41
+ },
42
+ onSuccess: (newCart, variables, context) => {
43
+ queryClient.setQueryData(cartKeys.get(), newCart)
44
+ // queryClient.invalidateQueries({ queryKey: cartKeys.get() })
45
+ mutationOptions?.onSuccess?.(newCart, variables, context)
46
+ },
47
+ })
48
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import type { Schemas as BaseSchemas, operations } from '#store-types'
2
+ import { useCartAddItemMutation } from './cart/useCartAddItemMutation'
3
+ import { useCartQueryOptions } from './cart/useCartQueryOptions'
4
+ import { useCartRemoveItemMutation } from './cart/useCartRemoveItemMutation'
5
+ import { useCartUpdateItemMutation } from './cart/useCartUpdateItemMutation'
2
6
  import { useContextOptions } from './context/useContextOptions'
3
7
  import { useContextUpdate } from './context/useContextUpdate'
4
8
  import { useCategoryQueryOptions } from './products/useCategoryQueryOptions'
@@ -21,4 +25,8 @@ export default class ShopwareComposables<Operations extends operations, Schemas
21
25
  useContextUpdate = useContextUpdate<Operations>
22
26
  useProductQueryOptions = useProductQueryOptions<Operations>
23
27
  useProductVariantForOptions = useProductVariantForOptions<Schemas>
28
+ useCartQueryOptions = useCartQueryOptions<Operations>
29
+ useCartUpdateItemMutation = useCartUpdateItemMutation<Operations>
30
+ useCartRemoveItemMutation = useCartRemoveItemMutation<Operations>
31
+ useCartAddItemMutation = useCartAddItemMutation<Operations>
24
32
  }
package/src/keys.ts CHANGED
@@ -40,3 +40,7 @@ export const productKeys = {
40
40
  },
41
41
  ] as const,
42
42
  }
43
+
44
+ export const cartKeys = {
45
+ get: () => ['cart'] as const,
46
+ }