@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.
@@ -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 M = Object.defineProperty;
2
- var b = (t, e, n) => e in t ? M(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var y = (t, e, n) => b(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { queryOptions as h, useMutation as V } from "@tanstack/vue-query";
5
- import { inject as $, unref as a, computed as o, reactive as z, watch as K, toRef as L } from "vue";
6
- const I = Symbol("shopwareClient");
7
- function v() {
8
- const t = $(I);
9
- if (!t)
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 t;
11
+ return e;
12
12
  }
13
- const R = {
13
+ const j = {
14
14
  all: () => ["context"]
15
- }, F = {
15
+ }, Q = {
16
16
  all: () => ["category"],
17
- lists: () => [...F.all(), "list"],
18
- list: (t) => [
19
- ...F.all(),
17
+ lists: () => [...Q.all(), "list"],
18
+ list: (e) => [
19
+ ...Q.all(),
20
20
  "list",
21
21
  {
22
- body: t
22
+ body: e
23
23
  }
24
24
  ]
25
25
  }, m = {
26
26
  all: () => ["product"],
27
27
  lists: () => [...m.all(), "list"],
28
- list: (t, e) => [
28
+ list: (e, t) => [
29
29
  ...m.all(),
30
30
  "list",
31
31
  {
32
- url: t,
33
- body: e
32
+ url: e,
33
+ body: t
34
34
  }
35
35
  ],
36
36
  details: () => [...m.all(), "detail"],
37
- detail: (t, e) => [
37
+ detail: (e, t) => [
38
38
  ...m.all(),
39
39
  "detail",
40
40
  {
41
- url: t,
42
- body: e
41
+ url: e,
42
+ body: t
43
43
  }
44
44
  ]
45
- }, j = "readContext get /context";
46
- function E() {
47
- const t = v();
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
- queryKey: R.all(),
50
- queryFn: () => t.query(j)
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 = "updateContext patch /context";
61
+ const T = "readCart get /checkout/cart";
54
62
  function W() {
55
- const t = v();
56
- return V({
57
- mutationFn: async () => t.query(T)
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 k = "readCategoryList post /category";
61
- function A(t) {
62
- const e = v(), n = F.list(t);
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
- queryKey: n,
65
- queryFn: async () => e.query(k, {
66
- body: a(t)
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 S = (t) => {
71
- const e = t.replace(/\/?$/, "");
72
- return e.startsWith("/") ? e.slice(1) : e;
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 () => n.query(B, {
79
- params: { seoUrl: S(a(t)) },
80
- body: a(e)
130
+ queryFn: async () => r.query(_, {
131
+ params: { seoUrl: L(l(e)) },
132
+ body: l(t)
81
133
  })
82
134
  });
83
135
  }
84
- const H = "readCustomProductDetail post /novu/headless/product/{seoUrl}";
85
- function J(t, e) {
86
- const n = v(), c = m.detail(t, e);
87
- return h({
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 () => n.query(H, {
90
- params: { seoUrl: S(a(t)) },
91
- body: a(e)
141
+ queryFn: async () => r.query(te, {
142
+ params: { seoUrl: L(l(e)) },
143
+ body: l(t)
92
144
  })
93
145
  });
94
146
  }
95
- function N(t, e) {
147
+ function ne(e, t) {
96
148
  var c;
97
- const n = (c = t.extensions) == null ? void 0 : c.variants;
98
- return e.length === 0 ? (n == null ? void 0 : n.find((r) => {
99
- var l;
100
- return ((l = r.optionIds) == null ? void 0 : l.length) === 0;
101
- })) ?? (n == null ? void 0 : n[0]) : n == null ? void 0 : n.find((r) => {
102
- var l;
103
- return (l = r.optionIds) == null ? void 0 : l.every((d) => e.includes(d));
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 X(t, e) {
107
- return o(() => N(a(t), a(e)));
158
+ function ce(e, t) {
159
+ return o(() => ne(l(e), l(t)));
108
160
  }
109
- const Y = (t, e) => {
161
+ const se = (e, t) => {
110
162
  var c;
111
- const n = (c = t.extensions) == null ? void 0 : c.novuSeoUrls;
112
- return (n == null ? void 0 : n[e]) ?? "";
113
- }, tt = (t, e) => o(() => Y(a(t), a(e)));
114
- function Q(t) {
115
- var n;
116
- if (!t || !((n = t.calculatedPrices) != null && n.length))
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 e = t.calculatedPrices.length;
119
- return t.calculatedPrices.map(({ unitPrice: c, quantity: r }, l) => ({
120
- label: l === e - 1 ? `from ${r}` : `to ${r}`,
121
- quantity: r,
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 et(t) {
126
- const e = o(() => {
127
- var i;
128
- return (i = t.value) == null ? void 0 : i.calculatedCheapestPrice;
129
- }), n = o(
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, s, p, P, f;
132
- return (((s = (i = t.value) == null ? void 0 : i.calculatedPrices) == null ? void 0 : s.length) ?? 0) > 0 ? (P = (p = t.value) == null ? void 0 : p.calculatedPrices) == null ? void 0 : P[0] : (f = t.value) == null ? void 0 : f.calculatedPrice;
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 i;
136
- return (i = n == null ? void 0 : n.value) == null ? void 0 : i.referencePrice;
137
- }), r = o(() => {
138
- var i, s;
139
- return (((s = (i = t.value) == null ? void 0 : i.calculatedPrices) == null ? void 0 : s.length) ?? 0) > 1;
140
- }), l = o(
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, s, p, P, f, U;
143
- return !!((i = t.value) != null && i.parentId) && ((p = (s = t.value) == null ? void 0 : s.calculatedCheapestPrice) == null ? void 0 : p.hasRange) && ((P = n == null ? void 0 : n.value) == null ? void 0 : P.unitPrice) !== ((f = e == null ? void 0 : e.value) == null ? void 0 : f.unitPrice) && ((U = e == null ? void 0 : e.value) == null ? void 0 : U.unitPrice);
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
- ), d = o(
197
+ ), a = o(
146
198
  () => {
147
- var i, s;
148
- return r.value && Q(t.value).length > 1 ? (s = (i = t.value) == null ? void 0 : i.calculatedPrices) == null ? void 0 : s.reduce((p, P) => P.unitPrice < p.unitPrice ? P : p) : n.value;
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
- ), C = o(
202
+ ), x = o(
151
203
  () => {
152
- var i;
153
- return (i = d.value) == null ? void 0 : i.unitPrice;
204
+ var s;
205
+ return (s = a.value) == null ? void 0 : s.unitPrice;
154
206
  }
155
- ), O = o(
207
+ ), F = o(
156
208
  () => {
157
- var i;
158
- return (i = d.value) == null ? void 0 : i.totalPrice;
209
+ var s;
210
+ return (s = a.value) == null ? void 0 : s.totalPrice;
159
211
  }
160
- ), x = o(
161
- () => d.value
162
- ), q = o(() => {
163
- var i, s;
164
- return !!((s = (i = d.value) == null ? void 0 : i.listPrice) != null && s.percentage);
165
- }), g = o(
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 i, s, p;
168
- return (p = (s = (i = t.value) == null ? void 0 : i.calculatedPrice) == null ? void 0 : s.regulationPrice) == null ? void 0 : p.price;
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
- ), u = o(() => Q(t.value));
222
+ ), y = o(() => k(e.value));
171
223
  return {
172
- price: x,
173
- totalPrice: O,
174
- unitPrice: C,
175
- displayFromVariants: l,
176
- displayFrom: r,
177
- tierPrices: u,
224
+ price: S,
225
+ totalPrice: F,
226
+ unitPrice: x,
227
+ displayFromVariants: u,
228
+ displayFrom: n,
229
+ tierPrices: y,
178
230
  referencePrice: c,
179
- isListPrice: q,
180
- regulationPrice: g
231
+ isListPrice: I,
232
+ regulationPrice: C
181
233
  };
182
234
  }
183
- function nt(t) {
184
- const { total: e, limit: n, page: c } = t ?? {}, r = z({
235
+ function de(e) {
236
+ const { total: t, limit: r, page: c } = e ?? {}, n = z({
185
237
  page: c ?? 1,
186
- total: e ?? 0,
187
- limit: n
188
- }), l = o(() => r.limit === void 0 ? 1 : Math.max(1, Math.ceil(r.total / r.limit))), d = o({
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 r.page;
242
+ return n.page;
191
243
  },
192
- set(g) {
193
- r.page = Math.max(1, Math.min(a(l), g));
244
+ set(C) {
245
+ n.page = Math.max(1, Math.min(l(u), C));
194
246
  }
195
247
  });
196
248
  K(
197
- [() => a(l), () => r],
198
- ([g, u]) => {
199
- r.page = Math.min(g, r.page), r.total = u.total ?? 0, r.limit = u.limit;
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 C = o(() => r.page === a(l)), O = o(() => r.page === 1), x = o(() => ({
203
- p: r.page,
204
- limit: r.limit
205
- })), q = (g) => {
206
- K(() => a(g), (u) => {
207
- r.total = (u == null ? void 0 : u.total) ?? 0, r.limit = (u == null ? void 0 : u.limit) ?? 0;
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(d),
212
- total: L(r, "total"),
213
- limit: L(r, "limit"),
214
- pageCount: l,
215
- isLastPage: C,
216
- isFirstPage: O,
217
- usePaginationSync: q,
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: x
271
+ queryOptions: S
220
272
  };
221
273
  }
222
- class rt {
274
+ class ge {
223
275
  constructor() {
224
- y(this, "useProductListingQueryOptions", G);
225
- y(this, "useCategoryQueryOptions", A);
226
- y(this, "useContextOptions", E);
227
- y(this, "useContextUpdate", W);
228
- y(this, "useProductQueryOptions", J);
229
- y(this, "useProductVariantForOptions", X);
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
- D as absolutizeSeoUrl,
234
- F as categoryKeys,
235
- R as contextKeys,
236
- rt as default,
237
- N as getProductVariantForOptions,
238
- Y as getSeoUrl,
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
- S as relativizeSeoUrl,
241
- I as shopwareClientKey,
242
- nt as usePagination,
243
- et as useProductPrice,
244
- X as useProductVariantForOptions,
245
- tt as useSeoUrl,
246
- v as useShopwareQueryClient
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
@@ -22,3 +22,6 @@ export declare const productKeys: {
22
22
  readonly body: unknown;
23
23
  }];
24
24
  };
25
+ export declare const cartKeys: {
26
+ get: () => readonly ["cart"];
27
+ };
@@ -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 to expose most useful helpers for price displaying.
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.2",
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.2"
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
@@ -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
+ }
@@ -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#L7
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 to expose most useful helpers for price displaying.
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>(product: DetailProduct<S>, optionIds: string[]) {
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>(product: MaybeRef<DetailProduct<S>>, optionIds: MaybeRef<string[]>) {
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
- )