@brytdesigns/shopify-ajax-cart 1.0.42 → 1.0.45
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/index.d.ts +12 -12
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createHybridCartApi } from '/npm/@brytdesigns/shopify-hybrid-cart-api@1.2.23';
|
|
2
|
+
|
|
3
|
+
const API = createHybridCartApi({ debug: window?.BrytDesigns?.debug });
|
|
4
|
+
var api_default = API;
|
|
5
|
+
|
|
6
|
+
export { api_default as default };
|
|
7
|
+
//# sourceMappingURL=api.js.map
|
|
8
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/api.ts"],"names":[],"mappings":";;AAKA,MAAM,MAAM,mBAAoB,CAAA,EAAE,OAAO,MAAQ,EAAA,WAAA,EAAa,OAAO,CAAA;AAErE,IAAO,WAAQ,GAAA","file":"api.js","sourcesContent":["import { createHybridCartApi } from \"/npm/@brytdesigns/shopify-hybrid-cart-api@1.2.23\";\n\n/**\n * @internal\n */\nconst API = createHybridCartApi({ debug: window?.BrytDesigns?.debug });\n\nexport default API;\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QueryClient } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import { persistQueryClient } from '/npm/@tanstack/solid-query-persist-client@^5.67.1/+esm';
|
|
3
|
+
import { createSyncStoragePersister } from '/npm/@tanstack/query-sync-storage-persister@^5.67.1/+esm';
|
|
4
|
+
import lz from '/npm/lz-string@^1.5.0/+esm';
|
|
5
|
+
|
|
6
|
+
const client = new QueryClient();
|
|
7
|
+
persistQueryClient({
|
|
8
|
+
queryClient: client,
|
|
9
|
+
persister: createSyncStoragePersister({
|
|
10
|
+
storage: window.localStorage,
|
|
11
|
+
serialize: (data) => lz.compressToUTF16(JSON.stringify(data)),
|
|
12
|
+
deserialize: (data) => JSON.parse(lz.decompressFromUTF16(data)),
|
|
13
|
+
key: "brytdesigns-hybrid-cart"
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
var client_default = client;
|
|
17
|
+
|
|
18
|
+
export { client_default as default };
|
|
19
|
+
//# sourceMappingURL=client.js.map
|
|
20
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client.ts"],"names":[],"mappings":";;;;;AAKA,MAAM,MAAA,GAAS,IAAI,WAAY,EAAA;AAE/B,kBAAmB,CAAA;AAAA,EACjB,WAAa,EAAA,MAAA;AAAA,EACb,WAAW,0BAA2B,CAAA;AAAA,IACpC,SAAS,MAAO,CAAA,YAAA;AAAA,IAChB,SAAA,EAAW,CAAC,IAAS,KAAA,EAAA,CAAG,gBAAgB,IAAK,CAAA,SAAA,CAAU,IAAI,CAAC,CAAA;AAAA,IAC5D,WAAA,EAAa,CAAC,IAAS,KAAA,IAAA,CAAK,MAAM,EAAG,CAAA,mBAAA,CAAoB,IAAI,CAAC,CAAA;AAAA,IAC9D,GAAK,EAAA;AAAA,GACN;AACH,CAAC,CAAA;AAED,IAAO,cAAQ,GAAA","file":"client.js","sourcesContent":["import { QueryClient } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\nimport { persistQueryClient } from \"/npm/@tanstack/solid-query-persist-client@^5.67.1/+esm\";\nimport { createSyncStoragePersister } from \"/npm/@tanstack/query-sync-storage-persister@^5.67.1/+esm\";\nimport lz from \"/npm/lz-string@^1.5.0/+esm\";\n\nconst client = new QueryClient();\n\npersistQueryClient({\n queryClient: client,\n persister: createSyncStoragePersister({\n storage: window.localStorage,\n serialize: (data) => lz.compressToUTF16(JSON.stringify(data)),\n deserialize: (data) => JSON.parse(lz.decompressFromUTF16(data)),\n key: \"brytdesigns-hybrid-cart\",\n }),\n});\n\nexport default client;\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mergeProps } from '/npm/solid-js@^1.9.5/+esm';
|
|
2
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
3
|
+
import { UpdateItem, ClearCart, UpdateNote, UpdateAttributes, RemoveItems, AddItems, ReplaceItem, UpdateDiscounts } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/index.js';
|
|
4
|
+
import { subscribe, getCartDiscountCodes, uniq, getNormalizedAttributes } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/utils.js';
|
|
5
|
+
|
|
6
|
+
const HybridCart = 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 = HybridCart;
|
|
90
|
+
var index_default = HybridCart;
|
|
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":"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","file":"index.js","sourcesContent":["import type { CartData } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/types\";\n\nimport { mergeProps } from \"/npm/solid-js@^1.9.5/+esm\";\n\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\nimport {\n AddItems,\n RemoveItems,\n UpdateAttributes,\n UpdateDiscounts,\n UpdateItem,\n UpdateNote,\n ClearCart,\n ReplaceItem,\n} from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/index.js\";\nimport {\n getNormalizedAttributes,\n subscribe,\n getCartDiscountCodes,\n uniq,\n} from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/utils.js\";\n\nconst HybridCart = 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 HybridCart;\n debug?: boolean;\n };\n }\n}\n\n//@ts-ignore\nif (!window.BrytDesigns) window.BrytDesigns = {};\nwindow.BrytDesigns.cart = HybridCart;\n\nexport default HybridCart;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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,cAAA;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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = Parameters<typeof API.add>[0][\"items\"][number];\n\nexport const mutation = createMutation(\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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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,cAAA;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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = string | null;\n\nexport const mutation = createMutation(\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 '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/addItems.js';
|
|
2
|
+
export { addItems_js as AddItems };
|
|
3
|
+
import * as removeItems_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/removeItems.js';
|
|
4
|
+
export { removeItems_js as RemoveItems };
|
|
5
|
+
import * as updateAttributes_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/updateAttributes.js';
|
|
6
|
+
export { updateAttributes_js as UpdateAttributes };
|
|
7
|
+
import * as updateDiscounts_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/updateDiscounts.js';
|
|
8
|
+
export { updateDiscounts_js as UpdateDiscounts };
|
|
9
|
+
import * as updateItem_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/updateItem.js';
|
|
10
|
+
export { updateItem_js as UpdateItem };
|
|
11
|
+
import * as updateNote_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/updateNote.js';
|
|
12
|
+
export { updateNote_js as UpdateNote };
|
|
13
|
+
import * as clearCart_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/clearCart.js';
|
|
14
|
+
export { clearCart_js as ClearCart };
|
|
15
|
+
import * as replaceItem_js from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/mutations/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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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
|
+
//# sourceMappingURL=removeItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/removeItems.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,cAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,KAAmB,KAAA;AACpC,MAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,MAAO,CAAA;AAAA,QAChC,SAAS,KAAM,CAAA,MAAA;AAAA,UACb,CAAC,SAAS,GACP,MAAA,EAAE,GAAG,OAAS,EAAA,CAAC,GAAG,GAAG,CAAE,EAAA,CAAA;AAAA,UAC1B;AAAC;AACH,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,MAAM,SAAS,KAAO,EAAA;AACpB,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,GAAI,CAAA,KAAA,CACd,OAAO,CAAC,IAAA,KAAS,MAAM,QAAS,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CACzC,OAAO,CAAC,KAAA,EAAO,SAAS,KAAQ,GAAA,IAAA,CAAK,UAAU,CAAC,CAAA;AAAA,QACnD,KAAA,EAAO,GAAI,CAAA,KAAA,CAAM,MAAO,CAAA,CAAC,IAAS,KAAA,CAAC,KAAM,CAAA,QAAA,CAAS,IAAK,CAAA,GAAG,CAAC;AAAA,OAC3D,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":"removeItems.js","sourcesContent":["import { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = string;\n\nexport const mutation = createMutation(\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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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,cAAA;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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = {\n key: string;\n id: string | number;\n};\n\nexport const mutation = createMutation(\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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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,cAAA;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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = NonNullable<Parameters<typeof API.update>[0][\"attributes\"]>;\n\nexport const mutation = createMutation(\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,28 @@
|
|
|
1
|
+
import { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
7
|
+
() => ({
|
|
8
|
+
mutationFn: async (discounts) => {
|
|
9
|
+
const response = await API.discounts.update(discounts);
|
|
10
|
+
if (response.error) {
|
|
11
|
+
throw response.error;
|
|
12
|
+
}
|
|
13
|
+
return response.data;
|
|
14
|
+
},
|
|
15
|
+
onError() {
|
|
16
|
+
Cart.invalidate();
|
|
17
|
+
},
|
|
18
|
+
onSuccess(cart) {
|
|
19
|
+
if (!cart) return Cart.invalidate();
|
|
20
|
+
Cart.set(() => cart);
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
() => client
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export { mutation };
|
|
27
|
+
//# sourceMappingURL=updateDiscounts.js.map
|
|
28
|
+
//# sourceMappingURL=updateDiscounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/updateDiscounts.ts"],"names":[],"mappings":";;;;;AAQO,MAAM,QAAW,GAAA,cAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,SAAuB,KAAA;AACxC,MAAA,MAAM,QAAW,GAAA,MAAM,GAAI,CAAA,SAAA,CAAU,OAAO,SAAS,CAAA;AAErD,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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = string;\n\nexport const mutation = createMutation(\n () => ({\n mutationFn: async (discounts: Input[]) => {\n const response = await API.discounts.update(discounts);\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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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 = createMutation(
|
|
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
|
+
//# sourceMappingURL=updateItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mutations/updateItem.ts"],"names":[],"mappings":";;;;;AAYA,MAAM,iBAAoB,GAAA,CAAC,KAAiB,KAAA,CAAC,MAAgB,KAAkB,KAAA;AAC7E,EAAA,IAAI,QAAQ,KAAS,IAAA,KAAA,CAAM,OAAO,CAAG,EAAA,IAAA,CAAK,EAAE,CAAI,CAAA,EAAA;AAC9C,IAAO,OAAA,IAAA;AAAA;AAET,EAAA,IAAI,KAAS,IAAA,KAAA,IAAS,KAAM,CAAA,GAAA,KAAQ,KAAK,GAAK,EAAA;AAC5C,IAAO,OAAA,IAAA;AAAA;AAET,EAAA,IAAI,MAAU,IAAA,KAAA,IAAS,KAAM,CAAA,IAAA,KAAS,QAAQ,CAAG,EAAA;AAC/C,IAAO,OAAA,IAAA;AAAA;AAET,EAAO,OAAA,KAAA;AACT,CAAA;AAEO,MAAM,QAAW,GAAA,cAAA;AAAA,EACtB,OAAO;AAAA,IACL,UAAA,EAAY,OAAO,IAAgB,KAAA;AACjC,MAAA,MAAM,QAAW,GAAA,MAAM,GAAI,CAAA,MAAA,CAAO,IAAI,CAAA;AACtC,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,MAAM,SAAS,IAAM,EAAA;AACnB,MAAA,MAAM,KAAK,MAAO,EAAA;AAClB,MAAM,MAAA,YAAA,GAAe,KAAK,GAAI,EAAA;AAC9B,MAAM,MAAA,WAAA,GAAc,kBAAkB,IAAI,CAAA;AAE1C,MAAK,IAAA,CAAA,GAAA,CAAI,CAAC,GAAS,MAAA;AAAA,QACjB,GAAG,GAAA;AAAA,QACH,aAAa,GAAI,CAAA,KAAA,CAAM,OAAO,CAAC,KAAA,EAAO,GAAG,KAAU,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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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 = createMutation(\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 { createMutation } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js';
|
|
4
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js';
|
|
5
|
+
|
|
6
|
+
const mutation = createMutation(
|
|
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,cAAA;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 { createMutation } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/api.js\";\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/query/index.js\";\n\nexport type Input = string | null;\n\nexport const mutation = createMutation(\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 { createQuery } from '/npm/@tanstack/solid-query@^5.67.1/+esm';
|
|
2
|
+
import client from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js';
|
|
3
|
+
import API from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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 = createQuery(
|
|
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,WAAA;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 \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/types\";\n\nimport { createQuery } from \"/npm/@tanstack/solid-query@^5.67.1/+esm\";\n\nimport client from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/client.js\";\nimport API from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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 = createQuery(\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 '/npm/solid-js@^1.9.5/+esm';
|
|
2
|
+
import { Cart } from '/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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 \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/types\";\n\nimport { observable } from \"/npm/solid-js@^1.9.5/+esm\";\n\nimport { Cart } from \"/npm/@brytdesigns/shopify-hybrid-cart@0.1.29/dist/jsdelivr/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"]}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare const API: {
|
|
|
20
20
|
readonly selling_plan?: string | number | undefined;
|
|
21
21
|
}[];
|
|
22
22
|
} & {
|
|
23
|
-
readonly sections?: string | undefined;
|
|
23
|
+
readonly sections?: readonly string[] | undefined;
|
|
24
24
|
readonly sections_url?: string | undefined;
|
|
25
25
|
}, options?: createAjaxCartClient.RequestOptions) => Promise<{
|
|
26
26
|
readonly data?: undefined;
|
|
@@ -170,7 +170,7 @@ declare const API: {
|
|
|
170
170
|
} | undefined;
|
|
171
171
|
readonly selling_plan?: string | number | null | undefined;
|
|
172
172
|
} & {
|
|
173
|
-
readonly sections?: string | undefined;
|
|
173
|
+
readonly sections?: readonly string[] | undefined;
|
|
174
174
|
readonly sections_url?: string | undefined;
|
|
175
175
|
}) | ({
|
|
176
176
|
readonly line: number;
|
|
@@ -181,7 +181,7 @@ declare const API: {
|
|
|
181
181
|
} | undefined;
|
|
182
182
|
readonly selling_plan?: string | number | null | undefined;
|
|
183
183
|
} & {
|
|
184
|
-
readonly sections?: string | undefined;
|
|
184
|
+
readonly sections?: readonly string[] | undefined;
|
|
185
185
|
readonly sections_url?: string | undefined;
|
|
186
186
|
}), options?: createAjaxCartClient.RequestOptions) => Promise<{
|
|
187
187
|
readonly data?: undefined;
|
|
@@ -373,7 +373,7 @@ declare const API: {
|
|
|
373
373
|
} | undefined;
|
|
374
374
|
}>;
|
|
375
375
|
clear: (input: {
|
|
376
|
-
readonly sections?: string | undefined;
|
|
376
|
+
readonly sections?: readonly string[] | undefined;
|
|
377
377
|
readonly sections_url?: string | undefined;
|
|
378
378
|
}, options?: createAjaxCartClient.RequestOptions) => Promise<{
|
|
379
379
|
readonly data?: undefined;
|
|
@@ -565,7 +565,7 @@ declare const API: {
|
|
|
565
565
|
} | undefined;
|
|
566
566
|
}>;
|
|
567
567
|
get: (input: {
|
|
568
|
-
readonly sections?: string | undefined;
|
|
568
|
+
readonly sections?: readonly string[] | undefined;
|
|
569
569
|
readonly sections_url?: string | undefined;
|
|
570
570
|
}, options?: createAjaxCartClient.RequestOptions) => Promise<{
|
|
571
571
|
readonly data?: undefined;
|
|
@@ -766,7 +766,7 @@ declare const API: {
|
|
|
766
766
|
} | undefined;
|
|
767
767
|
readonly discount?: readonly string[] | undefined;
|
|
768
768
|
} & {
|
|
769
|
-
readonly sections?: string | undefined;
|
|
769
|
+
readonly sections?: readonly string[] | undefined;
|
|
770
770
|
readonly sections_url?: string | undefined;
|
|
771
771
|
}, options?: createAjaxCartClient.RequestOptions) => Promise<{
|
|
772
772
|
readonly data?: undefined;
|
|
@@ -2158,7 +2158,7 @@ declare const mutation$4: import("@tanstack/solid-query").UseMutationResult<{
|
|
|
2158
2158
|
} | undefined;
|
|
2159
2159
|
readonly selling_plan?: string | number | null | undefined;
|
|
2160
2160
|
} & {
|
|
2161
|
-
readonly sections?: string | undefined;
|
|
2161
|
+
readonly sections?: readonly string[] | undefined;
|
|
2162
2162
|
readonly sections_url?: string | undefined;
|
|
2163
2163
|
}) | ({
|
|
2164
2164
|
readonly line: number;
|
|
@@ -2169,7 +2169,7 @@ declare const mutation$4: import("@tanstack/solid-query").UseMutationResult<{
|
|
|
2169
2169
|
} | undefined;
|
|
2170
2170
|
readonly selling_plan?: string | number | null | undefined;
|
|
2171
2171
|
} & {
|
|
2172
|
-
readonly sections?: string | undefined;
|
|
2172
|
+
readonly sections?: readonly string[] | undefined;
|
|
2173
2173
|
readonly sections_url?: string | undefined;
|
|
2174
2174
|
}), {
|
|
2175
2175
|
previousCart: {
|
|
@@ -5750,7 +5750,7 @@ declare const AjaxCart: {
|
|
|
5750
5750
|
} | undefined;
|
|
5751
5751
|
readonly selling_plan?: string | number | null | undefined;
|
|
5752
5752
|
} & {
|
|
5753
|
-
readonly sections?: string | undefined;
|
|
5753
|
+
readonly sections?: readonly string[] | undefined;
|
|
5754
5754
|
readonly sections_url?: string | undefined;
|
|
5755
5755
|
}) | ({
|
|
5756
5756
|
readonly line: number;
|
|
@@ -5761,7 +5761,7 @@ declare const AjaxCart: {
|
|
|
5761
5761
|
} | undefined;
|
|
5762
5762
|
readonly selling_plan?: string | number | null | undefined;
|
|
5763
5763
|
} & {
|
|
5764
|
-
readonly sections?: string | undefined;
|
|
5764
|
+
readonly sections?: readonly string[] | undefined;
|
|
5765
5765
|
readonly sections_url?: string | undefined;
|
|
5766
5766
|
}), {
|
|
5767
5767
|
previousCart: {
|
|
@@ -10344,7 +10344,7 @@ declare const AjaxCart: {
|
|
|
10344
10344
|
} | undefined;
|
|
10345
10345
|
readonly selling_plan?: string | number | null | undefined;
|
|
10346
10346
|
} & {
|
|
10347
|
-
readonly sections?: string | undefined;
|
|
10347
|
+
readonly sections?: readonly string[] | undefined;
|
|
10348
10348
|
readonly sections_url?: string | undefined;
|
|
10349
10349
|
}) | ({
|
|
10350
10350
|
readonly line: number;
|
|
@@ -10355,7 +10355,7 @@ declare const AjaxCart: {
|
|
|
10355
10355
|
} | undefined;
|
|
10356
10356
|
readonly selling_plan?: string | number | null | undefined;
|
|
10357
10357
|
} & {
|
|
10358
|
-
readonly sections?: string | undefined;
|
|
10358
|
+
readonly sections?: readonly string[] | undefined;
|
|
10359
10359
|
readonly sections_url?: string | undefined;
|
|
10360
10360
|
}), {
|
|
10361
10361
|
previousCart: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brytdesigns/shopify-ajax-cart",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"description": "Reactive state management solution for the Ajax Cart API library",
|
|
5
5
|
"main": "./dist/main/index.js",
|
|
6
6
|
"module": "./dist/main/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@tanstack/solid-query-persist-client": "^5.76.2",
|
|
25
25
|
"lz-string": "^1.5.0",
|
|
26
26
|
"solid-js": "^1.9.7",
|
|
27
|
-
"@brytdesigns/shopify-ajax-cart-api": "1.0.
|
|
27
|
+
"@brytdesigns/shopify-ajax-cart-api": "1.0.36"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"dts-bundle-generator": "^9.5.1",
|