@artisan-commerce/shopping-cart-rn 0.12.0-canary.71

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ## Artisn's Shopping Cart library
2
+
3
+ Manages a Artisn's framework shoppingcart
@@ -0,0 +1,353 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var shoppingCartCore = require('@artisan-commerce/shopping-cart-core');
6
+ var firestore = require('@react-native-firebase/firestore');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var firestore__default = /*#__PURE__*/_interopDefaultLegacy(firestore);
11
+
12
+ const getShoppingCartNodes = async (config = {}) => {
13
+ var _a, _b;
14
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
15
+ const { accountId, customerId, anonymous } = reusedConfig;
16
+ shoppingCartCore.checkInitialized();
17
+ shoppingCartCore.checkMinimumConfigProvided(reusedConfig);
18
+ const path = anonymous ? "anonymousShoppingCartByUser" : "shoppingCartByUser";
19
+ const db = firestore__default["default"]();
20
+ const cartsCollection = await ((_b = (_a = db == null ? void 0 : db.collection(path)) == null ? void 0 : _a.doc(String(customerId))) == null ? void 0 : _b.collection(String(accountId)));
21
+ return cartsCollection;
22
+ };
23
+ const getShoppingCartNode = async (config) => {
24
+ const { shoppingCartName } = shoppingCartCore.reuseGlobalConfig(config);
25
+ const cartsCollection = await getShoppingCartNodes(config);
26
+ shoppingCartCore.checkInitialized();
27
+ if (!cartsCollection || !shoppingCartCore.checkInit())
28
+ return;
29
+ const newestCart = await cartsCollection.where("name", "==", shoppingCartName).get().then((userCarts) => {
30
+ return userCarts.docs[0];
31
+ });
32
+ return newestCart;
33
+ };
34
+ const getShoppingCart = (config) => {
35
+ return shoppingCartCore.getShoppingCart({ getShoppingCartNode }, config);
36
+ };
37
+ const listenShoppingCart = async (onSnapshot, config = {}) => {
38
+ const { shoppingCartName } = shoppingCartCore.reuseGlobalConfig(config);
39
+ const shoppingCartDocs = await getShoppingCartNodes(config);
40
+ shoppingCartCore.checkInitialized();
41
+ if (!shoppingCartDocs || !shoppingCartCore.checkInit()) {
42
+ return () => {
43
+ };
44
+ }
45
+ shoppingCartCore.setState({ activeShoppingCart: shoppingCartName });
46
+ return shoppingCartDocs.where("name", "==", shoppingCartName).onSnapshot(async (snapshot) => {
47
+ var _a;
48
+ if (!((_a = snapshot == null ? void 0 : snapshot.docs) == null ? void 0 : _a[0])) {
49
+ shoppingCartCore.logDebug(`Failed to fetch a shopping cart with name ${shoppingCartName} because there wasn't any.`);
50
+ return onSnapshot(void 0);
51
+ }
52
+ const shoppingCartData = await snapshot.docs[0].data();
53
+ return onSnapshot(shoppingCartData);
54
+ });
55
+ };
56
+
57
+ const setDoc = async (config) => {
58
+ const { payload, shoppingCartNode } = config != null ? config : {};
59
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.set(payload));
60
+ };
61
+ const deleteDoc = async (config) => {
62
+ const { shoppingCartNode } = config != null ? config : {};
63
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.delete());
64
+ };
65
+ const getCollectionReference = async (collectionName, ...path) => {
66
+ var _a, _b;
67
+ const [customerId, accountId] = path;
68
+ const db = firestore__default["default"]();
69
+ const collection = await ((_b = (_a = db == null ? void 0 : db.collection(collectionName)) == null ? void 0 : _a.doc(String(customerId))) == null ? void 0 : _b.collection(String(accountId)));
70
+ return collection;
71
+ };
72
+ const getDocumentsByCollections = async (collectionReference) => {
73
+ const queryDocuments = await collectionReference.get().then((result) => result.docs[0]);
74
+ return queryDocuments;
75
+ };
76
+
77
+ var __defProp$1 = Object.defineProperty;
78
+ var __defProps$1 = Object.defineProperties;
79
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
80
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
81
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
82
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
83
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
84
+ var __spreadValues$1 = (a, b) => {
85
+ for (var prop in b || (b = {}))
86
+ if (__hasOwnProp$1.call(b, prop))
87
+ __defNormalProp$1(a, prop, b[prop]);
88
+ if (__getOwnPropSymbols$1)
89
+ for (var prop of __getOwnPropSymbols$1(b)) {
90
+ if (__propIsEnum$1.call(b, prop))
91
+ __defNormalProp$1(a, prop, b[prop]);
92
+ }
93
+ return a;
94
+ };
95
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
96
+ const createShoppingCart = async (config, overrides = {}) => {
97
+ return new Promise((resolve, reject) => {
98
+ const action = async () => {
99
+ var _a;
100
+ try {
101
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
102
+ const { shoppingCartName } = reusedConfig;
103
+ const cartsCollection = await getShoppingCartNodes(reusedConfig);
104
+ const newShoppingCart = shoppingCartCore.buildInitialShoppingCart(__spreadValues$1({
105
+ name: shoppingCartName,
106
+ channelId: reusedConfig.channelId
107
+ }, overrides));
108
+ if (!cartsCollection) {
109
+ console.warn(`Couldn't find a shopping cart collection with the given config.
110
+ Please make sure everything is correct in your configuration
111
+ before continue.`);
112
+ resolve(null);
113
+ return null;
114
+ }
115
+ const { name } = newShoppingCart;
116
+ const numberOfCarts = (_a = await cartsCollection.get()) == null ? void 0 : _a.docs.length;
117
+ const maxNumberOfCarts = shoppingCartCore.getState().maxShoppingCarts;
118
+ if (numberOfCarts >= maxNumberOfCarts) {
119
+ throw new Error(`Cannot add more carts. Carts limit (${maxNumberOfCarts}) reached.`);
120
+ }
121
+ const namedCartsDocs = await cartsCollection.where("name", "==", name).get();
122
+ const cartsLength = namedCartsDocs.docs.length;
123
+ if (cartsLength > 0) {
124
+ throw new Error(`Attempted to create a shopping cart with the name ${name}, but there is already one shopping cart with that name.`);
125
+ }
126
+ const node = await cartsCollection.add(newShoppingCart);
127
+ if (!node) {
128
+ console.error("Failed to create a new shopping cart");
129
+ resolve(null);
130
+ return null;
131
+ }
132
+ const updatedCart = __spreadProps$1(__spreadValues$1({}, newShoppingCart), { id: node.id });
133
+ await node.set(updatedCart);
134
+ resolve(updatedCart);
135
+ return updatedCart;
136
+ } catch (e) {
137
+ reject(e);
138
+ return null;
139
+ }
140
+ };
141
+ const { eventLoop, queue } = shoppingCartCore.getState();
142
+ queue.enqueue(action);
143
+ if (!eventLoop.isRunning)
144
+ eventLoop.start();
145
+ });
146
+ };
147
+
148
+ const addProduct = (product, config) => {
149
+ return shoppingCartCore.addProduct({ getShoppingCartNode, setDoc, createShoppingCart }, product, config);
150
+ };
151
+
152
+ const subtractProduct = async (product, config) => {
153
+ return shoppingCartCore.subtractProduct({ getShoppingCartNode, setDoc }, product, config);
154
+ };
155
+
156
+ const removeProduct = (product, config = {}) => {
157
+ return shoppingCartCore.removeProduct({ getShoppingCartNode, setDoc }, product, config);
158
+ };
159
+
160
+ const setProduct = async (product, config = {}) => {
161
+ return shoppingCartCore.setProduct({ getShoppingCartNode, setDoc }, product, config);
162
+ };
163
+
164
+ const replaceProduct = (product, config) => {
165
+ return shoppingCartCore.replaceProduct({ getShoppingCartNode, setDoc }, product, config);
166
+ };
167
+
168
+ const emptyShoppingCart = async (config) => await shoppingCartCore.emptyShoppingCart({ getShoppingCartNode, setDoc }, config);
169
+
170
+ const deleteShoppingCart = async (config) => await shoppingCartCore.deleteShoppingCart({ getShoppingCartNode, deleteDoc }, config);
171
+
172
+ const validateShoppingCart = (config = {}, headers) => {
173
+ return shoppingCartCore.validateShoppingCart({ getShoppingCartNode }, config, headers);
174
+ };
175
+
176
+ const getBenefitsNode = (config = {}) => {
177
+ return shoppingCartCore.getBenefitsNode({ getBenefitsCollection: getCollectionReference }, config);
178
+ };
179
+ const getWallet = async (config) => {
180
+ return shoppingCartCore.getWallet({
181
+ getBenefitsCollection: getCollectionReference,
182
+ getBenefitsDocuments: getDocumentsByCollections
183
+ }, config);
184
+ };
185
+
186
+ var __defProp = Object.defineProperty;
187
+ var __defProps = Object.defineProperties;
188
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
189
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
190
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
191
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
192
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
193
+ var __spreadValues = (a, b) => {
194
+ for (var prop in b || (b = {}))
195
+ if (__hasOwnProp.call(b, prop))
196
+ __defNormalProp(a, prop, b[prop]);
197
+ if (__getOwnPropSymbols)
198
+ for (var prop of __getOwnPropSymbols(b)) {
199
+ if (__propIsEnum.call(b, prop))
200
+ __defNormalProp(a, prop, b[prop]);
201
+ }
202
+ return a;
203
+ };
204
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
205
+ const listenBenefitsWallet = (onSnapshot, config, headers) => {
206
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
207
+ shoppingCartCore.checkMinimumFetchWalletConfigProvided(reusedConfig);
208
+ shoppingCartCore.verifyHeaders(headers);
209
+ const { shoppingCartName, customerId, anonymous } = reusedConfig;
210
+ const { wallets } = shoppingCartCore.getState();
211
+ const walletExists = wallets[shoppingCartName];
212
+ if (anonymous)
213
+ return () => shoppingCartCore.unsubscriber(shoppingCartName);
214
+ if (walletExists) {
215
+ shoppingCartCore.logError(`There is already a listener for wallet of name ${shoppingCartName}. Either unsubscribe to the other listener or create a new listener for a different cart`);
216
+ return () => shoppingCartCore.unsubscriber(shoppingCartName);
217
+ }
218
+ const newWallet = shoppingCartCore.getInitialBenefitsWallet();
219
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet), { onSnapshot }));
220
+ let dbUnsubscriber = void 0;
221
+ (async () => {
222
+ const fetchConfig = __spreadProps(__spreadValues({}, reusedConfig), { customerId });
223
+ try {
224
+ await shoppingCartCore.fetchWalletByUser(fetchConfig, headers);
225
+ const benefitsNode = await getBenefitsNode(reusedConfig);
226
+ if (!benefitsNode) {
227
+ throw new Error("Failed to retrieve the benefits wallet node");
228
+ }
229
+ dbUnsubscriber = benefitsNode.onSnapshot(async (collection) => {
230
+ var _a, _b, _c;
231
+ const benefitsByUser = (_c = (_b = (_a = collection == null ? void 0 : collection.docs) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()) != null ? _c : {};
232
+ if (Object.keys(benefitsByUser).length === 0) {
233
+ const newWallet3 = shoppingCartCore.getInitialBenefitsWallet();
234
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet3), {
235
+ onSnapshot
236
+ }));
237
+ onSnapshot(newWallet3);
238
+ return;
239
+ }
240
+ const hash = collection.docs[0].id;
241
+ const benefits = shoppingCartCore.mapCollectionToBenefits(benefitsByUser, hash);
242
+ const newWallet2 = shoppingCartCore.getInitialBenefitsWallet({
243
+ benefits
244
+ });
245
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet2), { onSnapshot }));
246
+ onSnapshot(newWallet2);
247
+ });
248
+ } catch (e) {
249
+ console.error(e.message);
250
+ }
251
+ })();
252
+ return () => shoppingCartCore.unsubscriber(shoppingCartName, dbUnsubscriber);
253
+ };
254
+
255
+ const applyBenefit = async (config, headers) => {
256
+ return shoppingCartCore.applyBenefit({ getShoppingCartNode, applyBenefitsToCart, setDoc }, config, headers);
257
+ };
258
+ const applyBenefitsToCart = async (config, benefit, shippingCost) => {
259
+ const shoppingCartNode = await getShoppingCartNode(config);
260
+ if (!shoppingCartNode) {
261
+ console.warn("Cannot add benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.");
262
+ return;
263
+ }
264
+ const shoppingCart = await shoppingCartNode.data();
265
+ const updatedCart = shoppingCartCore.applyBenefitsHelper(shoppingCart, benefit, shippingCost);
266
+ await shoppingCartNode.ref.set(updatedCart);
267
+ };
268
+
269
+ const removeBenefit = (config) => {
270
+ return shoppingCartCore.removeBenefit({
271
+ getShoppingCartNode,
272
+ removeBenefitsFromCart,
273
+ removeProduct
274
+ }, config);
275
+ };
276
+ const removeBenefitsFromCart = async (config, benefit, shippingCost) => {
277
+ const shoppingCartNode = await getShoppingCartNode(config);
278
+ if (!shoppingCartNode) {
279
+ console.warn(`Cannot remove benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.`);
280
+ return;
281
+ }
282
+ const shoppingCart = await shoppingCartNode.data();
283
+ const updatedCart = shoppingCartCore.removeBenefitsHelper(shoppingCart, benefit, shippingCost);
284
+ await shoppingCartNode.ref.set(updatedCart);
285
+ };
286
+
287
+ const redeemCoupon = async (config, code, headers) => {
288
+ return shoppingCartCore.redeemCoupon({ getWallet, getShoppingCartNode }, config, code, headers);
289
+ };
290
+
291
+ const mergeShoppingCart = async (shoppingCart, config) => {
292
+ return shoppingCartCore.mergeShoppingCart({ getShoppingCartNode, setDoc }, shoppingCart, config);
293
+ };
294
+
295
+ const findProduct = async (config) => {
296
+ return shoppingCartCore.findProduct({ getShoppingCartNode }, config);
297
+ };
298
+
299
+ const updateShoppingCart = async (setShoppingCart, config) => {
300
+ return shoppingCartCore.updateShoppingCart({ getShoppingCartNode, setDoc }, setShoppingCart, config);
301
+ };
302
+
303
+ Object.defineProperty(exports, 'checkInit', {
304
+ enumerable: true,
305
+ get: function () { return shoppingCartCore.checkInit; }
306
+ });
307
+ Object.defineProperty(exports, 'closeShoppingCart', {
308
+ enumerable: true,
309
+ get: function () { return shoppingCartCore.closeShoppingCart; }
310
+ });
311
+ Object.defineProperty(exports, 'fetchStoreCouponDetail', {
312
+ enumerable: true,
313
+ get: function () { return shoppingCartCore.fetchStoreCouponDetail; }
314
+ });
315
+ Object.defineProperty(exports, 'fetchStoreCoupons', {
316
+ enumerable: true,
317
+ get: function () { return shoppingCartCore.fetchStoreCoupons; }
318
+ });
319
+ Object.defineProperty(exports, 'getProductHash', {
320
+ enumerable: true,
321
+ get: function () { return shoppingCartCore.getProductHash; }
322
+ });
323
+ Object.defineProperty(exports, 'getShoppingCartProducts', {
324
+ enumerable: true,
325
+ get: function () { return shoppingCartCore.getShoppingCartProducts; }
326
+ });
327
+ Object.defineProperty(exports, 'getShoppingCartTotal', {
328
+ enumerable: true,
329
+ get: function () { return shoppingCartCore.getShoppingCartTotal; }
330
+ });
331
+ Object.defineProperty(exports, 'initShoppingCart', {
332
+ enumerable: true,
333
+ get: function () { return shoppingCartCore.initShoppingCart; }
334
+ });
335
+ exports.addProduct = addProduct;
336
+ exports.applyBenefit = applyBenefit;
337
+ exports.createShoppingCart = createShoppingCart;
338
+ exports.deleteShoppingCart = deleteShoppingCart;
339
+ exports.emptyShoppingCart = emptyShoppingCart;
340
+ exports.findProduct = findProduct;
341
+ exports.getShoppingCart = getShoppingCart;
342
+ exports.listenBenefitsWallet = listenBenefitsWallet;
343
+ exports.listenShoppingCart = listenShoppingCart;
344
+ exports.mergeShoppingCart = mergeShoppingCart;
345
+ exports.redeemCoupon = redeemCoupon;
346
+ exports.removeBenefit = removeBenefit;
347
+ exports.removeProduct = removeProduct;
348
+ exports.replaceProduct = replaceProduct;
349
+ exports.setProduct = setProduct;
350
+ exports.subtractProduct = subtractProduct;
351
+ exports.updateShoppingCart = updateShoppingCart;
352
+ exports.validateShoppingCart = validateShoppingCart;
353
+ //# sourceMappingURL=bundle.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.cjs.js","sources":["../src/lib/fetchShoppingCart/fetchShoppingCart.ts","../src/utils/firestore.utils.ts","../src/lib/createShoppingCart/createShoppingCart.ts","../src/lib/addProduct/addProduct.ts","../src/lib/subtractProduct/subtractProduct.ts","../src/lib/removeProduct/removeProduct.ts","../src/lib/setProduct/setProduct.ts","../src/lib/replaceProduct/replaceProduct.ts","../src/lib/emptyShoppingCart/emptyShoppingCart.ts","../src/lib/deleteShoppingCart/deleteShoppingCart.ts","../src/lib/validateShoppingCart/validateShoppingCart.ts","../src/utils/benefits.utils.ts","../src/lib/listenBenefitsWallet/listenBenefitsWallet.ts","../src/lib/applyBenefit/applyBenefit.ts","../src/lib/removeBenefit/removeBenefit.ts","../src/lib/redeemCoupon/redeemCoupon.ts","../src/lib/mergeShoppingCart/mergeShoppingCart.ts","../src/utils/product.utils.ts","../src/lib/updateShoppingCart/updateShoppingCart.ts"],"sourcesContent":["import { ShoppingCart } from \"@artisan-commerce/types\";\nimport firestore from \"@react-native-firebase/firestore\";\nimport { checkInitialized } from \"@artisan-commerce/shopping-cart-core\";\nimport { getShoppingCart as getShoppingCartHelper } from \"@artisan-commerce/shopping-cart-core\";\nimport { logDebug } from \"@artisan-commerce/shopping-cart-core\";\nimport { reuseGlobalConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { checkInit } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { checkMinimumConfigProvided } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { setState } from \"../state\";\nimport { ShoppingCartNodes } from \"../../types/firestore.types\";\nimport { ShoppingCartNode } from \"../../types/firestore.types\";\n\n/**\n * Fetches all Artisn shopping cart of the given customer and account. It will first try to look at the function config.\n * If it cannot find any of the needed parameters, it will look into the global config provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param config: Function call level shopping cart configuration\n * @returns A collection of shopping carts of the given customer in the form of firestore document nodes\n */\nexport const getShoppingCartNodes = async (\n config: ShoppingCartConfig = {}\n): Promise<ShoppingCartNodes | undefined> => {\n const reusedConfig = reuseGlobalConfig(config);\n const { accountId, customerId, anonymous } = reusedConfig;\n checkInitialized();\n // Handle no config\n checkMinimumConfigProvided(reusedConfig);\n\n // The node path from firebase to connect\n const path = anonymous ? \"anonymousShoppingCartByUser\" : \"shoppingCartByUser\";\n // Connect to firestore\n const db = firestore();\n const cartsCollection = await db\n ?.collection(path)\n ?.doc(String(customerId))\n ?.collection(String(accountId));\n return cartsCollection;\n};\n\n/**\n * Fetches a shopping cart of the given customer and account, given by the\n * specified name. It will first try to look at the function config. If it\n * cannot find any of the needed parameters, it will look into the global config\n * provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Function call level shopping cart\n * configuration\n * @returns {ShoppingCartNode} The shopping cart of a given customer in the form\n * of firestore document nodes given by its name\n */\nexport const getShoppingCartNode = async (\n config?: ShoppingCartConfig\n): Promise<ShoppingCartNode | undefined> => {\n // Get all user remote shopping carts\n const { shoppingCartName } = reuseGlobalConfig(config);\n const cartsCollection = await getShoppingCartNodes(config);\n checkInitialized();\n if (!cartsCollection || !checkInit()) return;\n\n const newestCart = await cartsCollection\n .where(\"name\", \"==\", shoppingCartName)\n .get()\n .then(userCarts => {\n // Return only the latest shopping cart\n return userCarts.docs[0];\n });\n return newestCart;\n};\n\n/**\n * Fetches a shopping cart of the given customer and account, given by the\n * specified name. It will first try to look at the function config.\n * If it cannot find any of the needed parameters, it will look into the global\n * config provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param config Function call level shopping cart configuration\n * @returns The shopping cart of a given customer given by its specified name\n */\nexport const getShoppingCart = (config?: ShoppingCartConfig) => {\n return getShoppingCartHelper({ getShoppingCartNode }, config);\n};\n\n/**\n * Listens on realtime to any change of the default or\n * named shopping cart of a given customer.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Function} onSnapshot Callback function that receives the latest\n * shopping cart on any updates to the cart\n * @param {ShoppingCartConfig} config Shopping cart custom configuration\n */\nexport const listenShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n onSnapshot: (shoppingCart: T | undefined) => void,\n config: ShoppingCartConfig = {}\n) => {\n const { shoppingCartName } = reuseGlobalConfig(config);\n const shoppingCartDocs = await getShoppingCartNodes(config);\n checkInitialized();\n if (!shoppingCartDocs || !checkInit()) {\n return () => {};\n }\n setState({ activeShoppingCart: shoppingCartName });\n\n return (\n shoppingCartDocs\n .where(\"name\", \"==\", shoppingCartName)\n // @ts-ignore Since it cannot infer whether it's a react native app or a web app\n .onSnapshot(async snapshot => {\n if (!snapshot?.docs?.[0]) {\n logDebug(\n `Failed to fetch a shopping cart with name ${shoppingCartName} because there wasn't any.`\n );\n return onSnapshot(undefined);\n }\n const shoppingCartData = (await snapshot.docs[0].data()) as T;\n return onSnapshot(shoppingCartData);\n })\n );\n};\n","import firestore from \"@react-native-firebase/firestore\";\n\nimport { SetDoc, DeleteDoc } from \"../types/firestore.types\";\nimport { ShoppingCartNodes, ShoppingCartNode } from \"../types/firestore.types\";\n\nexport const setDoc = async (config: SetDoc) => {\n const { payload, shoppingCartNode } = config ?? {};\n await shoppingCartNode?.ref.set(payload);\n};\n\nexport const deleteDoc = async (config: DeleteDoc) => {\n const { shoppingCartNode } = config ?? {};\n await shoppingCartNode?.ref.delete();\n};\n\nexport const getCollectionReference = async (\n collectionName: string,\n ...path: string[]\n): Promise<ShoppingCartNodes> => {\n const [customerId, accountId] = path;\n\n const db = firestore();\n const collection = await db\n ?.collection(collectionName)\n ?.doc(String(customerId))\n ?.collection(String(accountId));\n\n return collection;\n};\n\nexport const getDocumentsByCollections = async (\n collectionReference: ShoppingCartNodes\n): Promise<ShoppingCartNode> => {\n const queryDocuments = await collectionReference\n .get()\n .then(result => result.docs[0]);\n return queryDocuments;\n};\n","import { ShoppingCart } from \"@artisan-commerce/types\";\nimport { buildInitialShoppingCart } from \"@artisan-commerce/shopping-cart-core\";\nimport { reuseGlobalConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartCreateConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getState } from \"../state\";\nimport { getShoppingCartNodes } from \"../fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Creates a new shopping cart to the authenticated user.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Partial<ShoppingCart>} overrides Initial state for one or\n * more shopping cart properties\n * @param {ShoppingCartCreateConfig} config Shopping cart custom configuration\n */\nexport const createShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n config?: ShoppingCartCreateConfig,\n overrides: Partial<T> = {}\n) => {\n return new Promise<T | null>((resolve, reject) => {\n const action = async () => {\n try {\n const reusedConfig = reuseGlobalConfig(config);\n const { shoppingCartName } = reusedConfig;\n const cartsCollection = await getShoppingCartNodes(reusedConfig);\n const newShoppingCart = buildInitialShoppingCart({\n name: shoppingCartName,\n channelId: reusedConfig.channelId,\n ...overrides\n }) as T;\n if (!cartsCollection) {\n console.warn(\n `Couldn't find a shopping cart collection with the given config.\n Please make sure everything is correct in your configuration\n before continue.`\n );\n resolve(null);\n return null;\n }\n // Check if cart with given name already exists\n const { name } = newShoppingCart;\n const numberOfCarts = (await cartsCollection.get())?.docs.length;\n const maxNumberOfCarts = getState().maxShoppingCarts;\n if (numberOfCarts >= maxNumberOfCarts) {\n throw new Error(\n `Cannot add more carts. Carts limit (${maxNumberOfCarts}) reached.`\n );\n }\n const namedCartsDocs = await cartsCollection\n .where(\"name\", \"==\", name)\n .get();\n const cartsLength = namedCartsDocs.docs.length;\n if (cartsLength > 0) {\n throw new Error(\n `Attempted to create a shopping cart with the name ${name}, but there is already one shopping cart with that name.`\n );\n }\n const node = await cartsCollection.add(newShoppingCart);\n if (!node) {\n console.error(\"Failed to create a new shopping cart\");\n resolve(null);\n return null;\n }\n const updatedCart = { ...newShoppingCart, id: node.id };\n await node.set(updatedCart);\n resolve(updatedCart);\n return updatedCart;\n } catch (e) {\n reject(e);\n return null;\n }\n };\n const { eventLoop, queue } = getState();\n queue.enqueue(action);\n if (!eventLoop.isRunning) eventLoop.start();\n });\n};\n","import { Product } from \"@artisan-commerce/types\";\nimport { addProduct as addProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ProductAddConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\nimport { createShoppingCart } from \"../createShoppingCart/createShoppingCart\";\n\nexport const addProduct = (product: Product, config: ProductAddConfig) => {\n return addProductCore(\n { getShoppingCartNode, setDoc, createShoppingCart },\n product,\n config\n );\n};\n","import { Product } from \"@artisan-commerce/types\";\nimport { subtractProduct as subtractProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ProductActionConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Subtracts a product amount async to the remote shopping cart.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Product} product The product object that will be subtracted from the\n * cart. It can be a BaseProduct, a DetailedProduct or a CartProduct\n * @param {ProductActionConfig} config A configuration that specifies how to\n * make an action over a product. E.g specify the amount\n */\nexport const subtractProduct = async (\n product: Product,\n config: ProductActionConfig\n) => {\n return subtractProductCore({ getShoppingCartNode, setDoc }, product, config);\n};\n","import { Product } from \"@artisan-commerce/types\";\nimport { removeProduct as removeProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ProductRemoveConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Removes a product async from the remote shopping cart\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Product} product the product object that will be removed from the\n * cart. It can be a BaseProduct, a DetailedProduct or a CartProduct\n * @param {ProductRemoveConfig} config global configuration overrides. E.g\n * storeId\n */\nexport const removeProduct = (\n product: Product,\n config: ProductRemoveConfig = {}\n) => {\n return removeProductCore({ getShoppingCartNode, setDoc }, product, config);\n};\n","import { Product } from \"@artisan-commerce/types\";\nimport { setProduct as setProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ProductSetConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Sets a product async in the remote shopping cart\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Product} product The product object that will be set in the cart. It\n * can be a BaseProduct, a DetailedProduct or a CartProduct\n * @param {ProductSetConfig} config A configuration that specifies how to make\n * an action over a product. E.g specify the amount\n */\nexport const setProduct = async (\n product: Product,\n config: ProductSetConfig = {}\n) => {\n return setProductCore({ getShoppingCartNode, setDoc }, product, config);\n};\n","// replaceProduct functions\nimport { CartProduct } from \"@artisan-commerce/types\";\nimport { replaceProduct as replaceProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ProductReplaceConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Replaces an existing product async in the remote shopping cart\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {CartProduct} product The product object that will be replaced in the\n * cart. It can only be a CartProduct\n * @param {ProductReplaceConfig} config A configuration that specifies how to\n * make an action over a product. E.g specify the store\n */\nexport const replaceProduct = (\n product: CartProduct,\n config: ProductReplaceConfig\n) => {\n return replaceProductCore({ getShoppingCartNode, setDoc }, product, config);\n};\n","import { emptyShoppingCart as emptyShoppingCartCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { EmptyShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Removes all products in all stores of a given cart. It will attempt to delete\n * the last active shopping cart otherwise the default.\n *\n * If a vendor identifier is specified in the configuration object, it will\n * remove all stores that have the specified vendor.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Empty shopping cart configuration\n */\nexport const emptyShoppingCart = async (config?: EmptyShoppingCartConfig) =>\n await emptyShoppingCartCore({ getShoppingCartNode, setDoc }, config);\n","import { deleteShoppingCart as deleteShoppingCartCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { deleteDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Deletes a customer shopping cart given by its name. It will attempt to delete\n * the last active shopping cart otherwise the default.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Function call level shopping cart\n * configuration\n */\nexport const deleteShoppingCart = async (config?: ShoppingCartConfig) =>\n await deleteShoppingCartCore({ getShoppingCartNode, deleteDoc }, config);\n","// Validate the shopping cart\nimport { validateShoppingCart as validateShoppingCartCore } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { ValidateConfig } from \"./validateShoppingCart.types\";\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Validate shopping cart integrity.\n *\n * @since 0.1.0\n * @param {ValidateConfig} config Object that defines the properties to check\n * whether the shopping cart is valid.\n * @param {Partial<ValidateHeaders>} headers The shopping cart that will be\n * validated. If none provided, then it will use default as its name.\n * @return {Promise<ValidateShoppingCartResult | undefined>} An object which\n * contains stores and products alerts\n */\nexport const validateShoppingCart = (\n config: ValidateConfig = {},\n headers: Headers\n) => {\n return validateShoppingCartCore({ getShoppingCartNode }, config, headers);\n};\n","// Benefits utility functions\nimport { Benefit } from \"@artisan-commerce/types\";\nimport { getBenefitsNode as getBenefitsNodeCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { getWalletNode as getWalletNodeCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { getWallet as getWalletCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getDocumentsByCollections } from \"./firestore.utils\";\nimport { getCollectionReference } from \"./firestore.utils\";\nimport { BenefitsByUserNode } from \"../types/firestore.types\";\nimport { BenefitsByUserNodes } from \"../types/firestore.types\";\n\nexport { getInitialBenefitsWallet } from \"@artisan-commerce/shopping-cart-core\";\nexport { mapCollectionToBenefits } from \"@artisan-commerce/shopping-cart-core\";\nexport { updateBenefitsWallets } from \"@artisan-commerce/shopping-cart-core\";\n\n/**\n * Fetches all Artisn benefits of the given customer and account. It will first\n * try to look at the function config. If it cannot find any of the needed\n * parameters, it will look into the global config provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Shopping cart configuration\n * @returns {Promise<BenefitsByUserNodes | undefined>} A collection of benefits\n * of the given customer in the form of firestore document nodes\n */\nexport const getBenefitsNode = (\n config: ShoppingCartConfig = {}\n): Promise<BenefitsByUserNodes | undefined> => {\n return getBenefitsNodeCore(\n { getBenefitsCollection: getCollectionReference },\n config\n );\n};\n\n/**\n * Fetches the wallet node of the given customer and account. It will first try\n * to look at the function config. If it cannot find any of the needed\n * parameters, it will look into the global config provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Shopping cart configuration\n * @returns {Promise<BenefitsByUserNode | undefined>} The benefits of a given\n * customer in the form of firestore document nodes\n */\nexport const getWalletNode = async (\n config?: ShoppingCartConfig\n): Promise<BenefitsByUserNode | undefined> => {\n return getWalletNodeCore(\n { getBenefitsDocuments: getDocumentsByCollections },\n config\n );\n};\n\n/**\n * Fetches an array of benefits of the given customer and account. It will first\n * try to look at the function config. If it cannot find any of the needed\n * parameters, it will look into the global config provided in initShoppingCart.\n *\n * @since 0.1.0\n * @param {ShoppingCartConfig} config Shopping cart configuration\n * @returns {Promise<Benefit[] | undefined>} An array of benefits of the given\n * customer, each benefit has the firestore hash inside them.\n */\nexport const getWallet = async (\n config?: ShoppingCartConfig | undefined\n): Promise<Benefit[] | undefined> => {\n return getWalletCore(\n {\n getBenefitsCollection: getCollectionReference,\n getBenefitsDocuments: getDocumentsByCollections\n },\n config\n );\n};\n","// listenBenefitsWallet functions\nimport { Wallet } from \"@artisan-commerce/types\";\nimport { verifyHeaders } from \"@artisan-commerce/shopping-cart-core\";\nimport { unsubscriber } from \"@artisan-commerce/shopping-cart-core\";\nimport { fetchWalletByUser } from \"@artisan-commerce/shopping-cart-core\";\nimport { logError } from \"@artisan-commerce/shopping-cart-core\";\nimport { reuseGlobalConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { BenefitsWalletConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { WalletHeaders } from \"@artisan-commerce/shopping-cart-core\";\nimport { checkMinimumFetchWalletConfigProvided } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getState } from \"../state\";\nimport { getBenefitsNode } from \"../../utils/benefits.utils\";\nimport { updateBenefitsWallets } from \"../../utils/benefits.utils\";\nimport { mapCollectionToBenefits } from \"../../utils/benefits.utils\";\nimport { getInitialBenefitsWallet } from \"../../utils/benefits.utils\";\n\n/**\n * Listens on realtime to any change of the default or named wallet\n * of a given customer.\n *\n * @since 0.1.0\n * @param {Function} onSnapshot Callback function that\n * receives the latest wallet on any updates to the cart\n * @param {BenefitsWalletConfig} config Configuration object to fetch a wallet\n * @param {Partial<WalletHeaders>} headers Optional headers to be passed to\n * retrieve the wallet of the current user\n */\nexport const listenBenefitsWallet = (\n onSnapshot: (wallet: Wallet) => void,\n config: BenefitsWalletConfig,\n headers: Headers\n) => {\n const reusedConfig = reuseGlobalConfig(config);\n // Check minimum config to fetch wallet\n checkMinimumFetchWalletConfigProvided(reusedConfig);\n // Check minimum required headers\n verifyHeaders(headers);\n\n const { shoppingCartName, customerId, anonymous } = reusedConfig;\n const { wallets } = getState();\n const walletExists = wallets[shoppingCartName!];\n\n if (anonymous) return () => unsubscriber(shoppingCartName!);\n\n if (walletExists) {\n logError(\n `There is already a listener for wallet of name ${shoppingCartName}. Either unsubscribe to the other listener or create a new listener for a different cart`\n );\n return () => unsubscriber(shoppingCartName!);\n }\n // Saves an empty wallet so that walletExist clause will fire if 2 listeners\n // are fired synchronously\n const newWallet = getInitialBenefitsWallet();\n updateBenefitsWallets(shoppingCartName!, { ...newWallet, onSnapshot });\n\n let dbUnsubscriber: (() => void) | undefined = undefined;\n\n (async () => {\n const fetchConfig = { ...reusedConfig, customerId };\n try {\n // TODO: This function is called because initially firestore does not have\n // the coupons data. This endpoint call will be removed once the backend\n // supports these changes.\n await fetchWalletByUser(fetchConfig, headers as WalletHeaders);\n const benefitsNode = await getBenefitsNode(reusedConfig);\n if (!benefitsNode) {\n throw new Error(\"Failed to retrieve the benefits wallet node\");\n }\n\n // @ts-ignore Since it cannot infer whether it's a react native or a web app\n dbUnsubscriber = benefitsNode.onSnapshot(async collection => {\n const benefitsByUser = collection?.docs?.[0]?.data() ?? {};\n // Empty wallet\n if (Object.keys(benefitsByUser).length === 0) {\n const newWallet = getInitialBenefitsWallet();\n updateBenefitsWallets(shoppingCartName!, {\n ...newWallet,\n onSnapshot\n });\n onSnapshot(newWallet);\n return;\n }\n\n const hash = collection.docs[0].id;\n const benefits = mapCollectionToBenefits(benefitsByUser, hash);\n\n const newWallet = getInitialBenefitsWallet({\n benefits\n });\n\n updateBenefitsWallets(shoppingCartName!, { ...newWallet, onSnapshot });\n onSnapshot(newWallet);\n });\n } catch (e) {\n console.error(e.message);\n }\n })();\n\n return () => unsubscriber(shoppingCartName!, dbUnsubscriber);\n};\n","// applyBenefits functions\nimport { ShoppingCart, Benefit } from \"@artisan-commerce/types\";\nimport { ShippingCost } from \"@artisan-commerce/types\";\nimport { applyBenefit as applyBenefitCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { applyBenefitsHelper } from \"@artisan-commerce/shopping-cart-core\";\nimport { ApplyBenefitConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Apply a benefit with the given configuration on the current shopping cart.\n *\n * @since 0.1.0\n * @param {ApplyBenefitConfig} config Benefits wallet configuration and\n * parameters to be passed to apply in shopping cart\n */\n\nexport const applyBenefit = async (\n config: ApplyBenefitConfig,\n headers: Headers\n) => {\n return applyBenefitCore(\n { getShoppingCartNode, applyBenefitsToCart, setDoc },\n config,\n headers\n );\n};\n/**\n * Apply benefit to benefits array in shopping cart.\n *\n * @since 0.1.0\n * @param {ApplyBenefitConfig} config Benefits wallet configuration\n * @param {Benefit} benefit Benefit object to be applied\n * @param {ShippingCost} shippingCost ShippingCost object to be added\n * in the shopping cart\n */\nexport const applyBenefitsToCart = async (\n config: ApplyBenefitConfig,\n benefit: Benefit,\n shippingCost?: ShippingCost\n) => {\n // Get latest shopping cart\n const shoppingCartNode = await getShoppingCartNode(config);\n if (!shoppingCartNode) {\n console.warn(\n \"Cannot add benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.\"\n );\n return;\n }\n const shoppingCart = (await shoppingCartNode.data()) as ShoppingCart;\n // Apply benefits to cart\n const updatedCart = applyBenefitsHelper(shoppingCart, benefit, shippingCost);\n // Update cart remotely\n await shoppingCartNode.ref.set(updatedCart);\n};\n","// removeBenefits functions\nimport { ShoppingCart, Benefit, ShippingCost } from \"@artisan-commerce/types\";\nimport { removeBenefit as removeBenefitCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { removeBenefitsHelper } from \"@artisan-commerce/shopping-cart-core\";\nimport { RemoveBenefitConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { removeProduct } from \"../removeProduct/removeProduct\";\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Remove a benefit with the given config on the current shopping cart.\n *\n * @since 0.1.0\n * @param {RemoveBenefitConfig} config Benefits wallet configuration and\n * parameters to be passed to remove in shopping cart\n */\nexport const removeBenefit = (config: RemoveBenefitConfig) => {\n return removeBenefitCore(\n {\n getShoppingCartNode,\n removeBenefitsFromCart,\n removeProduct\n },\n config\n );\n};\n\n/**\n * Remove benefit from benefits array in shopping cart.\n *\n * @since 0.1.0\n * @param {RemoveBenefitConfig} config Benefits wallet configuration\n * @param {Benefit} benefit Benefit object to be removed\n * @param {ShippingCost} shippingCost ShippingCost object to be restored\n * in shopping cart\n */\nexport const removeBenefitsFromCart = async (\n config: RemoveBenefitConfig,\n benefit: Benefit,\n shippingCost?: ShippingCost\n) => {\n // Get latest shopping cart\n const shoppingCartNode = await getShoppingCartNode(config);\n if (!shoppingCartNode) {\n console.warn(\n `Cannot remove benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.`\n );\n return;\n }\n const shoppingCart = (await shoppingCartNode.data()) as ShoppingCart;\n // Remove benefits from cart\n const updatedCart = removeBenefitsHelper(shoppingCart, benefit, shippingCost);\n // Update cart remotely\n await shoppingCartNode.ref.set(updatedCart);\n};\n","// redeemCoupon functions\nimport { redeemCoupon as redeemCouponCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { BenefitsWalletConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getWallet } from \"../../utils/benefits.utils\";\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Redeems a coupon based on the code given.\n *\n * @since 0.1.0\n * @param {BenefitsWalletConfig} config Benefits wallet configuration parameters\n * to be passed to call the endpoint.\n * @param {string} code The code that the user inputs on the app.\n * @param {Partial<WalletHeaders>} headers Headers to be passed to call the\n * endpoint, as a default header, the uid is fetched internally\n */\nexport const redeemCoupon = async (\n config: BenefitsWalletConfig,\n code: string,\n headers: Headers\n) => {\n return redeemCouponCore(\n { getWallet, getShoppingCartNode },\n config,\n code,\n headers\n );\n};\n","// mergeShoppingCart functions\nimport { ShoppingCart } from \"@artisan-commerce/types\";\nimport { mergeShoppingCart as mergeShoppingCartCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\nimport { setDoc } from \"../../utils/firestore.utils\";\n\n/**\n * Merge a shopping cart to the current shopping cart or to the one specified\n * through the configuration.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {ShoppingCart} shoppingCart Shopping cart to be merged\n * @param {ShoppingCartConfig} config Configuration to get the current shopping\n * cart\n */\nexport const mergeShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n shoppingCart: T,\n config?: ShoppingCartConfig\n) => {\n return mergeShoppingCartCore(\n { getShoppingCartNode, setDoc },\n shoppingCart,\n config\n );\n};\n","import { FindProductConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { findProduct as findProductCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { AdditionalInfo, CartProduct } from \"@artisan-commerce/types\";\n\nimport { getShoppingCartNode } from \"../lib/fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Returns the specified product based on its id or hash if it exists on the\n * active shopping cart. If both are provided, the hash takes precedence\n * over the product id.\n *\n * @param {FindProductConfig} config Configuration provided to find the\n * desired product\n * @returns {Promise<Product|undefined>} The product if found in the\n * shopping cart\n */\nexport const findProduct = async <\n T extends AdditionalInfo = AdditionalInfo,\n U extends AdditionalInfo = AdditionalInfo\n>(\n config: FindProductConfig\n): Promise<CartProduct<T, U> | undefined> => {\n return findProductCore({ getShoppingCartNode }, config);\n};\n","// updateShoppingCart functions\nimport { ShoppingCart } from \"@artisan-commerce/types\";\nimport { updateShoppingCart as updateShoppingCartCore } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { setDoc } from \"../../utils/firestore.utils\";\nimport { getShoppingCartNode } from \"../fetchShoppingCart/fetchShoppingCart\";\n\n/**\n * Sets properties in the shopping cart remotely.\n *\n * @template T Shopping cart generic type\n * @since 0.1.0\n * @param {Function} shoppingCart The cart that will be set remotely\n * @param {ShoppingCartConfig} config Shopping cart configuration\n */\nexport const updateShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n setShoppingCart: (previousShoppingCart: T) => T,\n config?: ShoppingCartConfig\n) => {\n return updateShoppingCartCore(\n { getShoppingCartNode, setDoc },\n setShoppingCart,\n config\n );\n};\n"],"names":["reuseGlobalConfig","checkInitialized","checkMinimumConfigProvided","firestore","checkInit","getShoppingCartHelper","setState","logDebug","__defProp","__defProps","__getOwnPropDescs","__getOwnPropSymbols","__hasOwnProp","__propIsEnum","__defNormalProp","__spreadValues","__spreadProps","buildInitialShoppingCart","getState","addProductCore","subtractProductCore","removeProductCore","setProductCore","replaceProductCore","emptyShoppingCartCore","deleteShoppingCartCore","validateShoppingCartCore","getBenefitsNodeCore","getWalletCore","checkMinimumFetchWalletConfigProvided","verifyHeaders","unsubscriber","logError","getInitialBenefitsWallet","updateBenefitsWallets","fetchWalletByUser","mapCollectionToBenefits","applyBenefitCore","applyBenefitsHelper","removeBenefitCore","removeBenefitsHelper","redeemCouponCore","mergeShoppingCartCore","findProductCore","updateShoppingCartCore"],"mappings":";;;;;;;;;;;AAQO,MAAM,oBAAoB,GAAG,OAAO,MAAM,GAAG,EAAE,KAAK;AAC3D,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACb,EAAE,MAAM,YAAY,GAAGA,kCAAiB,CAAC,MAAM,CAAC,CAAC;AACjD,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC;AAC5D,EAAEC,iCAAgB,EAAE,CAAC;AACrB,EAAEC,2CAA0B,CAAC,YAAY,CAAC,CAAC;AAC3C,EAAE,MAAM,IAAI,GAAG,SAAS,GAAG,6BAA6B,GAAG,oBAAoB,CAAC;AAChF,EAAE,MAAM,EAAE,GAAGC,6BAAS,EAAE,CAAC;AACzB,EAAE,MAAM,eAAe,GAAG,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,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