@teamnovu/kit-shopware-composables 0.0.2 → 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.
- package/dist/cart/useCartAddItemMutation.d.ts +12 -0
- package/dist/cart/useCartQueryOptions.d.ts +9 -0
- package/dist/cart/useCartRemoveItemMutation.d.ts +7 -0
- package/dist/cart/useCartUpdateItemMutation.d.ts +12 -0
- package/dist/index.d.ts +34 -1
- package/dist/index.mjs +218 -161
- package/dist/keys.d.ts +3 -0
- package/dist/products/useProductPrice.d.ts +2 -1
- package/package.json +2 -2
- package/src/cart/useCartAddItemMutation.ts +48 -0
- package/src/cart/useCartQueryOptions.ts +19 -0
- package/src/cart/useCartRemoveItemMutation.ts +32 -0
- package/src/cart/useCartUpdateItemMutation.ts +48 -0
- package/src/index.ts +8 -0
- package/src/keys.ts +4 -0
- package/src/products/useProductListingQueryOptions.ts +1 -0
- package/src/products/useProductPrice.ts +3 -2
- package/src/products/useProductQueryOptions.ts +1 -0
- package/src/products/useProductVariantForOptions.ts +8 -2
- package/eslint.config.mjs +0 -84
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { operations } from '../../api-types/storeApiTypes.d.ts';
|
|
2
|
+
import { MutationOptions, UseMutationReturnType, MutationObserverIdleResult, MutationObserverLoadingResult, MutationObserverErrorResult, MutationObserverSuccessResult } from '@tanstack/vue-query';
|
|
3
|
+
import { OperationBody, OperationResponse } from '../types/query';
|
|
4
|
+
import { OperationProp } from '@teamnovu/kit-shopware-api-client';
|
|
5
|
+
declare const addCartItemOperation = "addLineItem post /checkout/cart/line-item";
|
|
6
|
+
type LineItem<Operations extends operations> = OperationBody<Operations, typeof addCartItemOperation>['items'][number];
|
|
7
|
+
type LineItemPayload<Operations extends operations> = Partial<Omit<LineItem<Operations>, 'id' | 'quantity' | 'type'>> & Required<Pick<LineItem<Operations>, 'id' | 'quantity' | 'type'>>;
|
|
8
|
+
type Body<Operations extends operations> = Omit<OperationBody<Operations, typeof addCartItemOperation>, 'items'> & {
|
|
9
|
+
items: LineItemPayload<Operations>[];
|
|
10
|
+
};
|
|
11
|
+
export declare function useCartAddItemMutation<Operations extends operations>(mutationOptions: MutationOptions<OperationResponse<Operations, typeof addCartItemOperation>, unknown, Body<Operations>>): UseMutationReturnType<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset">>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { operations } from '../../api-types/storeApiTypes.d.ts';
|
|
2
|
+
import { UndefinedInitialQueryOptions } from '@tanstack/vue-query';
|
|
3
|
+
import { OperationProp } from '@teamnovu/kit-shopware-api-client';
|
|
4
|
+
export declare function useCartQueryOptions<Operations extends operations>(): UndefinedInitialQueryOptions<OperationProp<operations & Operations, "readCart get /checkout/cart", "response">, Error, OperationProp<operations & Operations, "readCart get /checkout/cart", "response">, readonly ["cart"]> & {
|
|
5
|
+
queryKey: readonly ["cart"] & {
|
|
6
|
+
[dataTagSymbol]: OperationProp<operations & Operations, "readCart get /checkout/cart", "response">;
|
|
7
|
+
[dataTagErrorSymbol]: Error;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { operations } from '../../api-types/storeApiTypes.d.ts';
|
|
2
|
+
import { MutationOptions, UseMutationReturnType, MutationObserverIdleResult, MutationObserverLoadingResult, MutationObserverErrorResult, MutationObserverSuccessResult } from '@tanstack/vue-query';
|
|
3
|
+
import { OperationBody, OperationResponse } from '../types/query';
|
|
4
|
+
import { OperationProp } from '@teamnovu/kit-shopware-api-client';
|
|
5
|
+
declare const removeCartItemOperation = "removeLineItem post /checkout/cart/line-item/delete";
|
|
6
|
+
export declare function useCartRemoveItemMutation<Operations extends operations>(mutationOptions?: MutationOptions<OperationResponse<Operations, typeof removeCartItemOperation>, unknown, OperationBody<Operations, typeof removeCartItemOperation>>): UseMutationReturnType<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset">>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { operations } from '../../api-types/storeApiTypes.d.ts';
|
|
2
|
+
import { MutationOptions, UseMutationReturnType, MutationObserverIdleResult, MutationObserverLoadingResult, MutationObserverErrorResult, MutationObserverSuccessResult } from '@tanstack/vue-query';
|
|
3
|
+
import { OperationBody, OperationResponse } from '../types/query';
|
|
4
|
+
import { OperationProp } from '@teamnovu/kit-shopware-api-client';
|
|
5
|
+
declare const updateCartItemOperation = "updateLineItem patch /checkout/cart/line-item";
|
|
6
|
+
type LineItem<Operations extends operations> = OperationBody<Operations, typeof updateCartItemOperation>['items'][number];
|
|
7
|
+
type LineItemPayload<Operations extends operations> = Partial<Omit<LineItem<Operations>, 'id' | 'quantity' | 'type'>> & Required<Pick<LineItem<Operations>, 'id' | 'quantity' | 'type'>>;
|
|
8
|
+
type Body<Operations extends operations> = Omit<OperationBody<Operations, typeof updateCartItemOperation>, 'items'> & {
|
|
9
|
+
items: LineItemPayload<Operations>[];
|
|
10
|
+
};
|
|
11
|
+
export declare function useCartUpdateItemMutation<Operations extends operations>(mutationOptions?: MutationOptions<OperationResponse<Operations, typeof updateCartItemOperation>, unknown, Body<Operations>>): UseMutationReturnType<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Body<Operations>, unknown>, "mutate" | "reset">>;
|
|
12
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schemas as BaseSchemas, operations, components, GenericRecord } from '../api-types/storeApiTypes.d.ts';
|
|
2
2
|
import { MaybeRef, ComputedRef } from 'vue';
|
|
3
3
|
import { OperationProp } from '@teamnovu/kit-shopware-api-client';
|
|
4
|
-
import { UndefinedInitialQueryOptions, UseMutationReturnType, MutationObserverIdleResult, MutationObserverLoadingResult, MutationObserverErrorResult, MutationObserverSuccessResult } from '@tanstack/vue-query';
|
|
4
|
+
import { UndefinedInitialQueryOptions, UseMutationReturnType, MutationObserverIdleResult, MutationObserverLoadingResult, MutationObserverErrorResult, MutationObserverSuccessResult, MutationOptions } from '@tanstack/vue-query';
|
|
5
5
|
export * from './general/useSeoUrl';
|
|
6
6
|
export * from './inject';
|
|
7
7
|
export * from './keys';
|
|
@@ -187,4 +187,37 @@ export default class ShopwareComposables<Operations extends operations, Schemas
|
|
|
187
187
|
weight?: number;
|
|
188
188
|
width?: number;
|
|
189
189
|
} | undefined>;
|
|
190
|
+
useCartQueryOptions: () => UndefinedInitialQueryOptions<OperationProp<operations & Operations, "readCart get /checkout/cart", "response">, Error, OperationProp<operations & Operations, "readCart get /checkout/cart", "response">, readonly ["cart"]> & {
|
|
191
|
+
queryKey: readonly ["cart"] & {
|
|
192
|
+
[dataTagSymbol]: OperationProp<operations & Operations, "readCart get /checkout/cart", "response">;
|
|
193
|
+
[dataTagErrorSymbol]: Error;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
useCartUpdateItemMutation: (mutationOptions?: MutationOptions<OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
197
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
198
|
+
}, unknown> | undefined) => UseMutationReturnType<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
199
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
200
|
+
}, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
201
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
202
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
203
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
204
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
205
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
206
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "updateLineItem patch /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">, "items"> & {
|
|
207
|
+
items: (Partial<Omit< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "updateLineItem patch /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
208
|
+
}, unknown>, "mutate" | "reset">>;
|
|
209
|
+
useCartRemoveItemMutation: (mutationOptions?: MutationOptions<OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown> | undefined) => UseMutationReturnType<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "removeLineItem post /checkout/cart/line-item/delete", "response">, unknown, OperationProp<Operations, "removeLineItem post /checkout/cart/line-item/delete", "body">, unknown>, "mutate" | "reset">>;
|
|
210
|
+
useCartAddItemMutation: (mutationOptions: MutationOptions<OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
211
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
212
|
+
}, unknown>) => UseMutationReturnType<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
213
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
214
|
+
}, unknown, Omit< MutationObserverIdleResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
215
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
216
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverLoadingResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
217
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
218
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverErrorResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
219
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
220
|
+
}, unknown>, "mutate" | "reset"> | Omit< MutationObserverSuccessResult<OperationProp<operations & Operations, "addLineItem post /checkout/cart/line-item", "response">, unknown, Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">, "items"> & {
|
|
221
|
+
items: (Partial<Omit< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">> & Required<Pick< OperationProp<Operations, "addLineItem post /checkout/cart/line-item", "body">["items"][number], "id" | "quantity" | "type">>)[];
|
|
222
|
+
}, unknown>, "mutate" | "reset">>;
|
|
190
223
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,247 +1,304 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import { inject as $, unref as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
1
|
+
var R = Object.defineProperty;
|
|
2
|
+
var V = (e, t, r) => t in e ? R(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var g = (e, t, r) => V(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { useQueryClient as M, useMutation as h, queryOptions as v } from "@tanstack/vue-query";
|
|
5
|
+
import { inject as $, unref as l, computed as o, reactive as z, watch as K, toRef as b } from "vue";
|
|
6
|
+
const A = Symbol("shopwareClient");
|
|
7
|
+
function P() {
|
|
8
|
+
const e = $(A);
|
|
9
|
+
if (!e)
|
|
10
10
|
throw new Error("Shopware client not provided!");
|
|
11
|
-
return
|
|
11
|
+
return e;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const j = {
|
|
14
14
|
all: () => ["context"]
|
|
15
|
-
},
|
|
15
|
+
}, Q = {
|
|
16
16
|
all: () => ["category"],
|
|
17
|
-
lists: () => [...
|
|
18
|
-
list: (
|
|
19
|
-
...
|
|
17
|
+
lists: () => [...Q.all(), "list"],
|
|
18
|
+
list: (e) => [
|
|
19
|
+
...Q.all(),
|
|
20
20
|
"list",
|
|
21
21
|
{
|
|
22
|
-
body:
|
|
22
|
+
body: e
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
25
|
}, m = {
|
|
26
26
|
all: () => ["product"],
|
|
27
27
|
lists: () => [...m.all(), "list"],
|
|
28
|
-
list: (
|
|
28
|
+
list: (e, t) => [
|
|
29
29
|
...m.all(),
|
|
30
30
|
"list",
|
|
31
31
|
{
|
|
32
|
-
url:
|
|
33
|
-
body:
|
|
32
|
+
url: e,
|
|
33
|
+
body: t
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
36
|
details: () => [...m.all(), "detail"],
|
|
37
|
-
detail: (
|
|
37
|
+
detail: (e, t) => [
|
|
38
38
|
...m.all(),
|
|
39
39
|
"detail",
|
|
40
40
|
{
|
|
41
|
-
url:
|
|
42
|
-
body:
|
|
41
|
+
url: e,
|
|
42
|
+
body: t
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
}, q = {
|
|
46
|
+
get: () => ["cart"]
|
|
47
|
+
}, E = "addLineItem post /checkout/cart/line-item";
|
|
48
|
+
function O(e) {
|
|
49
|
+
const t = P(), r = M();
|
|
48
50
|
return h({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
...e,
|
|
52
|
+
mutationFn: async (c) => t.query(E, {
|
|
53
|
+
body: c
|
|
54
|
+
}),
|
|
55
|
+
onSuccess: (c, n, u) => {
|
|
56
|
+
var a;
|
|
57
|
+
r.setQueryData(q.get(), c), (a = e.onSuccess) == null || a.call(e, c, n, u);
|
|
58
|
+
}
|
|
51
59
|
});
|
|
52
60
|
}
|
|
53
|
-
const T = "
|
|
61
|
+
const T = "readCart get /checkout/cart";
|
|
54
62
|
function W() {
|
|
55
|
-
const t =
|
|
56
|
-
return
|
|
57
|
-
|
|
63
|
+
const e = P(), t = q.get();
|
|
64
|
+
return v({
|
|
65
|
+
queryKey: t,
|
|
66
|
+
queryFn: async () => e.query(T)
|
|
58
67
|
});
|
|
59
68
|
}
|
|
60
|
-
const
|
|
61
|
-
function
|
|
62
|
-
const
|
|
69
|
+
const B = "removeLineItem post /checkout/cart/line-item/delete";
|
|
70
|
+
function G(e) {
|
|
71
|
+
const t = P(), r = M();
|
|
63
72
|
return h({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
body:
|
|
67
|
-
})
|
|
73
|
+
...e,
|
|
74
|
+
mutationFn: async (c) => t.query(B, {
|
|
75
|
+
body: c
|
|
76
|
+
}),
|
|
77
|
+
onSuccess: (c, n, u) => {
|
|
78
|
+
var a;
|
|
79
|
+
r.setQueryData(q.get(), c), (a = e == null ? void 0 : e.onSuccess) == null || a.call(e, c, n, u);
|
|
80
|
+
}
|
|
68
81
|
});
|
|
69
82
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, D = (t) => `/${S(t)}`, B = "readCompactProductListing post /novu/headless/product-listing/{seoUrl}";
|
|
74
|
-
function G(t, e) {
|
|
75
|
-
const n = v(), c = m.list(t, e);
|
|
83
|
+
const H = "updateLineItem patch /checkout/cart/line-item";
|
|
84
|
+
function J(e) {
|
|
85
|
+
const t = P(), r = M();
|
|
76
86
|
return h({
|
|
87
|
+
...e,
|
|
88
|
+
mutationFn: async (c) => t.query(H, {
|
|
89
|
+
body: c
|
|
90
|
+
}),
|
|
91
|
+
onSuccess: (c, n, u) => {
|
|
92
|
+
var a;
|
|
93
|
+
r.setQueryData(q.get(), c), (a = e == null ? void 0 : e.onSuccess) == null || a.call(e, c, n, u);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const N = "readContext get /context";
|
|
98
|
+
function X() {
|
|
99
|
+
const e = P();
|
|
100
|
+
return v({
|
|
101
|
+
queryKey: j.all(),
|
|
102
|
+
queryFn: () => e.query(N)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const Y = "updateContext patch /context";
|
|
106
|
+
function Z() {
|
|
107
|
+
const e = P();
|
|
108
|
+
return h({
|
|
109
|
+
mutationFn: async () => e.query(Y)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const D = "readCategoryList post /category";
|
|
113
|
+
function w(e) {
|
|
114
|
+
const t = P(), r = Q.list(e);
|
|
115
|
+
return v({
|
|
116
|
+
queryKey: r,
|
|
117
|
+
queryFn: async () => t.query(D, {
|
|
118
|
+
body: l(e)
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const L = (e) => {
|
|
123
|
+
const t = e.replace(/\/?$/, "");
|
|
124
|
+
return t.startsWith("/") ? t.slice(1) : t;
|
|
125
|
+
}, ie = (e) => `/${L(e)}`, _ = "readCompactProductListing post /novu/headless/product-listing/{seoUrl}";
|
|
126
|
+
function ee(e, t) {
|
|
127
|
+
const r = P(), c = m.list(e, t);
|
|
128
|
+
return v({
|
|
77
129
|
queryKey: c,
|
|
78
|
-
queryFn: async () =>
|
|
79
|
-
params: { seoUrl:
|
|
80
|
-
body:
|
|
130
|
+
queryFn: async () => r.query(_, {
|
|
131
|
+
params: { seoUrl: L(l(e)) },
|
|
132
|
+
body: l(t)
|
|
81
133
|
})
|
|
82
134
|
});
|
|
83
135
|
}
|
|
84
|
-
const
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
return
|
|
136
|
+
const te = "readCustomProductDetail post /novu/headless/product/{seoUrl}";
|
|
137
|
+
function re(e, t) {
|
|
138
|
+
const r = P(), c = m.detail(e, t);
|
|
139
|
+
return v({
|
|
88
140
|
queryKey: c,
|
|
89
|
-
queryFn: async () =>
|
|
90
|
-
params: { seoUrl:
|
|
91
|
-
body:
|
|
141
|
+
queryFn: async () => r.query(te, {
|
|
142
|
+
params: { seoUrl: L(l(e)) },
|
|
143
|
+
body: l(t)
|
|
92
144
|
})
|
|
93
145
|
});
|
|
94
146
|
}
|
|
95
|
-
function
|
|
147
|
+
function ne(e, t) {
|
|
96
148
|
var c;
|
|
97
|
-
const
|
|
98
|
-
return
|
|
99
|
-
var
|
|
100
|
-
return ((
|
|
101
|
-
})) ?? (
|
|
102
|
-
var
|
|
103
|
-
return (
|
|
149
|
+
const r = (c = e.extensions) == null ? void 0 : c.variants;
|
|
150
|
+
return t.length === 0 ? (r == null ? void 0 : r.find((n) => {
|
|
151
|
+
var u;
|
|
152
|
+
return ((u = n.optionIds) == null ? void 0 : u.length) === 0;
|
|
153
|
+
})) ?? (r == null ? void 0 : r[0]) : r == null ? void 0 : r.find((n) => {
|
|
154
|
+
var u;
|
|
155
|
+
return (u = n.optionIds) == null ? void 0 : u.every((a) => t.includes(a));
|
|
104
156
|
});
|
|
105
157
|
}
|
|
106
|
-
function
|
|
107
|
-
return o(() =>
|
|
158
|
+
function ce(e, t) {
|
|
159
|
+
return o(() => ne(l(e), l(t)));
|
|
108
160
|
}
|
|
109
|
-
const
|
|
161
|
+
const se = (e, t) => {
|
|
110
162
|
var c;
|
|
111
|
-
const
|
|
112
|
-
return (
|
|
113
|
-
},
|
|
114
|
-
function
|
|
115
|
-
var
|
|
116
|
-
if (!
|
|
163
|
+
const r = (c = e.extensions) == null ? void 0 : c.novuSeoUrls;
|
|
164
|
+
return (r == null ? void 0 : r[t]) ?? "";
|
|
165
|
+
}, le = (e, t) => o(() => se(l(e), l(t)));
|
|
166
|
+
function k(e) {
|
|
167
|
+
var r;
|
|
168
|
+
if (!e || !((r = e.calculatedPrices) != null && r.length))
|
|
117
169
|
return [];
|
|
118
|
-
const
|
|
119
|
-
return
|
|
120
|
-
label:
|
|
121
|
-
quantity:
|
|
170
|
+
const t = e.calculatedPrices.length;
|
|
171
|
+
return e.calculatedPrices.map(({ unitPrice: c, quantity: n }, u) => ({
|
|
172
|
+
label: u === t - 1 ? `from ${n}` : `to ${n}`,
|
|
173
|
+
quantity: n,
|
|
122
174
|
unitPrice: c
|
|
123
175
|
}));
|
|
124
176
|
}
|
|
125
|
-
function
|
|
126
|
-
const
|
|
127
|
-
var
|
|
128
|
-
return (
|
|
129
|
-
}),
|
|
177
|
+
function ye(e) {
|
|
178
|
+
const t = o(() => {
|
|
179
|
+
var s;
|
|
180
|
+
return (s = e.value) == null ? void 0 : s.calculatedCheapestPrice;
|
|
181
|
+
}), r = o(
|
|
130
182
|
() => {
|
|
131
|
-
var i,
|
|
132
|
-
return (((
|
|
183
|
+
var s, i, d, p, f;
|
|
184
|
+
return (((i = (s = e.value) == null ? void 0 : s.calculatedPrices) == null ? void 0 : i.length) ?? 0) > 0 ? (p = (d = e.value) == null ? void 0 : d.calculatedPrices) == null ? void 0 : p[0] : (f = e.value) == null ? void 0 : f.calculatedPrice;
|
|
133
185
|
}
|
|
134
186
|
), c = o(() => {
|
|
135
|
-
var
|
|
136
|
-
return (
|
|
137
|
-
}),
|
|
138
|
-
var
|
|
139
|
-
return (((
|
|
140
|
-
}),
|
|
187
|
+
var s;
|
|
188
|
+
return (s = r == null ? void 0 : r.value) == null ? void 0 : s.referencePrice;
|
|
189
|
+
}), n = o(() => {
|
|
190
|
+
var s, i;
|
|
191
|
+
return (((i = (s = e.value) == null ? void 0 : s.calculatedPrices) == null ? void 0 : i.length) ?? 0) > 1;
|
|
192
|
+
}), u = o(
|
|
141
193
|
() => {
|
|
142
|
-
var i,
|
|
143
|
-
return !!((
|
|
194
|
+
var s, i, d, p, f, U;
|
|
195
|
+
return !!((s = e.value) != null && s.parentId) && ((d = (i = e.value) == null ? void 0 : i.calculatedCheapestPrice) == null ? void 0 : d.hasRange) && ((p = r == null ? void 0 : r.value) == null ? void 0 : p.unitPrice) !== ((f = t == null ? void 0 : t.value) == null ? void 0 : f.unitPrice) && ((U = t == null ? void 0 : t.value) == null ? void 0 : U.unitPrice);
|
|
144
196
|
}
|
|
145
|
-
),
|
|
197
|
+
), a = o(
|
|
146
198
|
() => {
|
|
147
|
-
var
|
|
148
|
-
return
|
|
199
|
+
var s, i;
|
|
200
|
+
return n.value && k(e.value).length > 1 ? (i = (s = e.value) == null ? void 0 : s.calculatedPrices) == null ? void 0 : i.reduce((d, p) => p.unitPrice < d.unitPrice ? p : d) : r.value;
|
|
149
201
|
}
|
|
150
|
-
),
|
|
202
|
+
), x = o(
|
|
151
203
|
() => {
|
|
152
|
-
var
|
|
153
|
-
return (
|
|
204
|
+
var s;
|
|
205
|
+
return (s = a.value) == null ? void 0 : s.unitPrice;
|
|
154
206
|
}
|
|
155
|
-
),
|
|
207
|
+
), F = o(
|
|
156
208
|
() => {
|
|
157
|
-
var
|
|
158
|
-
return (
|
|
209
|
+
var s;
|
|
210
|
+
return (s = a.value) == null ? void 0 : s.totalPrice;
|
|
159
211
|
}
|
|
160
|
-
),
|
|
161
|
-
() =>
|
|
162
|
-
),
|
|
163
|
-
var
|
|
164
|
-
return !!((
|
|
165
|
-
}),
|
|
212
|
+
), S = o(
|
|
213
|
+
() => a.value
|
|
214
|
+
), I = o(() => {
|
|
215
|
+
var s, i;
|
|
216
|
+
return !!((i = (s = a.value) == null ? void 0 : s.listPrice) != null && i.percentage);
|
|
217
|
+
}), C = o(
|
|
166
218
|
() => {
|
|
167
|
-
var
|
|
168
|
-
return (
|
|
219
|
+
var s, i, d;
|
|
220
|
+
return (d = (i = (s = e.value) == null ? void 0 : s.calculatedPrice) == null ? void 0 : i.regulationPrice) == null ? void 0 : d.price;
|
|
169
221
|
}
|
|
170
|
-
),
|
|
222
|
+
), y = o(() => k(e.value));
|
|
171
223
|
return {
|
|
172
|
-
price:
|
|
173
|
-
totalPrice:
|
|
174
|
-
unitPrice:
|
|
175
|
-
displayFromVariants:
|
|
176
|
-
displayFrom:
|
|
177
|
-
tierPrices:
|
|
224
|
+
price: S,
|
|
225
|
+
totalPrice: F,
|
|
226
|
+
unitPrice: x,
|
|
227
|
+
displayFromVariants: u,
|
|
228
|
+
displayFrom: n,
|
|
229
|
+
tierPrices: y,
|
|
178
230
|
referencePrice: c,
|
|
179
|
-
isListPrice:
|
|
180
|
-
regulationPrice:
|
|
231
|
+
isListPrice: I,
|
|
232
|
+
regulationPrice: C
|
|
181
233
|
};
|
|
182
234
|
}
|
|
183
|
-
function
|
|
184
|
-
const { total:
|
|
235
|
+
function de(e) {
|
|
236
|
+
const { total: t, limit: r, page: c } = e ?? {}, n = z({
|
|
185
237
|
page: c ?? 1,
|
|
186
|
-
total:
|
|
187
|
-
limit:
|
|
188
|
-
}),
|
|
238
|
+
total: t ?? 0,
|
|
239
|
+
limit: r
|
|
240
|
+
}), u = o(() => n.limit === void 0 ? 1 : Math.max(1, Math.ceil(n.total / n.limit))), a = o({
|
|
189
241
|
get() {
|
|
190
|
-
return
|
|
242
|
+
return n.page;
|
|
191
243
|
},
|
|
192
|
-
set(
|
|
193
|
-
|
|
244
|
+
set(C) {
|
|
245
|
+
n.page = Math.max(1, Math.min(l(u), C));
|
|
194
246
|
}
|
|
195
247
|
});
|
|
196
248
|
K(
|
|
197
|
-
[() =>
|
|
198
|
-
([
|
|
199
|
-
|
|
249
|
+
[() => l(u), () => n],
|
|
250
|
+
([C, y]) => {
|
|
251
|
+
n.page = Math.min(C, n.page), n.total = y.total ?? 0, n.limit = y.limit;
|
|
200
252
|
}
|
|
201
253
|
);
|
|
202
|
-
const
|
|
203
|
-
p:
|
|
204
|
-
limit:
|
|
205
|
-
})),
|
|
206
|
-
K(() =>
|
|
207
|
-
|
|
254
|
+
const x = o(() => n.page === l(u)), F = o(() => n.page === 1), S = o(() => ({
|
|
255
|
+
p: n.page,
|
|
256
|
+
limit: n.limit
|
|
257
|
+
})), I = (C) => {
|
|
258
|
+
K(() => l(C), (y) => {
|
|
259
|
+
n.total = (y == null ? void 0 : y.total) ?? 0, n.limit = (y == null ? void 0 : y.limit) ?? 0;
|
|
208
260
|
});
|
|
209
261
|
};
|
|
210
262
|
return {
|
|
211
|
-
page: a
|
|
212
|
-
total:
|
|
213
|
-
limit:
|
|
214
|
-
pageCount:
|
|
215
|
-
isLastPage:
|
|
216
|
-
isFirstPage:
|
|
217
|
-
usePaginationSync:
|
|
263
|
+
page: l(a),
|
|
264
|
+
total: b(n, "total"),
|
|
265
|
+
limit: b(n, "limit"),
|
|
266
|
+
pageCount: u,
|
|
267
|
+
isLastPage: x,
|
|
268
|
+
isFirstPage: F,
|
|
269
|
+
usePaginationSync: I,
|
|
218
270
|
// This can be used to pass the pagination options directly to the query options
|
|
219
|
-
queryOptions:
|
|
271
|
+
queryOptions: S
|
|
220
272
|
};
|
|
221
273
|
}
|
|
222
|
-
class
|
|
274
|
+
class ge {
|
|
223
275
|
constructor() {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
276
|
+
g(this, "useProductListingQueryOptions", ee);
|
|
277
|
+
g(this, "useCategoryQueryOptions", w);
|
|
278
|
+
g(this, "useContextOptions", X);
|
|
279
|
+
g(this, "useContextUpdate", Z);
|
|
280
|
+
g(this, "useProductQueryOptions", re);
|
|
281
|
+
g(this, "useProductVariantForOptions", ce);
|
|
282
|
+
g(this, "useCartQueryOptions", W);
|
|
283
|
+
g(this, "useCartUpdateItemMutation", J);
|
|
284
|
+
g(this, "useCartRemoveItemMutation", G);
|
|
285
|
+
g(this, "useCartAddItemMutation", O);
|
|
230
286
|
}
|
|
231
287
|
}
|
|
232
288
|
export {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
289
|
+
ie as absolutizeSeoUrl,
|
|
290
|
+
q as cartKeys,
|
|
291
|
+
Q as categoryKeys,
|
|
292
|
+
j as contextKeys,
|
|
293
|
+
ge as default,
|
|
294
|
+
ne as getProductVariantForOptions,
|
|
295
|
+
se as getSeoUrl,
|
|
239
296
|
m as productKeys,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
297
|
+
L as relativizeSeoUrl,
|
|
298
|
+
A as shopwareClientKey,
|
|
299
|
+
de as usePagination,
|
|
300
|
+
ye as useProductPrice,
|
|
301
|
+
ce as useProductVariantForOptions,
|
|
302
|
+
le as useSeoUrl,
|
|
303
|
+
P as useShopwareQueryClient
|
|
247
304
|
};
|
package/dist/keys.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export type UseProductPriceReturn = {
|
|
|
40
40
|
regulationPrice: ComputedRef<number | undefined>;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
|
-
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
43
|
+
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
44
|
+
* to expose most useful helpers for price displaying.
|
|
44
45
|
*
|
|
45
46
|
* @public
|
|
46
47
|
* @category Product
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnovu/kit-shopware-composables",
|
|
3
|
-
"version": "0.0.
|
|
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",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@tanstack/vue-query": "^5.0.0",
|
|
16
16
|
"vue": "^3.0.0",
|
|
17
|
-
"@teamnovu/kit-shopware-api-client": "0.0.
|
|
17
|
+
"@teamnovu/kit-shopware-api-client": "0.0.3"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -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
|
@@ -7,6 +7,7 @@ import { productKeys } from '../keys'
|
|
|
7
7
|
import type { OperationBody, OperationKey } from '../types/query'
|
|
8
8
|
import { relativizeSeoUrl } from '../util/url'
|
|
9
9
|
|
|
10
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
10
11
|
const readListingOperation = 'readCompactProductListing post /novu/headless/product-listing/{seoUrl}' satisfies OperationKey
|
|
11
12
|
|
|
12
13
|
export function useProductListingQueryOptions<Operations extends operations>(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copied from:
|
|
3
|
-
* https://github.com/shopware/frontends/blob/main/packages/composables/src/useProductPrice/useProductPrice.ts
|
|
3
|
+
* https://github.com/shopware/frontends/blob/main/packages/composables/src/useProductPrice/useProductPrice.ts
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Schemas } from '#store-types'
|
|
@@ -51,7 +51,8 @@ export type UseProductPriceReturn = {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
54
|
+
* The purpose of the `useProductPrice` function is to abstract the logic
|
|
55
|
+
* to expose most useful helpers for price displaying.
|
|
55
56
|
*
|
|
56
57
|
* @public
|
|
57
58
|
* @category Product
|
|
@@ -7,6 +7,7 @@ import { productKeys } from '../keys'
|
|
|
7
7
|
import type { OperationBody, OperationKey } from '../types/query'
|
|
8
8
|
import { relativizeSeoUrl } from '../util/url'
|
|
9
9
|
|
|
10
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
10
11
|
const readCustomProductDetailOperation = 'readCustomProductDetail post /novu/headless/product/{seoUrl}' satisfies OperationKey
|
|
11
12
|
|
|
12
13
|
export function useProductQueryOptions<Operations extends operations>(
|
|
@@ -4,7 +4,10 @@ import { computed, unref } from 'vue'
|
|
|
4
4
|
|
|
5
5
|
type DetailProduct<S extends Schemas> = S['CustomProductDetailResponse']['product']
|
|
6
6
|
|
|
7
|
-
export function getProductVariantForOptions<S extends Schemas>(
|
|
7
|
+
export function getProductVariantForOptions<S extends Schemas>(
|
|
8
|
+
product: DetailProduct<S>,
|
|
9
|
+
optionIds: string[],
|
|
10
|
+
) {
|
|
8
11
|
const variants = product.extensions?.variants
|
|
9
12
|
|
|
10
13
|
if (optionIds.length === 0) {
|
|
@@ -16,6 +19,9 @@ export function getProductVariantForOptions<S extends Schemas>(product: DetailPr
|
|
|
16
19
|
return variants?.find(v => v.optionIds?.every(optId => optionIds.includes(optId)))
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
export function useProductVariantForOptions<S extends Schemas>(
|
|
22
|
+
export function useProductVariantForOptions<S extends Schemas>(
|
|
23
|
+
product: MaybeRef<DetailProduct<S>>,
|
|
24
|
+
optionIds: MaybeRef<string[]>,
|
|
25
|
+
) {
|
|
20
26
|
return computed(() => getProductVariantForOptions(unref(product), unref(optionIds)))
|
|
21
27
|
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js'
|
|
2
|
-
import pluginStylistic from '@stylistic/eslint-plugin'
|
|
3
|
-
import tseslint from 'typescript-eslint'
|
|
4
|
-
|
|
5
|
-
export default tseslint.config(
|
|
6
|
-
js.configs.recommended,
|
|
7
|
-
tseslint.configs.recommended,
|
|
8
|
-
pluginStylistic.configs['recommended'],
|
|
9
|
-
{
|
|
10
|
-
rules: {
|
|
11
|
-
// stylistic
|
|
12
|
-
// ********************
|
|
13
|
-
'@stylistic/newline-per-chained-call': [
|
|
14
|
-
'error',
|
|
15
|
-
{ ignoreChainWithDepth: 2 },
|
|
16
|
-
],
|
|
17
|
-
'@stylistic/nonblock-statement-body-position': 'error',
|
|
18
|
-
'@stylistic/one-var-declaration-per-line': 'error',
|
|
19
|
-
'@stylistic/operator-linebreak': [
|
|
20
|
-
'error',
|
|
21
|
-
'before',
|
|
22
|
-
{ overrides: { '=': 'none' } },
|
|
23
|
-
],
|
|
24
|
-
'@stylistic/function-paren-newline': ['error', 'multiline-arguments'],
|
|
25
|
-
'@stylistic/dot-location': ['error', 'property'],
|
|
26
|
-
'@stylistic/no-mixed-operators': ['error', { allowSamePrecedence: true }],
|
|
27
|
-
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
28
|
-
'@stylistic/array-bracket-newline': ['error', { multiline: true }],
|
|
29
|
-
'@stylistic/array-element-newline': [
|
|
30
|
-
'error',
|
|
31
|
-
{
|
|
32
|
-
multiline: true,
|
|
33
|
-
consistent: true,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
'@stylistic/max-len': [
|
|
37
|
-
'warn',
|
|
38
|
-
{
|
|
39
|
-
code: 150,
|
|
40
|
-
tabWidth: 2,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
'@stylistic/object-curly-newline': [
|
|
44
|
-
'error',
|
|
45
|
-
{
|
|
46
|
-
multiline: true,
|
|
47
|
-
consistent: true,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
'@stylistic/object-property-newline': [
|
|
51
|
-
'error',
|
|
52
|
-
{ allowAllPropertiesOnSameLine: false },
|
|
53
|
-
],
|
|
54
|
-
|
|
55
|
-
// common
|
|
56
|
-
// ********************
|
|
57
|
-
'no-console': ['error', { allow: ['warn', 'error'] }],
|
|
58
|
-
'prefer-destructuring': [
|
|
59
|
-
'error',
|
|
60
|
-
{
|
|
61
|
-
array: false,
|
|
62
|
-
object: true,
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
'no-unused-vars': 'off',
|
|
66
|
-
'eqeqeq': ['error', 'smart'],
|
|
67
|
-
'no-undef': 'off', // done by typescript
|
|
68
|
-
'@typescript-eslint/consistent-type-imports': 'error',
|
|
69
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
70
|
-
'@typescript-eslint/no-unused-vars': [
|
|
71
|
-
'error',
|
|
72
|
-
{
|
|
73
|
-
args: 'all',
|
|
74
|
-
argsIgnorePattern: '^_',
|
|
75
|
-
caughtErrors: 'all',
|
|
76
|
-
caughtErrorsIgnorePattern: '^_',
|
|
77
|
-
destructuredArrayIgnorePattern: '^_',
|
|
78
|
-
varsIgnorePattern: '^_',
|
|
79
|
-
ignoreRestSiblings: true,
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
)
|