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

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,337 @@
1
+ 'use strict';
2
+
3
+ var shoppingCartCore = require('@artisan-commerce/shopping-cart-core');
4
+ var firestore = require('@react-native-firebase/firestore');
5
+
6
+ const getShoppingCartNodes = (config) => {
7
+ var _a, _b;
8
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
9
+ const { accountId, customerId, anonymous } = reusedConfig;
10
+ shoppingCartCore.checkMinimumConfigProvided(reusedConfig);
11
+ const path = anonymous ? "anonymousShoppingCartByUser" : "shoppingCartByUser";
12
+ const db = firestore();
13
+ const cartsCollection = (_b = (_a = db == null ? void 0 : db.collection(path)) == null ? void 0 : _a.doc(String(customerId))) == null ? void 0 : _b.collection(String(accountId));
14
+ return cartsCollection;
15
+ };
16
+ const getShoppingCartNode = async (config) => {
17
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
18
+ const { shoppingCartName } = reusedConfig;
19
+ const cartsCollection = getShoppingCartNodes(reusedConfig);
20
+ if (!cartsCollection)
21
+ return;
22
+ const newestCart = await cartsCollection.where("name", "==", shoppingCartName).get().then((userCarts) => {
23
+ return userCarts.docs[0];
24
+ });
25
+ return newestCart;
26
+ };
27
+ const getShoppingCart = (config) => {
28
+ return shoppingCartCore.getShoppingCart({ getShoppingCartNode }, config);
29
+ };
30
+ const listenShoppingCart = (onSnapshot, config) => {
31
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
32
+ const { shoppingCartName } = reusedConfig;
33
+ const shoppingCartDocs = getShoppingCartNodes(reusedConfig);
34
+ if (!shoppingCartDocs) {
35
+ return () => {
36
+ };
37
+ }
38
+ shoppingCartCore.State().setState({ activeShoppingCart: shoppingCartName });
39
+ return shoppingCartDocs.where("name", "==", shoppingCartName).onSnapshot((snapshot) => {
40
+ var _a;
41
+ if (!((_a = snapshot == null ? void 0 : snapshot.docs) == null ? void 0 : _a[0])) {
42
+ shoppingCartCore.logDebug(`Failed to fetch a shopping cart with name ${shoppingCartName} because there wasn't any.`);
43
+ return onSnapshot(void 0);
44
+ }
45
+ const cart = snapshot.docs[0].data();
46
+ if ((cart == null ? void 0 : cart.id) === "" || (cart == null ? void 0 : cart.id) === null)
47
+ return;
48
+ return onSnapshot(cart);
49
+ });
50
+ };
51
+
52
+ const setDoc = async (config) => {
53
+ const { payload, shoppingCartNode } = config != null ? config : {};
54
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.set(payload));
55
+ };
56
+ const deleteDoc = async (config) => {
57
+ const { shoppingCartNode } = config != null ? config : {};
58
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.delete());
59
+ };
60
+ const getCollectionReference = async (collectionName, ...path) => {
61
+ var _a, _b;
62
+ const [customerId, accountId] = path;
63
+ const db = firestore();
64
+ 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)));
65
+ return collection;
66
+ };
67
+ const getDocumentsByCollections = async (collectionReference) => {
68
+ const queryDocuments = await collectionReference.get().then((result) => result.docs[0]);
69
+ return queryDocuments;
70
+ };
71
+
72
+ var __defProp$1 = Object.defineProperty;
73
+ var __defProps$1 = Object.defineProperties;
74
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
75
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
76
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
77
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
78
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
79
+ var __spreadValues$1 = (a, b) => {
80
+ for (var prop in b || (b = {}))
81
+ if (__hasOwnProp$1.call(b, prop))
82
+ __defNormalProp$1(a, prop, b[prop]);
83
+ if (__getOwnPropSymbols$1)
84
+ for (var prop of __getOwnPropSymbols$1(b)) {
85
+ if (__propIsEnum$1.call(b, prop))
86
+ __defNormalProp$1(a, prop, b[prop]);
87
+ }
88
+ return a;
89
+ };
90
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
91
+ const createShoppingCart = async (config, overrides = {}) => {
92
+ return new Promise((resolve, reject) => {
93
+ const action = async () => {
94
+ var _a;
95
+ try {
96
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
97
+ const { shoppingCartName } = reusedConfig;
98
+ const cartsCollection = getShoppingCartNodes(reusedConfig);
99
+ const newShoppingCart = shoppingCartCore.createShoppingCartSync(__spreadValues$1({
100
+ name: shoppingCartName,
101
+ channelId: config == null ? void 0 : config.channelId
102
+ }, overrides));
103
+ if (!cartsCollection) {
104
+ console.warn(`Couldn't find a shopping cart collection with the given config.
105
+ Please make sure everything is correct in your configuration
106
+ before continue.`);
107
+ resolve(null);
108
+ return null;
109
+ }
110
+ const { name } = newShoppingCart;
111
+ const numberOfCarts = (_a = await cartsCollection.get()) == null ? void 0 : _a.docs.length;
112
+ const maxNumberOfCarts = shoppingCartCore.State().state.maxShoppingCarts;
113
+ if (numberOfCarts >= maxNumberOfCarts) {
114
+ throw new Error(`Cannot add more carts. Carts limit (${maxNumberOfCarts}) reached.`);
115
+ }
116
+ const namedCartsDocs = await cartsCollection.where("name", "==", name).get();
117
+ const cartsLength = namedCartsDocs.docs.length;
118
+ if (cartsLength > 0) {
119
+ throw new Error(`Attempted to create a shopping cart with the name ${name}, but there is already one shopping cart with that name.`);
120
+ }
121
+ const node = await cartsCollection.add(newShoppingCart);
122
+ if (!node) {
123
+ console.error("Failed to create a new shopping cart");
124
+ resolve(null);
125
+ return null;
126
+ }
127
+ const updatedCart = __spreadProps$1(__spreadValues$1({}, newShoppingCart), { id: node.id });
128
+ await node.set(updatedCart);
129
+ resolve(updatedCart);
130
+ return updatedCart;
131
+ } catch (e) {
132
+ reject(e);
133
+ return null;
134
+ }
135
+ };
136
+ const { eventLoop, queue } = shoppingCartCore.State().state;
137
+ queue.enqueue(action);
138
+ if (!eventLoop.isRunning)
139
+ eventLoop.start();
140
+ });
141
+ };
142
+
143
+ const addProduct = (product, config) => {
144
+ return shoppingCartCore.addProduct({ getShoppingCartNode, setDoc, createShoppingCart }, product, config);
145
+ };
146
+
147
+ const subtractProduct = async (product, config) => {
148
+ return shoppingCartCore.subtractProduct({ getShoppingCartNode, setDoc }, product, config);
149
+ };
150
+
151
+ const removeProduct = (product, config) => {
152
+ return shoppingCartCore.removeProduct({ getShoppingCartNode, setDoc }, product, config);
153
+ };
154
+
155
+ const setProduct = async (product, config) => {
156
+ return shoppingCartCore.setProduct({ getShoppingCartNode, setDoc }, product, config);
157
+ };
158
+
159
+ const replaceProduct = (product, config) => {
160
+ return shoppingCartCore.replaceProduct({ getShoppingCartNode, setDoc }, product, config);
161
+ };
162
+
163
+ const emptyShoppingCart = async (config) => await shoppingCartCore.emptyShoppingCart({ getShoppingCartNode, setDoc }, config);
164
+
165
+ const deleteShoppingCart = async (config) => await shoppingCartCore.deleteShoppingCart({ getShoppingCartNode, deleteDoc }, config);
166
+
167
+ const validateShoppingCart = (config, headers = new Headers()) => {
168
+ return shoppingCartCore.validateShoppingCart({ getShoppingCartNode }, config, headers);
169
+ };
170
+
171
+ const getBenefitsNode = (config) => {
172
+ return shoppingCartCore.getBenefitsNode({ getBenefitsCollection: getCollectionReference }, config);
173
+ };
174
+ const getWallet = async (config) => {
175
+ return shoppingCartCore.getWallet({
176
+ getBenefitsCollection: getCollectionReference,
177
+ getBenefitsDocuments: getDocumentsByCollections
178
+ }, config);
179
+ };
180
+
181
+ var __defProp = Object.defineProperty;
182
+ var __defProps = Object.defineProperties;
183
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
184
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
185
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
186
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
187
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
188
+ var __spreadValues = (a, b) => {
189
+ for (var prop in b || (b = {}))
190
+ if (__hasOwnProp.call(b, prop))
191
+ __defNormalProp(a, prop, b[prop]);
192
+ if (__getOwnPropSymbols)
193
+ for (var prop of __getOwnPropSymbols(b)) {
194
+ if (__propIsEnum.call(b, prop))
195
+ __defNormalProp(a, prop, b[prop]);
196
+ }
197
+ return a;
198
+ };
199
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
200
+ const listenBenefitsWallet = (onSnapshot, config, headers = new Headers()) => {
201
+ const selectedHeaders = shoppingCartCore.buildServiceHeaders(headers);
202
+ const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
203
+ shoppingCartCore.checkMinimumFetchWalletConfigProvided(reusedConfig);
204
+ shoppingCartCore.verifyHeaders(selectedHeaders);
205
+ const { shoppingCartName, customerId, anonymous } = reusedConfig;
206
+ const { wallets } = shoppingCartCore.State().state;
207
+ const walletExists = wallets[shoppingCartName];
208
+ if (anonymous)
209
+ return () => shoppingCartCore.listenBenefitsWalletUnsubscribe(shoppingCartName);
210
+ if (walletExists) {
211
+ 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`);
212
+ return () => shoppingCartCore.listenBenefitsWalletUnsubscribe(shoppingCartName);
213
+ }
214
+ const newWallet = shoppingCartCore.getInitialBenefitsWallet();
215
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet), { onSnapshot }));
216
+ let dbUnsubscriber = void 0;
217
+ (async () => {
218
+ const fetchConfig = __spreadProps(__spreadValues({}, reusedConfig), { customerId });
219
+ try {
220
+ await shoppingCartCore.fetchWalletByUser(fetchConfig, selectedHeaders);
221
+ const benefitsNode = await getBenefitsNode(reusedConfig);
222
+ if (!benefitsNode) {
223
+ throw new Error("Failed to retrieve the benefits wallet node");
224
+ }
225
+ dbUnsubscriber = benefitsNode.onSnapshot(async (collection) => {
226
+ var _a, _b, _c;
227
+ const benefitsByUser = (_c = (_b = (_a = collection == null ? void 0 : collection.docs) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()) != null ? _c : {};
228
+ if (Object.keys(benefitsByUser).length === 0) {
229
+ const newWallet3 = shoppingCartCore.getInitialBenefitsWallet();
230
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet3), {
231
+ onSnapshot
232
+ }));
233
+ onSnapshot(newWallet3);
234
+ return;
235
+ }
236
+ const hash = collection.docs[0].id;
237
+ const benefits = shoppingCartCore.mapCollectionToBenefits(benefitsByUser, hash);
238
+ const newWallet2 = shoppingCartCore.getInitialBenefitsWallet({
239
+ benefits
240
+ });
241
+ shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet2), { onSnapshot }));
242
+ onSnapshot(newWallet2);
243
+ });
244
+ } catch (e) {
245
+ console.error(e.message);
246
+ }
247
+ })();
248
+ return () => shoppingCartCore.listenBenefitsWalletUnsubscribe(shoppingCartName, dbUnsubscriber);
249
+ };
250
+
251
+ const applyBenefit = async (config, headers = new Headers()) => {
252
+ return shoppingCartCore.applyBenefit({ getShoppingCartNode, applyBenefitsToCart, setDoc }, config, headers);
253
+ };
254
+ const applyBenefitsToCart = async (config, benefit, shippingCost) => {
255
+ const shoppingCartNode = await getShoppingCartNode(config);
256
+ if (!shoppingCartNode) {
257
+ console.warn("Cannot add benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.");
258
+ return;
259
+ }
260
+ const shoppingCart = await shoppingCartNode.data();
261
+ const updatedCart = shoppingCartCore.applyBenefitSync(shoppingCart, benefit, shippingCost);
262
+ await shoppingCartNode.ref.set(updatedCart);
263
+ };
264
+
265
+ const removeBenefit = (config) => {
266
+ return shoppingCartCore.removeBenefit({
267
+ getShoppingCartNode,
268
+ removeBenefitsFromCart,
269
+ removeProduct
270
+ }, config);
271
+ };
272
+ const removeBenefitsFromCart = async (config, benefit, shippingCost) => {
273
+ const shoppingCartNode = await getShoppingCartNode(config);
274
+ if (!shoppingCartNode) {
275
+ console.warn(`Cannot remove benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.`);
276
+ return;
277
+ }
278
+ const shoppingCart = await shoppingCartNode.data();
279
+ const updatedCart = shoppingCartCore.removeBenefitsHelper(shoppingCart, benefit, shippingCost);
280
+ await shoppingCartNode.ref.set(updatedCart);
281
+ };
282
+
283
+ const redeemCoupon = async (config, code, headers = new Headers()) => {
284
+ return shoppingCartCore.redeemCoupon({ getWallet, getShoppingCartNode }, config, code, headers);
285
+ };
286
+
287
+ const mergeShoppingCart = async (shoppingCart, config) => {
288
+ return shoppingCartCore.mergeShoppingCart({ getShoppingCartNode, setDoc }, shoppingCart, config);
289
+ };
290
+
291
+ const findProduct = async (config) => {
292
+ return shoppingCartCore.findProduct({ getShoppingCartNode }, config);
293
+ };
294
+
295
+ const updateShoppingCart = async (setShoppingCart, config) => {
296
+ return shoppingCartCore.updateShoppingCart({ getShoppingCartNode, setDoc }, setShoppingCart, config);
297
+ };
298
+
299
+ Object.defineProperty(exports, 'fetchStoreCouponDetail', {
300
+ enumerable: true,
301
+ get: function () { return shoppingCartCore.fetchStoreCouponDetail; }
302
+ });
303
+ Object.defineProperty(exports, 'fetchStoreCoupons', {
304
+ enumerable: true,
305
+ get: function () { return shoppingCartCore.fetchStoreCoupons; }
306
+ });
307
+ Object.defineProperty(exports, 'getProductHash', {
308
+ enumerable: true,
309
+ get: function () { return shoppingCartCore.getProductHash; }
310
+ });
311
+ Object.defineProperty(exports, 'getShoppingCartProducts', {
312
+ enumerable: true,
313
+ get: function () { return shoppingCartCore.getShoppingCartProducts; }
314
+ });
315
+ Object.defineProperty(exports, 'getShoppingCartTotal', {
316
+ enumerable: true,
317
+ get: function () { return shoppingCartCore.getShoppingCartTotal; }
318
+ });
319
+ exports.addProduct = addProduct;
320
+ exports.applyBenefit = applyBenefit;
321
+ exports.createShoppingCart = createShoppingCart;
322
+ exports.deleteShoppingCart = deleteShoppingCart;
323
+ exports.emptyShoppingCart = emptyShoppingCart;
324
+ exports.findProduct = findProduct;
325
+ exports.getShoppingCart = getShoppingCart;
326
+ exports.listenBenefitsWallet = listenBenefitsWallet;
327
+ exports.listenShoppingCart = listenShoppingCart;
328
+ exports.mergeShoppingCart = mergeShoppingCart;
329
+ exports.redeemCoupon = redeemCoupon;
330
+ exports.removeBenefit = removeBenefit;
331
+ exports.removeProduct = removeProduct;
332
+ exports.replaceProduct = replaceProduct;
333
+ exports.setProduct = setProduct;
334
+ exports.subtractProduct = subtractProduct;
335
+ exports.updateShoppingCart = updateShoppingCart;
336
+ exports.validateShoppingCart = validateShoppingCart;
337
+ //# sourceMappingURL=bundle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.cjs","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 { 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 { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartFetchConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { checkMinimumConfigProvided } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { State } 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.\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 = (\n config: ShoppingCartFetchConfig\n): ShoppingCartNodes | undefined => {\n const reusedConfig = reuseGlobalConfig(config);\n const { accountId, customerId, anonymous } = reusedConfig;\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 = 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.\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: ShoppingCartFetchConfig\n): Promise<ShoppingCartNode | undefined> => {\n // Get all user remote shopping carts\n const reusedConfig = reuseGlobalConfig(config);\n const { shoppingCartName } = reusedConfig;\n const cartsCollection = getShoppingCartNodes(reusedConfig);\n if (!cartsCollection) 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.\n * .\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?: ShoppingCartFetchConfig) => {\n return getShoppingCartHelper(\n { getShoppingCartNode },\n config as ShoppingCartConfig\n );\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 = <T extends ShoppingCart = ShoppingCart>(\n onSnapshot: (shoppingCart: T | undefined) => void,\n config: ShoppingCartFetchConfig\n) => {\n const reusedConfig = reuseGlobalConfig(config);\n const { shoppingCartName } = reusedConfig;\n const shoppingCartDocs = getShoppingCartNodes(reusedConfig);\n if (!shoppingCartDocs) {\n return () => {};\n }\n State().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(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 cart = snapshot.docs[0].data() as T;\n // cart?.id === \"\" Just created but not yet ready.\n // cart?.id === null is when cart is rebuilt from backend.\n if (cart?.id === \"\" || cart?.id === null) return;\n return onSnapshot(cart);\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 { createShoppingCartSync } from \"@artisan-commerce/shopping-cart-core\";\nimport { reuseGlobalConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartCreateConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { State } 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 = getShoppingCartNodes(reusedConfig);\n const newShoppingCart = createShoppingCartSync({\n name: shoppingCartName,\n channelId: config?.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 = State().state.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 } = State().state;\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 = new 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.\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.\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.\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\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 { buildServiceHeaders } from \"@artisan-commerce/shopping-cart-core\";\nimport { listenBenefitsWalletUnsubscribe as 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 { State } 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 = new Headers()\n) => {\n const selectedHeaders = buildServiceHeaders(headers);\n const reusedConfig = reuseGlobalConfig(config);\n // Check minimum config to fetch wallet\n checkMinimumFetchWalletConfigProvided(reusedConfig);\n // Check minimum required headers\n verifyHeaders(selectedHeaders);\n\n const { shoppingCartName, customerId, anonymous } = reusedConfig;\n const { wallets } = State().state;\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, selectedHeaders 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 { applyBenefitSync } 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 = new 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 = applyBenefitSync(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 = new 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 { ShoppingCartMergeConfig } 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 {ShoppingCartMergeConfig} config Configuration to get the current shopping\n * cart\n */\nexport const mergeShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n shoppingCart: T,\n config: ShoppingCartMergeConfig\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","checkMinimumConfigProvided","getShoppingCartHelper","State","logDebug","createShoppingCartSync","__spreadValues","__spreadProps","addProductCore","subtractProductCore","removeProductCore","setProductCore","replaceProductCore","emptyShoppingCartCore","deleteShoppingCartCore","validateShoppingCartCore","getBenefitsNodeCore","getWalletCore","buildServiceHeaders","checkMinimumFetchWalletConfigProvided","verifyHeaders","unsubscriber","logError","getInitialBenefitsWallet","updateBenefitsWallets","fetchWalletByUser","mapCollectionToBenefits","applyBenefitCore","applyBenefitSync","removeBenefitCore","removeBenefitsHelper","redeemCouponCore","mergeShoppingCartCore","findProductCore","updateShoppingCartCore"],"mappings":";;;;;AAoBa,MAAA,oBAAA,GAAuB,CAClC,MACkC,KAAA;AAtBp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,MACG,KAAA;AACH,EAAA,OAAOC,kCACL,CAAA,EAAE,mBAAqB,EAAA,MAAA,EAAA,EACvB,YACA,EAAA,MAAA,CAAA,CAAA;AAAA;;ACTS,MAAA,WAAA,GAAc,OAIzB,MAC2C,KAAA;AAC3C,EAAO,OAAAC,4BAAA,CAAgB,EAAE,mBAAuB,EAAA,EAAA,MAAA,CAAA,CAAA;AAAA;;ACNrC,MAAA,kBAAA,GAAqB,OAChC,eAAA,EACA,MACG,KAAA;AACH,EAAA,OAAOC,mCACL,CAAA,EAAE,mBAAqB,EAAA,MAAA,EAAA,EACvB,eACA,EAAA,MAAA,CAAA,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,219 @@
1
+ import * as _artisan_commerce_shopping_cart_core from '@artisan-commerce/shopping-cart-core';
2
+ import { ShoppingCartFetchConfig, ProductAddConfig, ProductActionConfig, ProductRemoveConfig, ProductSetConfig, ProductReplaceConfig, ShoppingCartCreateConfig, EmptyShoppingCartConfig, ShoppingCartConfig, BenefitsWalletConfig, ApplyBenefitConfig, RemoveBenefitConfig, ShoppingCartMergeConfig, FindProductConfig } from '@artisan-commerce/shopping-cart-core';
3
+ export { ProductActionConfig, ShoppingCartTotals, ValidateShoppingCartResult, fetchStoreCouponDetail, fetchStoreCoupons, getProductHash, getShoppingCartProducts, getShoppingCartTotal } from '@artisan-commerce/shopping-cart-core';
4
+ import * as _artisan_commerce_types from '@artisan-commerce/types';
5
+ import { ShoppingCart, Product, CartProduct, Wallet, AdditionalInfo } from '@artisan-commerce/types';
6
+
7
+ /**
8
+ * Fetches a shopping cart of the given customer and account, given by the
9
+ * specified name.
10
+ * .
11
+ *
12
+ * @since 0.1.0
13
+ * @param config Function call level shopping cart configuration
14
+ * @returns The shopping cart of a given customer given by its specified name
15
+ */
16
+ declare const getShoppingCart: (config?: ShoppingCartFetchConfig) => Promise<ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
17
+ /**
18
+ * Listens on realtime to any change of the default or
19
+ * named shopping cart of a given customer.
20
+ *
21
+ * @template T Shopping cart generic type
22
+ * @since 0.1.0
23
+ * @param {Function} onSnapshot Callback function that receives the latest
24
+ * shopping cart on any updates to the cart
25
+ * @param {ShoppingCartConfig} config Shopping cart custom configuration
26
+ */
27
+ declare const listenShoppingCart: <T extends ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> = ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo>>(onSnapshot: (shoppingCart: T | undefined) => void, config: ShoppingCartFetchConfig) => () => void;
28
+
29
+ declare const addProduct: (product: Product, config: ProductAddConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
30
+
31
+ /**
32
+ * Subtracts a product amount async to the remote shopping cart.
33
+ *
34
+ * @template T Shopping cart generic type
35
+ * @since 0.1.0
36
+ * @param {Product} product The product object that will be subtracted from the
37
+ * cart. It can be a BaseProduct, a DetailedProduct or a CartProduct
38
+ * @param {ProductActionConfig} config A configuration that specifies how to
39
+ * make an action over a product. E.g specify the amount
40
+ */
41
+ declare const subtractProduct: (product: Product, config: ProductActionConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
42
+
43
+ /**
44
+ * Removes a product async from the remote shopping cart
45
+ *
46
+ * @template T Shopping cart generic type
47
+ * @since 0.1.0
48
+ * @param {Product} product the product object that will be removed from the
49
+ * cart. It can be a BaseProduct, a DetailedProduct or a CartProduct
50
+ * @param {ProductRemoveConfig} config global configuration overrides. E.g
51
+ * storeId
52
+ */
53
+ declare const removeProduct: (product: Product, config: ProductRemoveConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
54
+
55
+ /**
56
+ * Sets a product async in the remote shopping cart
57
+ *
58
+ * @template T Shopping cart generic type
59
+ * @since 0.1.0
60
+ * @param {Product} product The product object that will be set in the cart. It
61
+ * can be a BaseProduct, a DetailedProduct or a CartProduct
62
+ * @param {ProductSetConfig} config A configuration that specifies how to make
63
+ * an action over a product. E.g specify the amount
64
+ */
65
+ declare const setProduct: (product: Product, config: ProductSetConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
66
+
67
+ /**
68
+ * Replaces an existing product async in the remote shopping cart
69
+ *
70
+ * @template T Shopping cart generic type
71
+ * @since 0.1.0
72
+ * @param {CartProduct} product The product object that will be replaced in the
73
+ * cart. It can only be a CartProduct
74
+ * @param {ProductReplaceConfig} config A configuration that specifies how to
75
+ * make an action over a product. E.g specify the store
76
+ */
77
+ declare const replaceProduct: (product: CartProduct, config: ProductReplaceConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
78
+
79
+ /**
80
+ * Creates a new shopping cart to the authenticated user.
81
+ *
82
+ * @template T Shopping cart generic type
83
+ * @since 0.1.0
84
+ * @param {Partial<ShoppingCart>} overrides Initial state for one or
85
+ * more shopping cart properties
86
+ * @param {ShoppingCartCreateConfig} config Shopping cart custom configuration
87
+ */
88
+ declare const createShoppingCart: <T extends ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> = ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo>>(config: ShoppingCartCreateConfig, overrides?: Partial<T>) => Promise<T | null>;
89
+
90
+ /**
91
+ * Removes all products in all stores of a given cart. It will attempt to delete
92
+ * the last active shopping cart otherwise the default.
93
+ *
94
+ * If a vendor identifier is specified in the configuration object, it will
95
+ * remove all stores that have the specified vendor.
96
+ *
97
+ * @template T Shopping cart generic type
98
+ * @since 0.1.0
99
+ * @param {ShoppingCartConfig} config Empty shopping cart configuration
100
+ */
101
+ declare const emptyShoppingCart: (config: EmptyShoppingCartConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
102
+
103
+ /**
104
+ * Deletes a customer shopping cart given by its name. It will attempt to delete
105
+ * the last active shopping cart otherwise the default.
106
+ *
107
+ * @template T Shopping cart generic type
108
+ * @since 0.1.0
109
+ * @param {ShoppingCartConfig} config Function call level shopping cart
110
+ * configuration
111
+ */
112
+ declare const deleteShoppingCart: (config: ShoppingCartConfig) => Promise<_artisan_commerce_types.ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | null>;
113
+
114
+ /**
115
+ * Shopping cart validation options.
116
+ *
117
+ * @interface ValidateConfig
118
+ * @since 0.1.0
119
+ */
120
+ interface ValidateConfig extends ShoppingCartConfig {
121
+ /** Location latitude of the user */
122
+ latitude?: number;
123
+ /** Location latitude of the user */
124
+ longitude?: number;
125
+ /** Artisn project api url */
126
+ apiURL?: string;
127
+ }
128
+
129
+ /**
130
+ * Validate shopping cart integrity.
131
+ *
132
+ * @since 0.1.0
133
+ * @param {ValidateConfig} config Object that defines the properties to check
134
+ * whether the shopping cart is valid.
135
+ * @param {Partial<ValidateHeaders>} headers The shopping cart that will be
136
+ * validated. If none provided, then it will use default as its name.
137
+ * @return {Promise<ValidateShoppingCartResult | undefined>} An object which
138
+ * contains stores and products alerts
139
+ */
140
+ declare const validateShoppingCart: (config: ValidateConfig, headers?: Headers) => Promise<_artisan_commerce_shopping_cart_core.ValidateShoppingCartResult | undefined>;
141
+
142
+ /**
143
+ * Listens on realtime to any change of the default or named wallet
144
+ * of a given customer.
145
+ *
146
+ * @since 0.1.0
147
+ * @param {Function} onSnapshot Callback function that
148
+ * receives the latest wallet on any updates to the cart
149
+ * @param {BenefitsWalletConfig} config Configuration object to fetch a wallet
150
+ * @param {Partial<WalletHeaders>} headers Optional headers to be passed to
151
+ * retrieve the wallet of the current user
152
+ */
153
+ declare const listenBenefitsWallet: (onSnapshot: (wallet: Wallet) => void, config: BenefitsWalletConfig, headers?: Headers) => () => void;
154
+
155
+ /**
156
+ * Apply a benefit with the given configuration on the current shopping cart.
157
+ *
158
+ * @since 0.1.0
159
+ * @param {ApplyBenefitConfig} config Benefits wallet configuration and
160
+ * parameters to be passed to apply in shopping cart
161
+ */
162
+ declare const applyBenefit: (config: ApplyBenefitConfig, headers?: Headers) => Promise<void>;
163
+
164
+ /**
165
+ * Remove a benefit with the given config on the current shopping cart.
166
+ *
167
+ * @since 0.1.0
168
+ * @param {RemoveBenefitConfig} config Benefits wallet configuration and
169
+ * parameters to be passed to remove in shopping cart
170
+ */
171
+ declare const removeBenefit: (config: RemoveBenefitConfig) => Promise<void>;
172
+
173
+ /**
174
+ * Redeems a coupon based on the code given.
175
+ *
176
+ * @since 0.1.0
177
+ * @param {BenefitsWalletConfig} config Benefits wallet configuration parameters
178
+ * to be passed to call the endpoint.
179
+ * @param {string} code The code that the user inputs on the app.
180
+ * @param {Partial<WalletHeaders>} headers Headers to be passed to call the
181
+ * endpoint, as a default header, the uid is fetched internally
182
+ */
183
+ declare const redeemCoupon: (config: BenefitsWalletConfig, code: string, headers?: Headers) => Promise<void>;
184
+
185
+ /**
186
+ * Merge a shopping cart to the current shopping cart or to the one specified
187
+ * through the configuration.
188
+ *
189
+ * @template T Shopping cart generic type
190
+ * @since 0.1.0
191
+ * @param {ShoppingCart} shoppingCart Shopping cart to be merged
192
+ * @param {ShoppingCartMergeConfig} config Configuration to get the current shopping
193
+ * cart
194
+ */
195
+ declare const mergeShoppingCart: <T extends ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> = ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo>>(shoppingCart: T, config: ShoppingCartMergeConfig) => Promise<T | null>;
196
+
197
+ /**
198
+ * Returns the specified product based on its id or hash if it exists on the
199
+ * active shopping cart. If both are provided, the hash takes precedence
200
+ * over the product id.
201
+ *
202
+ * @param {FindProductConfig} config Configuration provided to find the
203
+ * desired product
204
+ * @returns {Promise<Product|undefined>} The product if found in the
205
+ * shopping cart
206
+ */
207
+ declare const findProduct: <T extends AdditionalInfo = AdditionalInfo, U extends AdditionalInfo = AdditionalInfo>(config: FindProductConfig) => Promise<CartProduct<T, U> | undefined>;
208
+
209
+ /**
210
+ * Sets properties in the shopping cart remotely.
211
+ *
212
+ * @template T Shopping cart generic type
213
+ * @since 0.1.0
214
+ * @param {Function} shoppingCart The cart that will be set remotely
215
+ * @param {ShoppingCartConfig} config Shopping cart configuration
216
+ */
217
+ declare const updateShoppingCart: <T extends ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> = ShoppingCart<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo>>(setShoppingCart: (previousShoppingCart: T) => T, config: ShoppingCartConfig) => Promise<T | null>;
218
+
219
+ export { addProduct, applyBenefit, createShoppingCart, deleteShoppingCart, emptyShoppingCart, findProduct, getShoppingCart, listenBenefitsWallet, listenShoppingCart, mergeShoppingCart, redeemCoupon, removeBenefit, removeProduct, replaceProduct, setProduct, subtractProduct, updateShoppingCart, validateShoppingCart };
@@ -0,0 +1,299 @@
1
+ import { getShoppingCart as getShoppingCart$1, reuseGlobalConfig, State, logDebug, checkMinimumConfigProvided, createShoppingCartSync, addProduct as addProduct$1, subtractProduct as subtractProduct$1, removeProduct as removeProduct$1, setProduct as setProduct$1, replaceProduct as replaceProduct$1, emptyShoppingCart as emptyShoppingCart$1, deleteShoppingCart as deleteShoppingCart$1, validateShoppingCart as validateShoppingCart$1, getBenefitsNode as getBenefitsNode$1, getWallet as getWallet$1, buildServiceHeaders, checkMinimumFetchWalletConfigProvided, verifyHeaders, listenBenefitsWalletUnsubscribe, logError, getInitialBenefitsWallet, updateBenefitsWallets, fetchWalletByUser, mapCollectionToBenefits, applyBenefit as applyBenefit$1, applyBenefitSync, removeBenefit as removeBenefit$1, removeBenefitsHelper, redeemCoupon as redeemCoupon$1, mergeShoppingCart as mergeShoppingCart$1, findProduct as findProduct$1, updateShoppingCart as updateShoppingCart$1 } from '@artisan-commerce/shopping-cart-core';
2
+ export { fetchStoreCouponDetail, fetchStoreCoupons, getProductHash, getShoppingCartProducts, getShoppingCartTotal } from '@artisan-commerce/shopping-cart-core';
3
+ import firestore from '@react-native-firebase/firestore';
4
+
5
+ const getShoppingCartNodes = (config) => {
6
+ var _a, _b;
7
+ const reusedConfig = reuseGlobalConfig(config);
8
+ const { accountId, customerId, anonymous } = reusedConfig;
9
+ checkMinimumConfigProvided(reusedConfig);
10
+ const path = anonymous ? "anonymousShoppingCartByUser" : "shoppingCartByUser";
11
+ const db = firestore();
12
+ const cartsCollection = (_b = (_a = db == null ? void 0 : db.collection(path)) == null ? void 0 : _a.doc(String(customerId))) == null ? void 0 : _b.collection(String(accountId));
13
+ return cartsCollection;
14
+ };
15
+ const getShoppingCartNode = async (config) => {
16
+ const reusedConfig = reuseGlobalConfig(config);
17
+ const { shoppingCartName } = reusedConfig;
18
+ const cartsCollection = getShoppingCartNodes(reusedConfig);
19
+ if (!cartsCollection)
20
+ return;
21
+ const newestCart = await cartsCollection.where("name", "==", shoppingCartName).get().then((userCarts) => {
22
+ return userCarts.docs[0];
23
+ });
24
+ return newestCart;
25
+ };
26
+ const getShoppingCart = (config) => {
27
+ return getShoppingCart$1({ getShoppingCartNode }, config);
28
+ };
29
+ const listenShoppingCart = (onSnapshot, config) => {
30
+ const reusedConfig = reuseGlobalConfig(config);
31
+ const { shoppingCartName } = reusedConfig;
32
+ const shoppingCartDocs = getShoppingCartNodes(reusedConfig);
33
+ if (!shoppingCartDocs) {
34
+ return () => {
35
+ };
36
+ }
37
+ State().setState({ activeShoppingCart: shoppingCartName });
38
+ return shoppingCartDocs.where("name", "==", shoppingCartName).onSnapshot((snapshot) => {
39
+ var _a;
40
+ if (!((_a = snapshot == null ? void 0 : snapshot.docs) == null ? void 0 : _a[0])) {
41
+ logDebug(`Failed to fetch a shopping cart with name ${shoppingCartName} because there wasn't any.`);
42
+ return onSnapshot(void 0);
43
+ }
44
+ const cart = snapshot.docs[0].data();
45
+ if ((cart == null ? void 0 : cart.id) === "" || (cart == null ? void 0 : cart.id) === null)
46
+ return;
47
+ return onSnapshot(cart);
48
+ });
49
+ };
50
+
51
+ const setDoc = async (config) => {
52
+ const { payload, shoppingCartNode } = config != null ? config : {};
53
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.set(payload));
54
+ };
55
+ const deleteDoc = async (config) => {
56
+ const { shoppingCartNode } = config != null ? config : {};
57
+ await (shoppingCartNode == null ? void 0 : shoppingCartNode.ref.delete());
58
+ };
59
+ const getCollectionReference = async (collectionName, ...path) => {
60
+ var _a, _b;
61
+ const [customerId, accountId] = path;
62
+ const db = firestore();
63
+ 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)));
64
+ return collection;
65
+ };
66
+ const getDocumentsByCollections = async (collectionReference) => {
67
+ const queryDocuments = await collectionReference.get().then((result) => result.docs[0]);
68
+ return queryDocuments;
69
+ };
70
+
71
+ var __defProp$1 = Object.defineProperty;
72
+ var __defProps$1 = Object.defineProperties;
73
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
74
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
75
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
76
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
77
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
78
+ var __spreadValues$1 = (a, b) => {
79
+ for (var prop in b || (b = {}))
80
+ if (__hasOwnProp$1.call(b, prop))
81
+ __defNormalProp$1(a, prop, b[prop]);
82
+ if (__getOwnPropSymbols$1)
83
+ for (var prop of __getOwnPropSymbols$1(b)) {
84
+ if (__propIsEnum$1.call(b, prop))
85
+ __defNormalProp$1(a, prop, b[prop]);
86
+ }
87
+ return a;
88
+ };
89
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
90
+ const createShoppingCart = async (config, overrides = {}) => {
91
+ return new Promise((resolve, reject) => {
92
+ const action = async () => {
93
+ var _a;
94
+ try {
95
+ const reusedConfig = reuseGlobalConfig(config);
96
+ const { shoppingCartName } = reusedConfig;
97
+ const cartsCollection = getShoppingCartNodes(reusedConfig);
98
+ const newShoppingCart = createShoppingCartSync(__spreadValues$1({
99
+ name: shoppingCartName,
100
+ channelId: config == null ? void 0 : config.channelId
101
+ }, overrides));
102
+ if (!cartsCollection) {
103
+ console.warn(`Couldn't find a shopping cart collection with the given config.
104
+ Please make sure everything is correct in your configuration
105
+ before continue.`);
106
+ resolve(null);
107
+ return null;
108
+ }
109
+ const { name } = newShoppingCart;
110
+ const numberOfCarts = (_a = await cartsCollection.get()) == null ? void 0 : _a.docs.length;
111
+ const maxNumberOfCarts = State().state.maxShoppingCarts;
112
+ if (numberOfCarts >= maxNumberOfCarts) {
113
+ throw new Error(`Cannot add more carts. Carts limit (${maxNumberOfCarts}) reached.`);
114
+ }
115
+ const namedCartsDocs = await cartsCollection.where("name", "==", name).get();
116
+ const cartsLength = namedCartsDocs.docs.length;
117
+ if (cartsLength > 0) {
118
+ throw new Error(`Attempted to create a shopping cart with the name ${name}, but there is already one shopping cart with that name.`);
119
+ }
120
+ const node = await cartsCollection.add(newShoppingCart);
121
+ if (!node) {
122
+ console.error("Failed to create a new shopping cart");
123
+ resolve(null);
124
+ return null;
125
+ }
126
+ const updatedCart = __spreadProps$1(__spreadValues$1({}, newShoppingCart), { id: node.id });
127
+ await node.set(updatedCart);
128
+ resolve(updatedCart);
129
+ return updatedCart;
130
+ } catch (e) {
131
+ reject(e);
132
+ return null;
133
+ }
134
+ };
135
+ const { eventLoop, queue } = State().state;
136
+ queue.enqueue(action);
137
+ if (!eventLoop.isRunning)
138
+ eventLoop.start();
139
+ });
140
+ };
141
+
142
+ const addProduct = (product, config) => {
143
+ return addProduct$1({ getShoppingCartNode, setDoc, createShoppingCart }, product, config);
144
+ };
145
+
146
+ const subtractProduct = async (product, config) => {
147
+ return subtractProduct$1({ getShoppingCartNode, setDoc }, product, config);
148
+ };
149
+
150
+ const removeProduct = (product, config) => {
151
+ return removeProduct$1({ getShoppingCartNode, setDoc }, product, config);
152
+ };
153
+
154
+ const setProduct = async (product, config) => {
155
+ return setProduct$1({ getShoppingCartNode, setDoc }, product, config);
156
+ };
157
+
158
+ const replaceProduct = (product, config) => {
159
+ return replaceProduct$1({ getShoppingCartNode, setDoc }, product, config);
160
+ };
161
+
162
+ const emptyShoppingCart = async (config) => await emptyShoppingCart$1({ getShoppingCartNode, setDoc }, config);
163
+
164
+ const deleteShoppingCart = async (config) => await deleteShoppingCart$1({ getShoppingCartNode, deleteDoc }, config);
165
+
166
+ const validateShoppingCart = (config, headers = new Headers()) => {
167
+ return validateShoppingCart$1({ getShoppingCartNode }, config, headers);
168
+ };
169
+
170
+ const getBenefitsNode = (config) => {
171
+ return getBenefitsNode$1({ getBenefitsCollection: getCollectionReference }, config);
172
+ };
173
+ const getWallet = async (config) => {
174
+ return getWallet$1({
175
+ getBenefitsCollection: getCollectionReference,
176
+ getBenefitsDocuments: getDocumentsByCollections
177
+ }, config);
178
+ };
179
+
180
+ var __defProp = Object.defineProperty;
181
+ var __defProps = Object.defineProperties;
182
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
183
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
184
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
185
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
186
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
187
+ var __spreadValues = (a, b) => {
188
+ for (var prop in b || (b = {}))
189
+ if (__hasOwnProp.call(b, prop))
190
+ __defNormalProp(a, prop, b[prop]);
191
+ if (__getOwnPropSymbols)
192
+ for (var prop of __getOwnPropSymbols(b)) {
193
+ if (__propIsEnum.call(b, prop))
194
+ __defNormalProp(a, prop, b[prop]);
195
+ }
196
+ return a;
197
+ };
198
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
199
+ const listenBenefitsWallet = (onSnapshot, config, headers = new Headers()) => {
200
+ const selectedHeaders = buildServiceHeaders(headers);
201
+ const reusedConfig = reuseGlobalConfig(config);
202
+ checkMinimumFetchWalletConfigProvided(reusedConfig);
203
+ verifyHeaders(selectedHeaders);
204
+ const { shoppingCartName, customerId, anonymous } = reusedConfig;
205
+ const { wallets } = State().state;
206
+ const walletExists = wallets[shoppingCartName];
207
+ if (anonymous)
208
+ return () => listenBenefitsWalletUnsubscribe(shoppingCartName);
209
+ if (walletExists) {
210
+ 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`);
211
+ return () => listenBenefitsWalletUnsubscribe(shoppingCartName);
212
+ }
213
+ const newWallet = getInitialBenefitsWallet();
214
+ updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet), { onSnapshot }));
215
+ let dbUnsubscriber = void 0;
216
+ (async () => {
217
+ const fetchConfig = __spreadProps(__spreadValues({}, reusedConfig), { customerId });
218
+ try {
219
+ await fetchWalletByUser(fetchConfig, selectedHeaders);
220
+ const benefitsNode = await getBenefitsNode(reusedConfig);
221
+ if (!benefitsNode) {
222
+ throw new Error("Failed to retrieve the benefits wallet node");
223
+ }
224
+ dbUnsubscriber = benefitsNode.onSnapshot(async (collection) => {
225
+ var _a, _b, _c;
226
+ const benefitsByUser = (_c = (_b = (_a = collection == null ? void 0 : collection.docs) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()) != null ? _c : {};
227
+ if (Object.keys(benefitsByUser).length === 0) {
228
+ const newWallet3 = getInitialBenefitsWallet();
229
+ updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet3), {
230
+ onSnapshot
231
+ }));
232
+ onSnapshot(newWallet3);
233
+ return;
234
+ }
235
+ const hash = collection.docs[0].id;
236
+ const benefits = mapCollectionToBenefits(benefitsByUser, hash);
237
+ const newWallet2 = getInitialBenefitsWallet({
238
+ benefits
239
+ });
240
+ updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet2), { onSnapshot }));
241
+ onSnapshot(newWallet2);
242
+ });
243
+ } catch (e) {
244
+ console.error(e.message);
245
+ }
246
+ })();
247
+ return () => listenBenefitsWalletUnsubscribe(shoppingCartName, dbUnsubscriber);
248
+ };
249
+
250
+ const applyBenefit = async (config, headers = new Headers()) => {
251
+ return applyBenefit$1({ getShoppingCartNode, applyBenefitsToCart, setDoc }, config, headers);
252
+ };
253
+ const applyBenefitsToCart = async (config, benefit, shippingCost) => {
254
+ const shoppingCartNode = await getShoppingCartNode(config);
255
+ if (!shoppingCartNode) {
256
+ console.warn("Cannot add benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.");
257
+ return;
258
+ }
259
+ const shoppingCart = await shoppingCartNode.data();
260
+ const updatedCart = applyBenefitSync(shoppingCart, benefit, shippingCost);
261
+ await shoppingCartNode.ref.set(updatedCart);
262
+ };
263
+
264
+ const removeBenefit = (config) => {
265
+ return removeBenefit$1({
266
+ getShoppingCartNode,
267
+ removeBenefitsFromCart,
268
+ removeProduct
269
+ }, config);
270
+ };
271
+ const removeBenefitsFromCart = async (config, benefit, shippingCost) => {
272
+ const shoppingCartNode = await getShoppingCartNode(config);
273
+ if (!shoppingCartNode) {
274
+ console.warn(`Cannot remove benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.`);
275
+ return;
276
+ }
277
+ const shoppingCart = await shoppingCartNode.data();
278
+ const updatedCart = removeBenefitsHelper(shoppingCart, benefit, shippingCost);
279
+ await shoppingCartNode.ref.set(updatedCart);
280
+ };
281
+
282
+ const redeemCoupon = async (config, code, headers = new Headers()) => {
283
+ return redeemCoupon$1({ getWallet, getShoppingCartNode }, config, code, headers);
284
+ };
285
+
286
+ const mergeShoppingCart = async (shoppingCart, config) => {
287
+ return mergeShoppingCart$1({ getShoppingCartNode, setDoc }, shoppingCart, config);
288
+ };
289
+
290
+ const findProduct = async (config) => {
291
+ return findProduct$1({ getShoppingCartNode }, config);
292
+ };
293
+
294
+ const updateShoppingCart = async (setShoppingCart, config) => {
295
+ return updateShoppingCart$1({ getShoppingCartNode, setDoc }, setShoppingCart, config);
296
+ };
297
+
298
+ export { addProduct, applyBenefit, createShoppingCart, deleteShoppingCart, emptyShoppingCart, findProduct, getShoppingCart, listenBenefitsWallet, listenShoppingCart, mergeShoppingCart, redeemCoupon, removeBenefit, removeProduct, replaceProduct, setProduct, subtractProduct, updateShoppingCart, validateShoppingCart };
299
+ //# sourceMappingURL=bundle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.mjs","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 { 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 { ShoppingCartConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartFetchConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { checkMinimumConfigProvided } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { State } 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.\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 = (\n config: ShoppingCartFetchConfig\n): ShoppingCartNodes | undefined => {\n const reusedConfig = reuseGlobalConfig(config);\n const { accountId, customerId, anonymous } = reusedConfig;\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 = 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.\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: ShoppingCartFetchConfig\n): Promise<ShoppingCartNode | undefined> => {\n // Get all user remote shopping carts\n const reusedConfig = reuseGlobalConfig(config);\n const { shoppingCartName } = reusedConfig;\n const cartsCollection = getShoppingCartNodes(reusedConfig);\n if (!cartsCollection) 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.\n * .\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?: ShoppingCartFetchConfig) => {\n return getShoppingCartHelper(\n { getShoppingCartNode },\n config as ShoppingCartConfig\n );\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 = <T extends ShoppingCart = ShoppingCart>(\n onSnapshot: (shoppingCart: T | undefined) => void,\n config: ShoppingCartFetchConfig\n) => {\n const reusedConfig = reuseGlobalConfig(config);\n const { shoppingCartName } = reusedConfig;\n const shoppingCartDocs = getShoppingCartNodes(reusedConfig);\n if (!shoppingCartDocs) {\n return () => {};\n }\n State().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(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 cart = snapshot.docs[0].data() as T;\n // cart?.id === \"\" Just created but not yet ready.\n // cart?.id === null is when cart is rebuilt from backend.\n if (cart?.id === \"\" || cart?.id === null) return;\n return onSnapshot(cart);\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 { createShoppingCartSync } from \"@artisan-commerce/shopping-cart-core\";\nimport { reuseGlobalConfig } from \"@artisan-commerce/shopping-cart-core\";\nimport { ShoppingCartCreateConfig } from \"@artisan-commerce/shopping-cart-core\";\n\nimport { State } 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 = getShoppingCartNodes(reusedConfig);\n const newShoppingCart = createShoppingCartSync({\n name: shoppingCartName,\n channelId: config?.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 = State().state.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 } = State().state;\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 = new 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.\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.\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.\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\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 { buildServiceHeaders } from \"@artisan-commerce/shopping-cart-core\";\nimport { listenBenefitsWalletUnsubscribe as 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 { State } 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 = new Headers()\n) => {\n const selectedHeaders = buildServiceHeaders(headers);\n const reusedConfig = reuseGlobalConfig(config);\n // Check minimum config to fetch wallet\n checkMinimumFetchWalletConfigProvided(reusedConfig);\n // Check minimum required headers\n verifyHeaders(selectedHeaders);\n\n const { shoppingCartName, customerId, anonymous } = reusedConfig;\n const { wallets } = State().state;\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, selectedHeaders 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 { applyBenefitSync } 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 = new 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 = applyBenefitSync(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 = new 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 { ShoppingCartMergeConfig } 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 {ShoppingCartMergeConfig} config Configuration to get the current shopping\n * cart\n */\nexport const mergeShoppingCart = async <T extends ShoppingCart = ShoppingCart>(\n shoppingCart: T,\n config: ShoppingCartMergeConfig\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":["getShoppingCartHelper","__spreadValues","__spreadProps","addProductCore","subtractProductCore","removeProductCore","setProductCore","replaceProductCore","emptyShoppingCartCore","deleteShoppingCartCore","validateShoppingCartCore","getBenefitsNodeCore","getWalletCore","unsubscriber","applyBenefitCore","removeBenefitCore","redeemCouponCore","mergeShoppingCartCore","findProductCore","updateShoppingCartCore"],"mappings":";;;;AAoBa,MAAA,oBAAA,GAAuB,CAClC,MACkC,KAAA;AAtBpC,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAuBE,EAAA,MAAM,eAAe,iBAAkB,CAAA,MAAA,CAAA,CAAA;AACvC,EAAM,MAAA,EAAE,SAAW,EAAA,UAAA,EAAY,SAAc,EAAA,GAAA,YAAA,CAAA;AAE7C,EAA2B,0BAAA,CAAA,YAAA,CAAA,CAAA;AAG3B,EAAM,MAAA,IAAA,GAAO,YAAY,6BAAgC,GAAA,oBAAA,CAAA;AAEzD,EAAA,MAAM,EAAK,GAAA,SAAA,EAAA,CAAA;AACX,EAAM,MAAA,eAAA,GAAkB,CACpB,EAAA,GAAA,CAAA,EAAA,GAAA,EAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAA,CAAW,IADS,CAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAEpB,IAAI,MAAO,CAAA,UAAA,CAAA,CAAA,KAFS,IAGpB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAA,CAAW,MAAO,CAAA,SAAA,CAAA,CAAA,CAAA;AACtB,EAAO,OAAA,eAAA,CAAA;AAAA,CAAA,CAAA;AAaI,MAAA,mBAAA,GAAsB,OACjC,MAC0C,KAAA;AAE1C,EA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EAAA,CAAA;AAE7C,EAAM,MAAA,WAAA,GAAc,oBAAqB,CAAA,YAAA,EAAc,OAAS,EAAA,YAAA,CAAA,CAAA;AAEhE,EAAM,MAAA,gBAAA,CAAiB,IAAI,GAAI,CAAA,WAAA,CAAA,CAAA;AAAA,CAAA;;ACpC1B,MAAM,eAAe,OAC1B,MAAA,EACA,IACA,EAAA,OAAA,GAAU,IAAI,OACX,EAAA,KAAA;AACH,EAAA,OAAOC,cACL,CAAA,EAAE,SAAW,EAAA,mBAAA,EAAA,EACb,QACA,IACA,EAAA,OAAA,CAAA,CAAA;AAAA;;ACRS,MAAA,iBAAA,GAAoB,OAC/B,YAAA,EACA,MACG,KAAA;AACH,EAAA,OAAOC,mBACL,CAAA,EAAE,mBAAqB,EAAA,MAAA,EAAA,EACvB,YACA,EAAA,MAAA,CAAA,CAAA;AAAA;;ACTS,MAAA,WAAA,GAAc,OAIzB,MAC2C,KAAA;AAC3C,EAAO,OAAAC,aAAA,CAAgB,EAAE,mBAAuB,EAAA,EAAA,MAAA,CAAA,CAAA;AAAA;;ACNrC,MAAA,kBAAA,GAAqB,OAChC,eAAA,EACA,MACG,KAAA;AACH,EAAA,OAAOC,oBACL,CAAA,EAAE,mBAAqB,EAAA,MAAA,EAAA,EACvB,eACA,EAAA,MAAA,CAAA,CAAA;AAAA;;;;"}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@artisan-commerce/shopping-cart-rn",
3
+ "description": "Artisn's shopping cart",
4
+ "version": "0.12.0-canary.100",
5
+ "type": "module",
6
+ "main": "./dist/bundle.cjs",
7
+ "module": "./dist/bundle.mjs",
8
+ "types": "./dist/bundle.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": false,
13
+ "scripts": {
14
+ "compile": "rollup -c && npx agadoo",
15
+ "dev": "yarn compile -w",
16
+ "clean": "rimraf dist",
17
+ "prebuild": "yarn clean",
18
+ "build": "yarn compile",
19
+ "test": "jest --watchAll --runInBand",
20
+ "test:all": "yarn test --watchAll=false --coverage",
21
+ "test:ci": "cross-env CI=true jest --runInBand",
22
+ "test:staged": "yarn test:ci",
23
+ "check-types": "tsc --noEmit",
24
+ "lint": "eslint --ignore-path .gitignore --ignore-pattern !cypress/.eslintrc.cjs --ext .js,jsx,.ts,.tsx .",
25
+ "lint:staged": "yarn lint --max-warnings=0",
26
+ "prettier": "prettier --ignore-path .gitignore \"**/*.+(js|jsx|ts|tsx|json|css|scss|html)\"",
27
+ "format": "yarn prettier --write",
28
+ "check-format": "yarn prettier --list-different",
29
+ "validate": "cross-env CI=true npm-run-all --parallel test:ci check-types check-format lint build",
30
+ "validate:ci": "npm-run-all --parallel check-types check-format lint"
31
+ },
32
+ "author": "Luis Eduardo Andrade",
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "@artisan-commerce/builders": "0.7.0-canary.44",
36
+ "@artisan-commerce/products": "0.9.0-canary.47",
37
+ "@artisan-commerce/state": "0.3.0-canary.16",
38
+ "@artisan-commerce/types": "0.14.0-canary.44",
39
+ "@react-native-firebase/firestore": "^12.8.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@artisan-commerce/products": "*",
43
+ "@artisan-commerce/state": "*",
44
+ "@react-native-firebase/app": "*",
45
+ "@react-native-firebase/firestore": "*"
46
+ },
47
+ "gitHead": "3c92488c824df82adb39b272b9e389bb7d30443c",
48
+ "nx": {
49
+ "targets": {
50
+ "build": {
51
+ "outputs": [
52
+ "./dist"
53
+ ]
54
+ },
55
+ "compile": {
56
+ "outputs": [
57
+ "./dist"
58
+ ]
59
+ },
60
+ "test:all": {
61
+ "outputs": [
62
+ "./coverage"
63
+ ]
64
+ }
65
+ }
66
+ },
67
+ "dependencies": {
68
+ "@artisan-commerce/shopping-cart-core": "0.12.0-canary.100"
69
+ }
70
+ }