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