@brytdesigns/shopify-ajax-cart 1.0.0
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/jsdelivr/api.js +8 -0
- package/dist/jsdelivr/api.js.map +1 -0
- package/dist/jsdelivr/client.js +20 -0
- package/dist/jsdelivr/client.js.map +1 -0
- package/dist/jsdelivr/index.js +94 -0
- package/dist/jsdelivr/index.js.map +1 -0
- package/dist/jsdelivr/mutations/addItems.js +24 -0
- package/dist/jsdelivr/mutations/addItems.js.map +1 -0
- package/dist/jsdelivr/mutations/clearCart.js +39 -0
- package/dist/jsdelivr/mutations/clearCart.js.map +1 -0
- package/dist/jsdelivr/mutations/index.js +18 -0
- package/dist/jsdelivr/mutations/index.js.map +1 -0
- package/dist/jsdelivr/mutations/removeItems.js +44 -0
- package/dist/jsdelivr/mutations/removeItems.js.map +1 -0
- package/dist/jsdelivr/mutations/replaceItem.js +49 -0
- package/dist/jsdelivr/mutations/replaceItem.js.map +1 -0
- package/dist/jsdelivr/mutations/updateAttributes.js +43 -0
- package/dist/jsdelivr/mutations/updateAttributes.js.map +1 -0
- package/dist/jsdelivr/mutations/updateDiscounts.js +28 -0
- package/dist/jsdelivr/mutations/updateDiscounts.js.map +1 -0
- package/dist/jsdelivr/mutations/updateItem.js +69 -0
- package/dist/jsdelivr/mutations/updateItem.js.map +1 -0
- package/dist/jsdelivr/mutations/updateNote.js +40 -0
- package/dist/jsdelivr/mutations/updateNote.js.map +1 -0
- package/dist/jsdelivr/query/cart.js +30 -0
- package/dist/jsdelivr/query/cart.js.map +1 -0
- package/dist/jsdelivr/query/index.js +4 -0
- package/dist/jsdelivr/query/index.js.map +1 -0
- package/dist/jsdelivr/types.js +3 -0
- package/dist/jsdelivr/types.js.map +1 -0
- package/dist/jsdelivr/utils.js +33 -0
- package/dist/jsdelivr/utils.js.map +1 -0
- package/dist/main/api.js +8 -0
- package/dist/main/api.js.map +1 -0
- package/dist/main/client.js +20 -0
- package/dist/main/client.js.map +1 -0
- package/dist/main/index.d.ts +15831 -0
- package/dist/main/index.js +94 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/mutations/addItems.js +24 -0
- package/dist/main/mutations/addItems.js.map +1 -0
- package/dist/main/mutations/clearCart.js +39 -0
- package/dist/main/mutations/clearCart.js.map +1 -0
- package/dist/main/mutations/index.js +18 -0
- package/dist/main/mutations/index.js.map +1 -0
- package/dist/main/mutations/removeItems.js +44 -0
- package/dist/main/mutations/removeItems.js.map +1 -0
- package/dist/main/mutations/replaceItem.js +49 -0
- package/dist/main/mutations/replaceItem.js.map +1 -0
- package/dist/main/mutations/updateAttributes.js +43 -0
- package/dist/main/mutations/updateAttributes.js.map +1 -0
- package/dist/main/mutations/updateDiscounts.js +30 -0
- package/dist/main/mutations/updateDiscounts.js.map +1 -0
- package/dist/main/mutations/updateItem.js +69 -0
- package/dist/main/mutations/updateItem.js.map +1 -0
- package/dist/main/mutations/updateNote.js +40 -0
- package/dist/main/mutations/updateNote.js.map +1 -0
- package/dist/main/query/cart.js +30 -0
- package/dist/main/query/cart.js.map +1 -0
- package/dist/main/query/index.js +4 -0
- package/dist/main/query/index.js.map +1 -0
- package/dist/main/types.js +3 -0
- package/dist/main/types.js.map +1 -0
- package/dist/main/utils.js +33 -0
- package/dist/main/utils.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mergeProps } from 'solid-js';
|
|
2
|
+
import { Cart } from './query/index.js';
|
|
3
|
+
import { UpdateItem, ClearCart, UpdateNote, UpdateAttributes, RemoveItems, AddItems, ReplaceItem, UpdateDiscounts } from './mutations/index.js';
|
|
4
|
+
import { subscribe, getCartDiscountCodes, uniq, getNormalizedAttributes } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const AjaxCart = mergeProps(Cart.query, {
|
|
7
|
+
addItems: AddItems.mutation.mutateAsync,
|
|
8
|
+
addItem: (input) => AddItems.mutation.mutateAsync([input]),
|
|
9
|
+
removeItems: RemoveItems.mutation.mutateAsync,
|
|
10
|
+
removeItem(input) {
|
|
11
|
+
return RemoveItems.mutation.mutateAsync([input]);
|
|
12
|
+
},
|
|
13
|
+
addAttributes(input) {
|
|
14
|
+
const mergedAttributes = getNormalizedAttributes();
|
|
15
|
+
return UpdateAttributes.mutation.mutateAsync({
|
|
16
|
+
...mergedAttributes,
|
|
17
|
+
...input
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
addAttribute(input) {
|
|
21
|
+
const mergedAttributes = getNormalizedAttributes();
|
|
22
|
+
return UpdateAttributes.mutation.mutateAsync({
|
|
23
|
+
...mergedAttributes,
|
|
24
|
+
[input.key]: input.value
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
updateAttributes: UpdateAttributes.mutation.mutateAsync,
|
|
28
|
+
removeAttributes(input) {
|
|
29
|
+
const mergedAttributes = getNormalizedAttributes();
|
|
30
|
+
return UpdateAttributes.mutation.mutateAsync({
|
|
31
|
+
...mergedAttributes,
|
|
32
|
+
...Object.fromEntries(input.map((key) => [key, null]))
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
removeAttribute(key) {
|
|
36
|
+
const mergedAttributes = getNormalizedAttributes();
|
|
37
|
+
return UpdateAttributes.mutation.mutateAsync({
|
|
38
|
+
...mergedAttributes,
|
|
39
|
+
[key]: null
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
updateNote: UpdateNote.mutation.mutateAsync,
|
|
43
|
+
clear: ClearCart.mutation.mutateAsync,
|
|
44
|
+
updateItem: UpdateItem.mutation.mutateAsync,
|
|
45
|
+
async updateItems(input) {
|
|
46
|
+
const results = await Promise.allSettled(
|
|
47
|
+
input.map((i) => UpdateItem.mutation.mutateAsync(i))
|
|
48
|
+
);
|
|
49
|
+
return {
|
|
50
|
+
rejected: results.filter((r) => r.status === "rejected"),
|
|
51
|
+
resolved: results.filter((r) => r.status === "fulfilled")
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
addDiscounts(input) {
|
|
55
|
+
const codes = getCartDiscountCodes();
|
|
56
|
+
return UpdateDiscounts.mutation.mutateAsync(uniq([...codes, ...input]));
|
|
57
|
+
},
|
|
58
|
+
addDiscount(input) {
|
|
59
|
+
const codes = getCartDiscountCodes();
|
|
60
|
+
return UpdateDiscounts.mutation.mutateAsync(uniq([...codes, input]));
|
|
61
|
+
},
|
|
62
|
+
removeDiscounts(input) {
|
|
63
|
+
const codes = getCartDiscountCodes();
|
|
64
|
+
return UpdateDiscounts.mutation.mutateAsync(
|
|
65
|
+
codes.filter((code) => !input.includes(code))
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
removeDiscount(input) {
|
|
69
|
+
const codes = getCartDiscountCodes();
|
|
70
|
+
return UpdateDiscounts.mutation.mutateAsync(
|
|
71
|
+
codes.filter((code) => code !== input)
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
replaceItem(input) {
|
|
75
|
+
return ReplaceItem.mutation.mutateAsync(input);
|
|
76
|
+
},
|
|
77
|
+
async replaceItems(input) {
|
|
78
|
+
const results = await Promise.allSettled(
|
|
79
|
+
input.map((i) => ReplaceItem.mutation.mutateAsync(i))
|
|
80
|
+
);
|
|
81
|
+
return {
|
|
82
|
+
rejected: results.filter((r) => r.status === "rejected"),
|
|
83
|
+
resolved: results.filter((r) => r.status === "fulfilled")
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
subscribe
|
|
87
|
+
});
|
|
88
|
+
if (!window.BrytDesigns) window.BrytDesigns = {};
|
|
89
|
+
window.BrytDesigns.cart = AjaxCart;
|
|
90
|
+
var index_default = AjaxCart;
|
|
91
|
+
|
|
92
|
+
export { index_default as default };
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAsBA,MAAM,QAAA,GAAW,UAAW,CAAA,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A,QAAA,CAAS,IAAI,CAAC;AAAA,KAC9C;AAAA,GACF;AAAA,EACA,eAAe,KAA8B,EAAA;AAC3C,IAAA,MAAM,QAAQ,oBAAqB,EAAA;AACnC,IAAA,OAAO,gBAAgB,QAAS,CAAA,WAAA;AAAA,MAC9B,KAAM,CAAA,MAAA,CAAO,CAAC,IAAA,KAAS,SAAS,KAAK;AAAA,KACvC;AAAA,GACF;AAAA,EACA,YAAY,KAA0B,EAAA;AACpC,IAAO,OAAA,WAAA,CAAY,QAAS,CAAA,WAAA,CAAY,KAAK,CAAA;AAAA,GAC/C;AAAA,EACA,MAAM,aAAa,KAA4B,EAAA;AAC7C,IAAM,MAAA,OAAA,GAAU,MAAM,OAAQ,CAAA,UAAA;AAAA,MAC5B,KAAA,CAAM,IAAI,CAAC,CAAA,KAAM,YAAY,QAAS,CAAA,WAAA,CAAY,CAAC,CAAC;AAAA,KACtD;AACA,IAAO,OAAA;AAAA,MACL,UAAU,OAAQ,CAAA,MAAA,CAAO,CAAC,CAAM,KAAA,CAAA,CAAE,WAAW,UAAU,CAAA;AAAA,MACvD,UAAU,OAAQ,CAAA,MAAA,CAAO,CAAC,CAAM,KAAA,CAAA,CAAE,WAAW,WAAW;AAAA,KAC1D;AAAA,GACF;AAAA,EACA;AACF,CAAC,CAAA;AAaD,IAAI,CAAC,MAAA,CAAO,WAAa,EAAA,MAAA,CAAO,cAAc,EAAC;AAC/C,MAAA,CAAO,YAAY,IAAO,GAAA,QAAA;AAE1B,IAAO,aAAQ,GAAA","file":"index.js","sourcesContent":["import type { CartData } from \"./types\";\n\nimport { mergeProps } from \"solid-js\";\n\nimport { Cart } from \"./query/index.js\";\nimport {\n AddItems,\n RemoveItems,\n UpdateAttributes,\n UpdateDiscounts,\n UpdateItem,\n UpdateNote,\n ClearCart,\n ReplaceItem,\n} from \"./mutations/index.js\";\nimport {\n getNormalizedAttributes,\n subscribe,\n getCartDiscountCodes,\n uniq,\n} from \"./utils.js\";\n\nconst AjaxCart = mergeProps(Cart.query, {\n addItems: AddItems.mutation.mutateAsync,\n addItem: (input: AddItems.Input) => AddItems.mutation.mutateAsync([input]),\n removeItems: RemoveItems.mutation.mutateAsync,\n removeItem(input: RemoveItems.Input) {\n return RemoveItems.mutation.mutateAsync([input]);\n },\n addAttributes(input: UpdateAttributes.Input) {\n const mergedAttributes = getNormalizedAttributes();\n return UpdateAttributes.mutation.mutateAsync({\n ...mergedAttributes,\n ...input,\n });\n },\n addAttribute(input: { key: string; value: UpdateAttributes.Input[string] }) {\n const mergedAttributes = getNormalizedAttributes();\n return UpdateAttributes.mutation.mutateAsync({\n ...mergedAttributes,\n [input.key]: input.value,\n });\n },\n updateAttributes: UpdateAttributes.mutation.mutateAsync,\n removeAttributes(input: string[]) {\n const mergedAttributes = getNormalizedAttributes();\n return UpdateAttributes.mutation.mutateAsync({\n ...mergedAttributes,\n ...Object.fromEntries(input.map((key) => [key, null])),\n });\n },\n removeAttribute(key: string) {\n const mergedAttributes = getNormalizedAttributes();\n return UpdateAttributes.mutation.mutateAsync({\n ...mergedAttributes,\n [key]: null,\n });\n },\n updateNote: UpdateNote.mutation.mutateAsync,\n clear: ClearCart.mutation.mutateAsync,\n updateItem: UpdateItem.mutation.mutateAsync,\n async updateItems(input: UpdateItem.Input[]) {\n const results = await Promise.allSettled(\n input.map((i) => UpdateItem.mutation.mutateAsync(i)),\n );\n return {\n rejected: results.filter((r) => r.status === \"rejected\"),\n resolved: results.filter((r) => r.status === \"fulfilled\"),\n };\n },\n addDiscounts(input: UpdateDiscounts.Input[]) {\n const codes = getCartDiscountCodes();\n return UpdateDiscounts.mutation.mutateAsync(uniq([...codes, ...input]));\n },\n addDiscount(input: UpdateDiscounts.Input) {\n const codes = getCartDiscountCodes();\n return UpdateDiscounts.mutation.mutateAsync(uniq([...codes, input]));\n },\n removeDiscounts(input: UpdateDiscounts.Input[]) {\n const codes = getCartDiscountCodes();\n return UpdateDiscounts.mutation.mutateAsync(\n codes.filter((code) => !input.includes(code)),\n );\n },\n removeDiscount(input: UpdateDiscounts.Input) {\n const codes = getCartDiscountCodes();\n return UpdateDiscounts.mutation.mutateAsync(\n codes.filter((code) => code !== input),\n );\n },\n replaceItem(input: ReplaceItem.Input) {\n return ReplaceItem.mutation.mutateAsync(input);\n },\n async replaceItems(input: ReplaceItem.Input[]) {\n const results = await Promise.allSettled(\n input.map((i) => ReplaceItem.mutation.mutateAsync(i)),\n );\n return {\n rejected: results.filter((r) => r.status === \"rejected\"),\n resolved: results.filter((r) => r.status === \"fulfilled\"),\n };\n },\n subscribe,\n});\n\ndeclare global {\n interface Window {\n BrytDesigns: {\n initialCart: CartData;\n cart: typeof AjaxCart;\n debug?: boolean;\n };\n }\n}\n\n//@ts-ignore\nif (!window.BrytDesigns) window.BrytDesigns = {};\nwindow.BrytDesigns.cart = AjaxCart;\n\nexport default AjaxCart;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (items) => {
|
|
9
|
+
const response = await API.add({ items });
|
|
10
|
+
if (response?.error || !response.data) {
|
|
11
|
+
throw response?.error;
|
|
12
|
+
}
|
|
13
|
+
return response.data;
|
|
14
|
+
},
|
|
15
|
+
onSettled() {
|
|
16
|
+
Cart.invalidate();
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
() => client
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export { mutation };
|
|
23
|
+
//# sourceMappingURL=addItems.js.map
|
|
24
|
+
//# sourceMappingURL=addItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/addItems.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,KAAmB,KAAA;AACpC,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAI,CAAA,EAAE,OAAO,CAAA;AACxC,MAAA,IAAI,QAAU,EAAA,KAAA,IAAS,CAAC,QAAA,CAAS,IAAM,EAAA;AACrC,QAAA,MAAM,QAAU,EAAA,KAAA;AAAA;AAElB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,SAAY,GAAA;AACV,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA;AAClB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"addItems.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = Parameters<typeof API.add>[0][\"items\"][number];\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (items: Input[]) => {\n const response = await API.add({ items });\n if (response?.error || !response.data) {\n throw response?.error;\n }\n return response.data;\n },\n onSettled() {\n Cart.invalidate();\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async () => {
|
|
9
|
+
const response = await API.clear({});
|
|
10
|
+
if (response.error) {
|
|
11
|
+
throw response.error;
|
|
12
|
+
}
|
|
13
|
+
return response.data;
|
|
14
|
+
},
|
|
15
|
+
async onMutate() {
|
|
16
|
+
await Cart.cancel();
|
|
17
|
+
const previousCart = Cart.get();
|
|
18
|
+
Cart.set((old) => ({
|
|
19
|
+
...old,
|
|
20
|
+
item_count: 0,
|
|
21
|
+
items: []
|
|
22
|
+
}));
|
|
23
|
+
return { previousCart };
|
|
24
|
+
},
|
|
25
|
+
onError(_, __, context) {
|
|
26
|
+
if (context?.previousCart) Cart.set(() => context.previousCart);
|
|
27
|
+
Cart.invalidate();
|
|
28
|
+
},
|
|
29
|
+
onSuccess(cart) {
|
|
30
|
+
if (!cart) return Cart.invalidate();
|
|
31
|
+
Cart.set(() => cart);
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
() => client
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export { mutation };
|
|
38
|
+
//# sourceMappingURL=clearCart.js.map
|
|
39
|
+
//# sourceMappingURL=clearCart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/clearCart.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,YAAY,YAAY;AACtB,MAAA,MAAM,QAAW,GAAA,MAAM,GAAI,CAAA,KAAA,CAAM,EAAE,CAAA;AAEnC,MAAA,IAAI,SAAS,KAAO,EAAA;AAClB,QAAA,MAAM,QAAS,CAAA,KAAA;AAAA;AAGjB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,MAAM,QAAW,GAAA;AACf,MAAA,MAAM,KAAK,MAAO,EAAA;AAClB,MAAM,MAAA,YAAA,GAAe,KAAK,GAAI,EAAA;AAE9B,MAAK,IAAA,CAAA,GAAA,CAAI,CAAC,GAAS,MAAA;AAAA,QACjB,GAAG,GAAA;AAAA,QACH,UAAY,EAAA,CAAA;AAAA,QACZ,OAAO;AAAC,OACR,CAAA,CAAA;AAEF,MAAA,OAAO,EAAE,YAAa,EAAA;AAAA,KACxB;AAAA,IACA,OAAA,CAAQ,CAAG,EAAA,EAAA,EAAI,OAAS,EAAA;AACtB,MAAA,IAAI,SAAS,YAAc,EAAA,IAAA,CAAK,GAAI,CAAA,MAAM,QAAQ,YAAY,CAAA;AAC9D,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"clearCart.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = string | null;\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async () => {\n const response = await API.clear({});\n\n if (response.error) {\n throw response.error;\n }\n\n return response.data;\n },\n async onMutate() {\n await Cart.cancel();\n const previousCart = Cart.get();\n\n Cart.set((old) => ({\n ...old,\n item_count: 0,\n items: [],\n }));\n\n return { previousCart };\n },\n onError(_, __, context) {\n if (context?.previousCart) Cart.set(() => context.previousCart);\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as addItems_js from './addItems.js';
|
|
2
|
+
export { addItems_js as AddItems };
|
|
3
|
+
import * as removeItems_js from './removeItems.js';
|
|
4
|
+
export { removeItems_js as RemoveItems };
|
|
5
|
+
import * as updateAttributes_js from './updateAttributes.js';
|
|
6
|
+
export { updateAttributes_js as UpdateAttributes };
|
|
7
|
+
import * as updateDiscounts_js from './updateDiscounts.js';
|
|
8
|
+
export { updateDiscounts_js as UpdateDiscounts };
|
|
9
|
+
import * as updateItem_js from './updateItem.js';
|
|
10
|
+
export { updateItem_js as UpdateItem };
|
|
11
|
+
import * as updateNote_js from './updateNote.js';
|
|
12
|
+
export { updateNote_js as UpdateNote };
|
|
13
|
+
import * as clearCart_js from './clearCart.js';
|
|
14
|
+
export { clearCart_js as ClearCart };
|
|
15
|
+
import * as replaceItem_js from './replaceItem.js';
|
|
16
|
+
export { replaceItem_js as ReplaceItem };
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (items) => {
|
|
9
|
+
const response = await API.update({
|
|
10
|
+
updates: items.reduce(
|
|
11
|
+
(updates, key) => ({ ...updates, [key]: 0 }),
|
|
12
|
+
{}
|
|
13
|
+
)
|
|
14
|
+
});
|
|
15
|
+
if (response?.error || !response.data) {
|
|
16
|
+
throw response?.error;
|
|
17
|
+
}
|
|
18
|
+
return response.data;
|
|
19
|
+
},
|
|
20
|
+
async onMutate(items) {
|
|
21
|
+
await Cart.cancel();
|
|
22
|
+
const previousCart = Cart.get();
|
|
23
|
+
Cart.set((old) => ({
|
|
24
|
+
...old,
|
|
25
|
+
items_count: old.items.filter((item) => items.includes(item.key)).reduce((total, item) => total + item.quantity, 0),
|
|
26
|
+
items: old.items.filter((item) => !items.includes(item.key))
|
|
27
|
+
}));
|
|
28
|
+
return { previousCart };
|
|
29
|
+
},
|
|
30
|
+
onError(_, __, context) {
|
|
31
|
+
if (context?.previousCart) Cart.set(() => context.previousCart);
|
|
32
|
+
Cart.invalidate();
|
|
33
|
+
},
|
|
34
|
+
onSuccess(cart) {
|
|
35
|
+
if (!cart) return Cart.invalidate();
|
|
36
|
+
Cart.set(() => cart);
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
() => client
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export { mutation };
|
|
43
|
+
//# sourceMappingURL=removeItems.js.map
|
|
44
|
+
//# sourceMapp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AAA;AACtB,MAAA,IAAI,SAAS,YAAc,EAAA,IAAA,CAAK,GAAI,CAAA,MAAM,QAAQ,YAAY,CAAA;AAC9D,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"removeItems.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = string;\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (items: Input[]) => {\n const response = await API.update({\n updates: items.reduce(\n (updates, key) =>\n ({ ...updates, [key]: 0 }) as Record<string, number>,\n {},\n ),\n });\n if (response?.error || !response.data) {\n throw response?.error;\n }\n return response.data;\n },\n async onMutate(items) {\n await Cart.cancel();\n const previousCart = Cart.get();\n\n Cart.set((old) => ({\n ...old,\n items_count: old.items\n .filter((item) => items.includes(item.key))\n .reduce((total, item) => total + item.quantity, 0),\n items: old.items.filter((item) => !items.includes(item.key)),\n }));\n\n return { previousCart };\n },\n onError(_, __, context) {\n if (context?.previousCart) Cart.set(() => context.previousCart);\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (item) => {
|
|
9
|
+
const cart = Cart.get();
|
|
10
|
+
const currentItem = cart.items.find((i) => i.key === item.key);
|
|
11
|
+
if (!currentItem) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Item with provided key of ${item.key} does not exists!`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const tempValues = {
|
|
17
|
+
quantity: currentItem.quantity,
|
|
18
|
+
properties: {
|
|
19
|
+
...currentItem.properties
|
|
20
|
+
},
|
|
21
|
+
selling_plan: currentItem?.selling_plan_allocation?.selling_plan.id || void 0
|
|
22
|
+
};
|
|
23
|
+
await API.change({
|
|
24
|
+
id: item.key,
|
|
25
|
+
quantity: 0
|
|
26
|
+
});
|
|
27
|
+
const response = await API.add({
|
|
28
|
+
items: [
|
|
29
|
+
{
|
|
30
|
+
id: item.id,
|
|
31
|
+
...tempValues
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
if (response?.error || !response.data) {
|
|
36
|
+
throw response?.error;
|
|
37
|
+
}
|
|
38
|
+
return response.data;
|
|
39
|
+
},
|
|
40
|
+
onSettled() {
|
|
41
|
+
Cart.invalidate();
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
() => client
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export { mutation };
|
|
48
|
+
//# sourceMappingURL=replaceItem.js.map
|
|
49
|
+
//# sourceMappingURL=replaceItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/replaceItem.ts"],"names":[],"mappings":";;;;;AAWO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,IAAgB,KAAA;AACjC,MAAM,MAAA,IAAA,GAAO,KAAK,GAAI,EAAA;AACtB,MAAM,MAAA,WAAA,GAAc,KAAK,KAAM,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,GAAQ,KAAA,IAAA,CAAK,GAAG,CAAA;AAC7D,MAAA,IAAI,CAAC,WAAa,EAAA;AAChB,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,KAAK,GAAG,CAAA,iBAAA;AAAA,SACvC;AAAA;AAGF,MAAA,MAAM,UAAa,GAAA;AAAA,QACjB,UAAU,WAAY,CAAA,QAAA;AAAA,QACtB,UAAY,EAAA;AAAA,UACV,GAAG,WAAY,CAAA;AAAA,SACjB;AAAA,QACA,YACE,EAAA,WAAA,EAAa,uBAAyB,EAAA,YAAA,CAAa,EAAM,IAAA;AAAA,OAC7D;AAEA,MAAA,MAAM,IAAI,MAAO,CAAA;AAAA,QACf,IAAI,IAAK,CAAA,GAAA;AAAA,QACT,QAAU,EAAA;AAAA,OACX,CAAA;AACD,MAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,GAAI,CAAA;AAAA,QAC7B,KAAO,EAAA;AAAA,UACL;AAAA,YACE,IAAI,IAAK,CAAA,EAAA;AAAA,YACT,GAAG;AAAA;AACL;AACF,OACD,CAAA;AACD,MAAA,IAAI,QAAU,EAAA,KAAA,IAAS,CAAC,QAAA,CAAS,IAAM,EAAA;AACrC,QAAA,MAAM,QAAU,EAAA,KAAA;AAAA;AAElB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,SAAY,GAAA;AACV,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA;AAClB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"replaceItem.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = {\n key: string;\n id: string | number;\n};\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (item: Input) => {\n const cart = Cart.get();\n const currentItem = cart.items.find((i) => i.key === item.key);\n if (!currentItem) {\n throw new Error(\n `Item with provided key of ${item.key} does not exists!`,\n );\n }\n\n const tempValues = {\n quantity: currentItem.quantity,\n properties: {\n ...currentItem.properties,\n },\n selling_plan:\n currentItem?.selling_plan_allocation?.selling_plan.id || undefined,\n } as const;\n\n await API.change({\n id: item.key,\n quantity: 0,\n });\n const response = await API.add({\n items: [\n {\n id: item.id,\n ...tempValues,\n },\n ],\n });\n if (response?.error || !response.data) {\n throw response?.error;\n }\n return response.data;\n },\n onSettled() {\n Cart.invalidate();\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (attributes) => {
|
|
9
|
+
const response = await API.update({
|
|
10
|
+
attributes
|
|
11
|
+
});
|
|
12
|
+
if (response.error) {
|
|
13
|
+
throw response.error;
|
|
14
|
+
}
|
|
15
|
+
return response.data;
|
|
16
|
+
},
|
|
17
|
+
async onMutate(attributes) {
|
|
18
|
+
await Cart.cancel();
|
|
19
|
+
const previousCart = Cart.get();
|
|
20
|
+
Cart.set((old) => ({
|
|
21
|
+
...old,
|
|
22
|
+
attributes: {
|
|
23
|
+
...old.attributes,
|
|
24
|
+
...attributes
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
return { previousCart };
|
|
28
|
+
},
|
|
29
|
+
onError(_, __, context) {
|
|
30
|
+
if (context?.previousCart) Cart.set(() => context.previousCart);
|
|
31
|
+
Cart.invalidate();
|
|
32
|
+
},
|
|
33
|
+
onSuccess(cart) {
|
|
34
|
+
if (!cart) return Cart.invalidate();
|
|
35
|
+
Cart.set(() => cart);
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
() => client
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export { mutation };
|
|
42
|
+
//# sourceMappingURL=updateAttributes.js.map
|
|
43
|
+
//# sourceMappingURL=updateAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/updateAttributes.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,UAAsB,KAAA;AACvC,MAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,MAAO,CAAA;AAAA,QAChC;AAAA,OACD,CAAA;AAED,MAAA,IAAI,SAAS,KAAO,EAAA;AAClB,QAAA,MAAM,QAAS,CAAA,KAAA;AAAA;AAGjB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,MAAM,SAAS,UAAY,EAAA;AACzB,MAAA,MAAM,KAAK,MAAO,EAAA;AAClB,MAAM,MAAA,YAAA,GAAe,KAAK,GAAI,EAAA;AAE9B,MAAK,IAAA,CAAA,GAAA,CAAI,CAAC,GAAS,MAAA;AAAA,QACjB,GAAG,GAAA;AAAA,QACH,UAAY,EAAA;AAAA,UACV,GAAG,GAAI,CAAA,UAAA;AAAA,UACP,GAAG;AAAA;AACL,OACA,CAAA,CAAA;AAEF,MAAA,OAAO,EAAE,YAAa,EAAA;AAAA,KACxB;AAAA,IACA,OAAA,CAAQ,CAAG,EAAA,EAAA,EAAI,OAAS,EAAA;AACtB,MAAA,IAAI,SAAS,YAAc,EAAA,IAAA,CAAK,GAAI,CAAA,MAAM,QAAQ,YAAY,CAAA;AAC9D,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"updateAttributes.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = NonNullable<Parameters<typeof API.update>[0][\"attributes\"]>;\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (attributes: Input) => {\n const response = await API.update({\n attributes,\n });\n\n if (response.error) {\n throw response.error;\n }\n\n return response.data;\n },\n async onMutate(attributes) {\n await Cart.cancel();\n const previousCart = Cart.get();\n\n Cart.set((old) => ({\n ...old,\n attributes: {\n ...old.attributes,\n ...attributes,\n },\n }));\n\n return { previousCart };\n },\n onError(_, __, context) {\n if (context?.previousCart) Cart.set(() => context.previousCart);\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (discounts) => {
|
|
9
|
+
const response = await API.update({
|
|
10
|
+
discount: discounts
|
|
11
|
+
});
|
|
12
|
+
if (response.error) {
|
|
13
|
+
throw response.error;
|
|
14
|
+
}
|
|
15
|
+
return response.data;
|
|
16
|
+
},
|
|
17
|
+
onError() {
|
|
18
|
+
Cart.invalidate();
|
|
19
|
+
},
|
|
20
|
+
onSuccess(cart) {
|
|
21
|
+
if (!cart) return Cart.invalidate();
|
|
22
|
+
Cart.set(() => cart);
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
() => client
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export { mutation };
|
|
29
|
+
//# sourceMappingURL=updateDiscounts.js.map
|
|
30
|
+
//# sourceMappingURL=updateDiscounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/updateDiscounts.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,SAAuB,KAAA;AACxC,MAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,MAAO,CAAA;AAAA,QAChC,QAAU,EAAA;AAAA,OACX,CAAA;AAED,MAAA,IAAI,SAAS,KAAO,EAAA;AAClB,QAAA,MAAM,QAAS,CAAA,KAAA;AAAA;AAGjB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,OAAU,GAAA;AACR,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"updateDiscounts.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = string;\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (discounts: Input[]) => {\n const response = await API.update({\n discount: discounts,\n });\n\n if (response.error) {\n throw response.error;\n }\n\n return response.data;\n },\n onError() {\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const createIsItemCheck = (input) => (item, index) => {
|
|
7
|
+
if ("id" in input && input.id === `${item.id}`) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if ("key" in input && input.key === item.key) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if ("line" in input && input.line === index + 1) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
const mutation = useMutation(
|
|
19
|
+
() => ({
|
|
20
|
+
mutationFn: async (item) => {
|
|
21
|
+
const response = await API.change(item);
|
|
22
|
+
if (response?.error || !response.data) {
|
|
23
|
+
throw response?.error;
|
|
24
|
+
}
|
|
25
|
+
return response.data;
|
|
26
|
+
},
|
|
27
|
+
async onMutate(item) {
|
|
28
|
+
await Cart.cancel();
|
|
29
|
+
const previousCart = Cart.get();
|
|
30
|
+
const isItemCheck = createIsItemCheck(item);
|
|
31
|
+
Cart.set((old) => ({
|
|
32
|
+
...old,
|
|
33
|
+
items_count: old.items.reduce((total, i, index) => {
|
|
34
|
+
if (isItemCheck(i, index)) {
|
|
35
|
+
return total + (item.quantity || i.quantity);
|
|
36
|
+
}
|
|
37
|
+
return total + i.quantity;
|
|
38
|
+
}, 0),
|
|
39
|
+
items: old.items.map((i, index) => {
|
|
40
|
+
if (isItemCheck(i, index)) {
|
|
41
|
+
return {
|
|
42
|
+
...i,
|
|
43
|
+
quantity: item.quantity || i.quantity,
|
|
44
|
+
properties: {
|
|
45
|
+
...item.properties,
|
|
46
|
+
...i.properties
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return i;
|
|
51
|
+
})
|
|
52
|
+
}));
|
|
53
|
+
return { previousCart };
|
|
54
|
+
},
|
|
55
|
+
onError(_, __, context) {
|
|
56
|
+
if (context?.previousCart) Cart.set(() => context.previousCart);
|
|
57
|
+
Cart.invalidate();
|
|
58
|
+
},
|
|
59
|
+
onSuccess(cart) {
|
|
60
|
+
if (!cart) return Cart.invalidate();
|
|
61
|
+
Cart.set(() => cart);
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
() => client
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export { mutation };
|
|
68
|
+
//# sourceMappingURL=updateItem.js.map
|
|
69
|
+
//# s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U,KAAA;AACjD,UAAI,IAAA,WAAA,CAAY,CAAG,EAAA,KAAK,CAAG,EAAA;AACzB,YAAO,OAAA,KAAA,IAAS,IAAK,CAAA,QAAA,IAAY,CAAE,CAAA,QAAA,CAAA;AAAA;AAErC,UAAA,OAAO,QAAQ,CAAE,CAAA,QAAA;AAAA,WAChB,CAAC,CAAA;AAAA,QACJ,OAAO,GAAI,CAAA,KAAA,CAAM,GAAI,CAAA,CAAC,GAAG,KAAU,KAAA;AACjC,UAAI,IAAA,WAAA,CAAY,CAAG,EAAA,KAAK,CAAG,EAAA;AACzB,YAAO,OAAA;AAAA,cACL,GAAG,CAAA;AAAA,cACH,QAAA,EAAU,IAAK,CAAA,QAAA,IAAY,CAAE,CAAA,QAAA;AAAA,cAC7B,UAAY,EAAA;AAAA,gBACV,GAAG,IAAK,CAAA,UAAA;AAAA,gBACR,GAAG,CAAE,CAAA;AAAA;AACP,aACF;AAAA;AAEF,UAAO,OAAA,CAAA;AAAA,SACR;AAAA,OACD,CAAA,CAAA;AAEF,MAAA,OAAO,EAAE,YAAa,EAAA;AAAA,KACxB;AAAA,IACA,OAAA,CAAQ,CAAG,EAAA,EAAA,EAAI,OAAS,EAAA;AACtB,MAAA,IAAI,SAAS,YAAc,EAAA,IAAA,CAAK,GAAI,CAAA,MAAM,QAAQ,YAAY,CAAA;AAC9D,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"updateItem.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = Parameters<typeof API.change>[0];\n\ntype CartItem = NonNullable<\n Awaited<ReturnType<typeof API.get>>[\"data\"]\n>[\"items\"][number];\n\nconst createIsItemCheck = (input: Input) => (item: CartItem, index: number) => {\n if (\"id\" in input && input.id === `${item.id}`) {\n return true;\n }\n if (\"key\" in input && input.key === item.key) {\n return true;\n }\n if (\"line\" in input && input.line === index + 1) {\n return true;\n }\n return false;\n};\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (item: Input) => {\n const response = await API.change(item);\n if (response?.error || !response.data) {\n throw response?.error;\n }\n return response.data;\n },\n async onMutate(item) {\n await Cart.cancel();\n const previousCart = Cart.get();\n const isItemCheck = createIsItemCheck(item);\n\n Cart.set((old) => ({\n ...old,\n items_count: old.items.reduce((total, i, index) => {\n if (isItemCheck(i, index)) {\n return total + (item.quantity || i.quantity);\n }\n return total + i.quantity;\n }, 0),\n items: old.items.map((i, index) => {\n if (isItemCheck(i, index)) {\n return {\n ...i,\n quantity: item.quantity || i.quantity,\n properties: {\n ...item.properties,\n ...i.properties,\n },\n };\n }\n return i;\n }),\n }));\n\n return { previousCart };\n },\n onError(_, __, context) {\n if (context?.previousCart) Cart.set(() => context.previousCart);\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
import { Cart } from '../query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = useMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (note) => {
|
|
9
|
+
const response = await API.update({
|
|
10
|
+
note
|
|
11
|
+
});
|
|
12
|
+
if (response.error) {
|
|
13
|
+
throw response.error;
|
|
14
|
+
}
|
|
15
|
+
return response.data;
|
|
16
|
+
},
|
|
17
|
+
async onMutate(note) {
|
|
18
|
+
await Cart.cancel();
|
|
19
|
+
const previousCart = Cart.get();
|
|
20
|
+
Cart.set((old) => ({
|
|
21
|
+
...old,
|
|
22
|
+
note
|
|
23
|
+
}));
|
|
24
|
+
return { previousCart };
|
|
25
|
+
},
|
|
26
|
+
onError(_, __, context) {
|
|
27
|
+
if (context?.previousCart) Cart.set(() => context.previousCart);
|
|
28
|
+
Cart.invalidate();
|
|
29
|
+
},
|
|
30
|
+
onSuccess(cart) {
|
|
31
|
+
if (!cart) return Cart.invalidate();
|
|
32
|
+
Cart.set(() => cart);
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
() => client
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export { mutation };
|
|
39
|
+
//# sourceMappingURL=updateNote.js.map
|
|
40
|
+
//# sourceMappingURL=updateNote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/updateNote.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,WAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,IAAwB,KAAA;AACzC,MAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,MAAO,CAAA;AAAA,QAChC;AAAA,OACD,CAAA;AAED,MAAA,IAAI,SAAS,KAAO,EAAA;AAClB,QAAA,MAAM,QAAS,CAAA,KAAA;AAAA;AAGjB,MAAA,OAAO,QAAS,CAAA,IAAA;AAAA,KAClB;AAAA,IACA,MAAM,SAAS,IAAM,EAAA;AACnB,MAAA,MAAM,KAAK,MAAO,EAAA;AAClB,MAAM,MAAA,YAAA,GAAe,KAAK,GAAI,EAAA;AAE9B,MAAK,IAAA,CAAA,GAAA,CAAI,CAAC,GAAS,MAAA;AAAA,QACjB,GAAG,GAAA;AAAA,QACH;AAAA,OACA,CAAA,CAAA;AAEF,MAAA,OAAO,EAAE,YAAa,EAAA;AAAA,KACxB;AAAA,IACA,OAAA,CAAQ,CAAG,EAAA,EAAA,EAAI,OAAS,EAAA;AACtB,MAAA,IAAI,SAAS,YAAc,EAAA,IAAA,CAAK,GAAI,CAAA,MAAM,QAAQ,YAAY,CAAA;AAC9D,MAAA,IAAA,CAAK,UAAW,EAAA;AAAA,KAClB;AAAA,IACA,UAAU,IAAM,EAAA;AACd,MAAA,IAAI,CAAC,IAAA,EAAa,OAAA,IAAA,CAAK,UAAW,EAAA;AAClC,MAAK,IAAA,CAAA,GAAA,CAAI,MAAM,IAAI,CAAA;AAAA;AACrB,GACF,CAAA;AAAA,EACA,MAAM;AACR","file":"updateNote.js","sourcesContent":["import { useMutation } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\nimport { Cart } from \"../query/index.js\";\n\nexport type Input = string | null;\n\nexport const mutation = useMutation(\n () => ({\n mutationFn: async (note: string | null) => {\n const response = await API.update({\n note,\n });\n\n if (response.error) {\n throw response.error;\n }\n\n return response.data;\n },\n async onMutate(note) {\n await Cart.cancel();\n const previousCart = Cart.get();\n\n Cart.set((old) => ({\n ...old,\n note,\n }));\n\n return { previousCart };\n },\n onError(_, __, context) {\n if (context?.previousCart) Cart.set(() => context.previousCart);\n Cart.invalidate();\n },\n onSuccess(cart) {\n if (!cart) return Cart.invalidate();\n Cart.set(() => cart);\n },\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/solid-query';
|
|
2
|
+
import client from '../client.js';
|
|
3
|
+
import API from '../api.js';
|
|
4
|
+
|
|
5
|
+
const KEY = "cart";
|
|
6
|
+
const invalidate = () => client.invalidateQueries({ queryKey: [KEY] });
|
|
7
|
+
const set = (cb) => client.setQueryData([KEY], cb);
|
|
8
|
+
const cancel = async () => client.cancelQueries({ queryKey: [KEY] });
|
|
9
|
+
const get = () => client.getQueryData([KEY]);
|
|
10
|
+
const query = useQuery(
|
|
11
|
+
() => ({
|
|
12
|
+
queryKey: [KEY],
|
|
13
|
+
async queryFn({ signal }) {
|
|
14
|
+
const cart = await API.get({}, { signal });
|
|
15
|
+
if (cart?.error || !cart?.data) {
|
|
16
|
+
throw cart.error;
|
|
17
|
+
}
|
|
18
|
+
return cart.data;
|
|
19
|
+
},
|
|
20
|
+
initialData: window.BrytDesigns.initialCart,
|
|
21
|
+
staleTime: 1e3 * 60 * 5,
|
|
22
|
+
throwOnError: true,
|
|
23
|
+
reconcile: "cart"
|
|
24
|
+
}),
|
|
25
|
+
() => client
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export { KEY, cancel, get, invalidate, query, set };
|
|
29
|
+
//# sourceMappingURL=cart.js.map
|
|
30
|
+
//# sourceMappingURL=cart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/query/cart.ts"],"names":[],"mappings":";;;;AAOO,MAAM,GAAM,GAAA;AACN,MAAA,UAAA,GAAa,MAAM,MAAO,CAAA,iBAAA,CAAkB,EAAE,QAAU,EAAA,CAAC,GAAG,CAAA,EAAG;AAC/D,MAAA,GAAA,GAAM,CAAC,EAClB,KAAA,MAAA,CAAO,aAAa,CAAC,GAAG,GAAG,EAAE;AAClB,MAAA,MAAA,GAAS,YAAY,MAAO,CAAA,aAAA,CAAc,EAAE,QAAU,EAAA,CAAC,GAAG,CAAA,EAAG;AACnE,MAAM,MAAM,MAAM,MAAA,CAAO,YAAa,CAAA,CAAC,GAAG,CAAC;AAE3C,MAAM,KAAQ,GAAA,QAAA;AAAA,EACnB,OAAO;AAAA,IACL,QAAA,EAAU,CAAC,GAAG,CAAA;AAAA,IACd,MAAM,OAAA,CAAQ,EAAE,MAAA,EAAU,EAAA;AACxB,MAAM,MAAA,IAAA,GAAO,MAAM,GAAI,CAAA,GAAA,CAAI,EAAI,EAAA,EAAE,QAAQ,CAAA;AACzC,MAAA,IAAI,IAAM,EAAA,KAAA,IAAS,CAAC,IAAA,EAAM,IAAM,EAAA;AAC9B,QAAA,MAAM,IAAK,CAAA,KAAA;AAAA;AAEb,MAAA,OAAO,IAAK,CAAA,IAAA;AAAA,KACd;AAAA,IACA,WAAA,EAAa,OAAO,WAAY,CAAA,WAAA;AAAA,IAChC,SAAA,EAAW,MAAO,EAAK,GAAA,CAAA;AAAA,IACvB,YAAc,EAAA,IAAA;AAAA,IACd,SAAW,EAAA;AAAA,GACb,CAAA;AAAA,EACA,MAAM;AACR","file":"cart.js","sourcesContent":["import type { CartData } from \"../types\";\n\nimport { useQuery } from \"@tanstack/solid-query\";\n\nimport client from \"../client.js\";\nimport API from \"../api.js\";\n\nexport const KEY = \"cart\";\nexport const invalidate = () => client.invalidateQueries({ queryKey: [KEY] });\nexport const set = (cb: (data: CartData) => CartData) =>\n client.setQueryData([KEY], cb);\nexport const cancel = async () => client.cancelQueries({ queryKey: [KEY] });\nexport const get = () => client.getQueryData([KEY]) as CartData;\n\nexport const query = useQuery(\n () => ({\n queryKey: [KEY],\n async queryFn({ signal }) {\n const cart = await API.get({}, { signal });\n if (cart?.error || !cart?.data) {\n throw cart.error;\n }\n return cart.data;\n },\n initialData: window.BrytDesigns.initialCart,\n staleTime: 1000 * 60 * 5,\n throwOnError: true,\n reconcile: \"cart\",\n }),\n () => client,\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { observable } from 'solid-js';
|
|
2
|
+
import { Cart } from './query/index.js';
|
|
3
|
+
|
|
4
|
+
const uniq = (array) => Array.from(new Set(array));
|
|
5
|
+
const getNormalizedAttributes = () => {
|
|
6
|
+
const cart = Cart.get();
|
|
7
|
+
const mergedAttributes = {
|
|
8
|
+
...cart.attributes
|
|
9
|
+
};
|
|
10
|
+
return mergedAttributes;
|
|
11
|
+
};
|
|
12
|
+
const getCartDiscountCodes = () => {
|
|
13
|
+
const cart = Cart.get();
|
|
14
|
+
const cartLevelCodes = (cart?.cart_level_discount_applications || []).filter((discount) => discount.type === "discount_code").map((discount) => discount.title);
|
|
15
|
+
const itemLevelCodes = (cart?.items || [])?.reduce((codes, item) => {
|
|
16
|
+
const itemCodes = (item?.line_level_discount_allocations || []).filter(
|
|
17
|
+
(allocation) => allocation.discount_application.type === "discount_code"
|
|
18
|
+
).map((allocation) => allocation.discount_application.title);
|
|
19
|
+
return uniq([...codes, ...itemCodes]);
|
|
20
|
+
}, []);
|
|
21
|
+
return uniq([...cartLevelCodes, ...itemLevelCodes]);
|
|
22
|
+
};
|
|
23
|
+
function defaultUnwrap(cart) {
|
|
24
|
+
return cart;
|
|
25
|
+
}
|
|
26
|
+
function subscribe(unwrapValue = defaultUnwrap, cb) {
|
|
27
|
+
const observer = observable(() => unwrapValue(Cart.query.data));
|
|
28
|
+
return observer.subscribe(cb).unsubscribe;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getCartDiscountCodes, getNormalizedAttributes, subscribe, uniq };
|
|
32
|
+
//# sourceMappingURL=utils.js.map
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAMa,MAAA,IAAA,GAAO,CAAC,KAA8B,KAAA,KAAA,CAAM,KAAK,IAAI,GAAA,CAAI,KAAK,CAAC;AAErE,MAAM,0BAA0B,MAAM;AAC3C,EAAM,MAAA,IAAA,GAAO,KAAK,GAAI,EAAA;AACtB,EAAA,MAAM,gBAAmB,GAAA;AAAA,IACvB,GAAG,IAAK,CAAA;AAAA,GACV;AACA,EAAO,OAAA,gBAAA;AACT;AAEO,MAAM,uBAAuB,MAAM;AACxC,EAAM,MAAA,IAAA,GAAO,KAAK,GAAI,EAAA;AACtB,EAAA,MAAM,kBAAkB,IAAM,EAAA,gCAAA,IAAoC,EAAC,EAChE,OAAO,CAAC,QAAA,KAAa,QAAS,CAAA,IAAA,KAAS,eAAe,CACtD,CAAA,GAAA,CAAI,CAAC,QAAA,KAAa,SAAS,KAAK,CAAA;AAEnC,EAAM,MAAA,cAAA,GAAA,CAAkB,MAAM,KAAS,IAAA,KAAK,MAAO,CAAA,CAAC,OAAO,IAAS,KAAA;AAClE,IAAA,MAAM,SAAa,GAAA,CAAA,IAAA,EAAM,+BAAmC,IAAA,EACzD,EAAA,MAAA;AAAA,MACC,CAAC,UAAA,KACC,UAAW,CAAA,oBAAA,CAAqB,IAAS,KAAA;AAAA,MAE5C,GAAI,CAAA,CAAC,UAAe,KAAA,UAAA,CAAW,qBAAqB,KAAK,CAAA;AAC5D,IAAA,OAAO,KAAK,CAAC,GAAG,KAAO,EAAA,GAAG,SAAS,CAAC,CAAA;AAAA,GACtC,EAAG,EAAc,CAAA;AAEjB,EAAA,OAAO,KAAK,CAAC,GAAG,cAAgB,EAAA,GAAG,cAAc,CAAC,CAAA;AACpD;AAEA,SAAS,cAAiB,IAAmB,EAAA;AAC3C,EAAO,OAAA,IAAA;AACT;AAEO,SAAS,SAAA,CACd,WAAqC,GAAA,aAAA,EACrC,EACY,EAAA;AAEZ,EAAA,MAAM,WAAW,UAAW,CAAA,MAAM,YAAY,IAAK,CAAA,KAAA,CAAM,IAAI,CAAC,CAAA;AAC9D,EAAO,OAAA,QAAA,CAAS,SAAU,CAAA,EAAE,CAAE,CAAA,WAAA;AAChC","file":"utils.js","sourcesContent":["import type { CartData } from \"./types\";\n\nimport { observable } from \"solid-js\";\n\nimport { Cart } from \"./query/index.js\";\n\nexport const uniq = (array: string[]): string[] => Array.from(new Set(array));\n\nexport const getNormalizedAttributes = () => {\n const cart = Cart.get();\n const mergedAttributes = {\n ...cart.attributes,\n };\n return mergedAttributes;\n};\n\nexport const getCartDiscountCodes = () => {\n const cart = Cart.get();\n const cartLevelCodes = (cart?.cart_level_discount_applications || [])\n .filter((discount) => discount.type === \"discount_code\")\n .map((discount) => discount.title);\n\n const itemLevelCodes = (cart?.items || [])?.reduce((codes, item) => {\n const itemCodes = (item?.line_level_discount_allocations || [])\n .filter(\n (allocation) =>\n allocation.discount_application.type === \"discount_code\",\n )\n .map((allocation) => allocation.discount_application.title);\n return uniq([...codes, ...itemCodes]);\n }, [] as string[]);\n\n return uniq([...cartLevelCodes, ...itemLevelCodes]);\n};\n\nfunction defaultUnwrap<T>(cart: CartData): T {\n return cart as T; // Use unknown as intermediary to satisfy TypeScript\n}\n\nexport function subscribe<T>(\n unwrapValue: (cart: CartData) => T = defaultUnwrap,\n cb: (data: T) => void,\n): () => void {\n // Assuming cartQuery and observable are defined and set correctly.\n const observer = observable(() => unwrapValue(Cart.query.data));\n return observer.subscribe(cb).unsubscribe;\n}\n"]}
|