@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/README.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shoppingCartCore = require('@artisan-commerce/shopping-cart-core');
|
|
6
|
+
var firestore = require('firebase/firestore');
|
|
7
|
+
|
|
8
|
+
const getShoppingCartNodes = async (config = {}) => {
|
|
9
|
+
const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
|
|
10
|
+
const { accountId, customerId, anonymous } = reusedConfig;
|
|
11
|
+
shoppingCartCore.checkMinimumConfigProvided(reusedConfig);
|
|
12
|
+
const path = anonymous ? "anonymousShoppingCartByUser" : "shoppingCartByUser";
|
|
13
|
+
const db = firestore.getFirestore();
|
|
14
|
+
const collectionRef = firestore.collection(db, path, String(customerId), String(accountId));
|
|
15
|
+
return collectionRef;
|
|
16
|
+
};
|
|
17
|
+
const getShoppingCartNode = async (config) => {
|
|
18
|
+
const { shoppingCartName } = shoppingCartCore.reuseGlobalConfig(config);
|
|
19
|
+
const cartsCollection = await getShoppingCartNodes(config);
|
|
20
|
+
if (!cartsCollection || !shoppingCartCore.checkInit())
|
|
21
|
+
return;
|
|
22
|
+
const q = firestore.query(cartsCollection, firestore.where("name", "==", shoppingCartName));
|
|
23
|
+
const querySnapshot = await firestore.getDocs(q).then((userCarts) => userCarts.docs[0]);
|
|
24
|
+
return querySnapshot;
|
|
25
|
+
};
|
|
26
|
+
const getShoppingCart = (config) => {
|
|
27
|
+
return shoppingCartCore.getShoppingCart({ getShoppingCartNode }, config);
|
|
28
|
+
};
|
|
29
|
+
const listenShoppingCart = async (onSnapshotArtisn, config = {}) => {
|
|
30
|
+
const { shoppingCartName } = shoppingCartCore.reuseGlobalConfig(config);
|
|
31
|
+
const shoppingCartDocs = await getShoppingCartNodes(config);
|
|
32
|
+
if (!shoppingCartDocs || !shoppingCartCore.checkInit()) {
|
|
33
|
+
return () => {
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
shoppingCartCore.setState({ activeShoppingCart: shoppingCartName });
|
|
37
|
+
const q = firestore.query(shoppingCartDocs, firestore.where("name", "==", shoppingCartName));
|
|
38
|
+
return firestore.onSnapshot(q, async (snapshot) => {
|
|
39
|
+
var _a;
|
|
40
|
+
if (!((_a = snapshot == null ? void 0 : snapshot.docs) == null ? void 0 : _a[0])) {
|
|
41
|
+
shoppingCartCore.logDebug(`Failed to fetch a shopping cart with name ${shoppingCartName} because there wasn't any.`);
|
|
42
|
+
return onSnapshotArtisn(void 0);
|
|
43
|
+
}
|
|
44
|
+
const shoppingCartData = await snapshot.docs[0].data();
|
|
45
|
+
return onSnapshotArtisn(shoppingCartData);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getCartReference = (anonymous, customerId, accountId, shoppingCartId) => {
|
|
50
|
+
const db = firestore.getFirestore();
|
|
51
|
+
const path = anonymous ? "anonymousShoppingCartByUser" : "shoppingCartByUser";
|
|
52
|
+
const cartReference = firestore.doc(db, path, String(customerId), String(accountId), shoppingCartId);
|
|
53
|
+
return cartReference;
|
|
54
|
+
};
|
|
55
|
+
const setDoc = async (config) => {
|
|
56
|
+
const { reusedConfig, payload, shoppingCartNode } = config != null ? config : {};
|
|
57
|
+
const { customerId, anonymous, accountId } = reusedConfig != null ? reusedConfig : {};
|
|
58
|
+
const cartReference = getCartReference(anonymous, String(customerId), accountId, shoppingCartNode.id);
|
|
59
|
+
await firestore.setDoc(cartReference, payload);
|
|
60
|
+
};
|
|
61
|
+
const deleteDoc = async (config) => {
|
|
62
|
+
const { reusedConfig, shoppingCartNode } = config != null ? config : {};
|
|
63
|
+
const { customerId, anonymous, accountId } = reusedConfig != null ? reusedConfig : {};
|
|
64
|
+
const cartReference = getCartReference(anonymous, String(customerId), accountId, shoppingCartNode.id);
|
|
65
|
+
await firestore.deleteDoc(cartReference);
|
|
66
|
+
};
|
|
67
|
+
const getCollectionReference = async (collectionName, ...path) => {
|
|
68
|
+
const db = firestore.getFirestore();
|
|
69
|
+
const cartReference = firestore.collection(db, collectionName, ...path);
|
|
70
|
+
return cartReference;
|
|
71
|
+
};
|
|
72
|
+
const getDocumentsByCollections = async (collectionReference) => {
|
|
73
|
+
const q = firestore.query(collectionReference);
|
|
74
|
+
const querySnapshot = await firestore.getDocs(q).then((result) => result.docs[0]);
|
|
75
|
+
return querySnapshot;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var __defProp$1 = Object.defineProperty;
|
|
79
|
+
var __defProps$1 = Object.defineProperties;
|
|
80
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
81
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
82
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
83
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
84
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
85
|
+
var __spreadValues$1 = (a, b) => {
|
|
86
|
+
for (var prop in b || (b = {}))
|
|
87
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
88
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
89
|
+
if (__getOwnPropSymbols$1)
|
|
90
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
91
|
+
if (__propIsEnum$1.call(b, prop))
|
|
92
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
93
|
+
}
|
|
94
|
+
return a;
|
|
95
|
+
};
|
|
96
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
97
|
+
const createShoppingCart = async (config, overrides = {}) => {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const action = async () => {
|
|
100
|
+
try {
|
|
101
|
+
const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
|
|
102
|
+
const { shoppingCartName } = reusedConfig;
|
|
103
|
+
const cartsCollection = await getShoppingCartNodes(reusedConfig);
|
|
104
|
+
const newShoppingCart = shoppingCartCore.buildInitialShoppingCart(__spreadValues$1({
|
|
105
|
+
name: shoppingCartName,
|
|
106
|
+
channelId: reusedConfig.channelId
|
|
107
|
+
}, overrides));
|
|
108
|
+
if (!cartsCollection) {
|
|
109
|
+
console.warn(`Couldn't find a shopping cart collection with the given config.
|
|
110
|
+
Please make sure everything is correct in your configuration
|
|
111
|
+
before continue.`);
|
|
112
|
+
resolve(null);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const { name } = newShoppingCart;
|
|
116
|
+
const numberOfCarts = (await firestore.getDocs(cartsCollection)).docs.length;
|
|
117
|
+
const maxNumberOfCarts = shoppingCartCore.getState().maxShoppingCarts;
|
|
118
|
+
if (numberOfCarts >= maxNumberOfCarts) {
|
|
119
|
+
throw new Error(`Cannot add more carts. Carts limit (${maxNumberOfCarts}) reached.`);
|
|
120
|
+
}
|
|
121
|
+
const q = firestore.query(cartsCollection, firestore.where("name", "==", name));
|
|
122
|
+
const cartsLength = (await firestore.getDocs(q)).docs.length;
|
|
123
|
+
if (cartsLength > 0) {
|
|
124
|
+
throw new Error(`Attempted to create a shopping cart with the name ${name}, but there is already one shopping cart with that name.`);
|
|
125
|
+
}
|
|
126
|
+
const node = await firestore.addDoc(cartsCollection, newShoppingCart);
|
|
127
|
+
if (!node) {
|
|
128
|
+
console.error("Failed to create a new shopping cart");
|
|
129
|
+
resolve(null);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const updatedCart = __spreadProps$1(__spreadValues$1({}, newShoppingCart), { id: node.id });
|
|
133
|
+
await firestore.setDoc(node, updatedCart);
|
|
134
|
+
resolve(updatedCart);
|
|
135
|
+
return updatedCart;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
reject(e);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const { eventLoop, queue } = shoppingCartCore.getState();
|
|
142
|
+
queue.enqueue(action);
|
|
143
|
+
if (!eventLoop.isRunning)
|
|
144
|
+
eventLoop.start();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const addProduct = async (product, config) => {
|
|
149
|
+
return shoppingCartCore.addProduct({ getShoppingCartNode, setDoc, createShoppingCart }, product, config);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const subtractProduct = async (product, config) => {
|
|
153
|
+
return shoppingCartCore.subtractProduct({ getShoppingCartNode, setDoc }, product, config);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const removeProduct = (product, config = {}) => {
|
|
157
|
+
return shoppingCartCore.removeProduct({ getShoppingCartNode, setDoc }, product, config);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const setProduct = async (product, config = {}) => {
|
|
161
|
+
return shoppingCartCore.setProduct({ getShoppingCartNode, setDoc }, product, config);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const replaceProduct = (product, config) => {
|
|
165
|
+
return shoppingCartCore.replaceProduct({ getShoppingCartNode, setDoc }, product, config);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const emptyShoppingCart = async (config) => await shoppingCartCore.emptyShoppingCart({ getShoppingCartNode, setDoc }, config);
|
|
169
|
+
|
|
170
|
+
const deleteShoppingCart = async (config) => await shoppingCartCore.deleteShoppingCart({ getShoppingCartNode, deleteDoc }, config);
|
|
171
|
+
|
|
172
|
+
const validateShoppingCart = (config = {}, headers) => {
|
|
173
|
+
return shoppingCartCore.validateShoppingCart({ getShoppingCartNode }, config, headers);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const getBenefitsNode = (config = {}) => {
|
|
177
|
+
return shoppingCartCore.getBenefitsNode({ getBenefitsCollection: getCollectionReference }, config);
|
|
178
|
+
};
|
|
179
|
+
const getWallet = async (config) => {
|
|
180
|
+
return shoppingCartCore.getWallet({
|
|
181
|
+
getBenefitsCollection: getCollectionReference,
|
|
182
|
+
getBenefitsDocuments: getDocumentsByCollections
|
|
183
|
+
}, config);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
var __defProp = Object.defineProperty;
|
|
187
|
+
var __defProps = Object.defineProperties;
|
|
188
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
189
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
190
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
191
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
192
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
193
|
+
var __spreadValues = (a, b) => {
|
|
194
|
+
for (var prop in b || (b = {}))
|
|
195
|
+
if (__hasOwnProp.call(b, prop))
|
|
196
|
+
__defNormalProp(a, prop, b[prop]);
|
|
197
|
+
if (__getOwnPropSymbols)
|
|
198
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
199
|
+
if (__propIsEnum.call(b, prop))
|
|
200
|
+
__defNormalProp(a, prop, b[prop]);
|
|
201
|
+
}
|
|
202
|
+
return a;
|
|
203
|
+
};
|
|
204
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
205
|
+
const listenBenefitsWallet = (onSnapshot, config, headers) => {
|
|
206
|
+
const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
|
|
207
|
+
shoppingCartCore.checkMinimumFetchWalletConfigProvided(reusedConfig);
|
|
208
|
+
shoppingCartCore.verifyHeaders(headers);
|
|
209
|
+
const { shoppingCartName, customerId, anonymous } = reusedConfig;
|
|
210
|
+
const { wallets } = shoppingCartCore.getState();
|
|
211
|
+
const walletExists = wallets[shoppingCartName];
|
|
212
|
+
if (anonymous)
|
|
213
|
+
return () => shoppingCartCore.unsubscriber(shoppingCartName);
|
|
214
|
+
if (walletExists) {
|
|
215
|
+
shoppingCartCore.logError(`There is already a listener for wallet of name ${shoppingCartName}. Either unsubscribe to the other listener or create a new listener for a different cart`);
|
|
216
|
+
return () => shoppingCartCore.unsubscriber(shoppingCartName);
|
|
217
|
+
}
|
|
218
|
+
const newWallet = shoppingCartCore.getInitialBenefitsWallet();
|
|
219
|
+
shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet), { onSnapshot }));
|
|
220
|
+
let dbUnsubscriber = void 0;
|
|
221
|
+
(async () => {
|
|
222
|
+
const fetchConfig = __spreadProps(__spreadValues({}, reusedConfig), { customerId });
|
|
223
|
+
try {
|
|
224
|
+
await shoppingCartCore.fetchWalletByUser(fetchConfig, headers);
|
|
225
|
+
const benefitsNode = await getBenefitsNode(reusedConfig);
|
|
226
|
+
if (!benefitsNode) {
|
|
227
|
+
throw new Error("Failed to retrieve the benefits wallet node");
|
|
228
|
+
}
|
|
229
|
+
dbUnsubscriber = firestore.onSnapshot(benefitsNode, async (collection) => {
|
|
230
|
+
var _a, _b, _c;
|
|
231
|
+
const benefitsByUser = (_c = (_b = (_a = collection == null ? void 0 : collection.docs) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()) != null ? _c : {};
|
|
232
|
+
if (Object.keys(benefitsByUser).length === 0) {
|
|
233
|
+
const newWallet3 = shoppingCartCore.getInitialBenefitsWallet();
|
|
234
|
+
shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet3), {
|
|
235
|
+
onSnapshot
|
|
236
|
+
}));
|
|
237
|
+
onSnapshot(newWallet3);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const hash = collection.docs[0].id;
|
|
241
|
+
const benefits = shoppingCartCore.mapCollectionToBenefits(benefitsByUser, hash);
|
|
242
|
+
const newWallet2 = shoppingCartCore.getInitialBenefitsWallet({
|
|
243
|
+
benefits
|
|
244
|
+
});
|
|
245
|
+
shoppingCartCore.updateBenefitsWallets(shoppingCartName, __spreadProps(__spreadValues({}, newWallet2), {
|
|
246
|
+
onSnapshot
|
|
247
|
+
}));
|
|
248
|
+
onSnapshot(newWallet2);
|
|
249
|
+
});
|
|
250
|
+
} catch (e) {
|
|
251
|
+
console.error(e.message);
|
|
252
|
+
}
|
|
253
|
+
})();
|
|
254
|
+
return () => shoppingCartCore.unsubscriber(shoppingCartName, dbUnsubscriber);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const applyBenefit = async (config, headers) => {
|
|
258
|
+
return shoppingCartCore.applyBenefit({
|
|
259
|
+
getShoppingCartNode,
|
|
260
|
+
applyBenefitsToCart,
|
|
261
|
+
setDoc: setDoc
|
|
262
|
+
}, config, headers);
|
|
263
|
+
};
|
|
264
|
+
const applyBenefitsToCart = async (config, benefit, shippingCost) => {
|
|
265
|
+
const reusedConfig = shoppingCartCore.reuseGlobalConfig(config);
|
|
266
|
+
const { customerId, anonymous, accountId } = reusedConfig;
|
|
267
|
+
const shoppingCartNode = await getShoppingCartNode(config);
|
|
268
|
+
if (!shoppingCartNode) {
|
|
269
|
+
console.warn("Cannot add benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const shoppingCart = await shoppingCartNode.data();
|
|
273
|
+
const updatedCart = shoppingCartCore.applyBenefitsHelper(shoppingCart, benefit, shippingCost);
|
|
274
|
+
const cartReference = getCartReference(anonymous, String(customerId), accountId, shoppingCart.id);
|
|
275
|
+
await firestore.setDoc(cartReference, updatedCart);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const removeBenefit = (config) => {
|
|
279
|
+
return shoppingCartCore.removeBenefit({
|
|
280
|
+
getShoppingCartNode,
|
|
281
|
+
removeBenefitsFromCart,
|
|
282
|
+
removeProduct
|
|
283
|
+
}, config);
|
|
284
|
+
};
|
|
285
|
+
const removeBenefitsFromCart = async (config, benefit, shippingCost) => {
|
|
286
|
+
const reuseConfig = shoppingCartCore.reuseGlobalConfig(config);
|
|
287
|
+
const { customerId, anonymous, accountId } = reuseConfig;
|
|
288
|
+
const shoppingCartNode = await getShoppingCartNode(config);
|
|
289
|
+
if (!shoppingCartNode) {
|
|
290
|
+
console.warn(`Cannot remove benefit because no shopping cart nodes were found. Please ensure you have a shopping cart before continue.`);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const shoppingCart = await shoppingCartNode.data();
|
|
294
|
+
const updatedCart = shoppingCartCore.removeBenefitsHelper(shoppingCart, benefit, shippingCost);
|
|
295
|
+
const cartReference = getCartReference(anonymous, String(customerId), accountId, shoppingCart.id);
|
|
296
|
+
await firestore.setDoc(cartReference, updatedCart);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const redeemCoupon = async (config, code, headers) => {
|
|
300
|
+
return shoppingCartCore.redeemCoupon({ getWallet, getShoppingCartNode }, config, code, headers);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const mergeShoppingCart = async (shoppingCart, config) => {
|
|
304
|
+
return shoppingCartCore.mergeShoppingCart({ getShoppingCartNode, setDoc }, shoppingCart, config);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const findProduct = async (config) => {
|
|
308
|
+
return shoppingCartCore.findProduct({ getShoppingCartNode }, config);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const updateShoppingCart = async (setShoppingCart, config) => {
|
|
312
|
+
return shoppingCartCore.updateShoppingCart({ getShoppingCartNode, setDoc }, setShoppingCart, config);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
Object.defineProperty(exports, 'checkInit', {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
get: function () { return shoppingCartCore.checkInit; }
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(exports, 'closeShoppingCart', {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function () { return shoppingCartCore.closeShoppingCart; }
|
|
322
|
+
});
|
|
323
|
+
Object.defineProperty(exports, 'fetchStoreCouponDetail', {
|
|
324
|
+
enumerable: true,
|
|
325
|
+
get: function () { return shoppingCartCore.fetchStoreCouponDetail; }
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(exports, 'fetchStoreCoupons', {
|
|
328
|
+
enumerable: true,
|
|
329
|
+
get: function () { return shoppingCartCore.fetchStoreCoupons; }
|
|
330
|
+
});
|
|
331
|
+
Object.defineProperty(exports, 'getProductHash', {
|
|
332
|
+
enumerable: true,
|
|
333
|
+
get: function () { return shoppingCartCore.getProductHash; }
|
|
334
|
+
});
|
|
335
|
+
Object.defineProperty(exports, 'getShoppingCartProducts', {
|
|
336
|
+
enumerable: true,
|
|
337
|
+
get: function () { return shoppingCartCore.getShoppingCartProducts; }
|
|
338
|
+
});
|
|
339
|
+
Object.defineProperty(exports, 'getShoppingCartTotal', {
|
|
340
|
+
enumerable: true,
|
|
341
|
+
get: function () { return shoppingCartCore.getShoppingCartTotal; }
|
|
342
|
+
});
|
|
343
|
+
Object.defineProperty(exports, 'initShoppingCart', {
|
|
344
|
+
enumerable: true,
|
|
345
|
+
get: function () { return shoppingCartCore.initShoppingCart; }
|
|
346
|
+
});
|
|
347
|
+
exports.addProduct = addProduct;
|
|
348
|
+
exports.applyBenefit = applyBenefit;
|
|
349
|
+
exports.createShoppingCart = createShoppingCart;
|
|
350
|
+
exports.deleteShoppingCart = deleteShoppingCart;
|
|
351
|
+
exports.emptyShoppingCart = emptyShoppingCart;
|
|
352
|
+
exports.findProduct = findProduct;
|
|
353
|
+
exports.getShoppingCart = getShoppingCart;
|
|
354
|
+
exports.listenBenefitsWallet = listenBenefitsWallet;
|
|
355
|
+
exports.listenShoppingCart = listenShoppingCart;
|
|
356
|
+
exports.mergeShoppingCart = mergeShoppingCart;
|
|
357
|
+
exports.redeemCoupon = redeemCoupon;
|
|
358
|
+
exports.removeBenefit = removeBenefit;
|
|
359
|
+
exports.removeProduct = removeProduct;
|
|
360
|
+
exports.replaceProduct = replaceProduct;
|
|
361
|
+
exports.setProduct = setProduct;
|
|
362
|
+
exports.subtractProduct = subtractProduct;
|
|
363
|
+
exports.updateShoppingCart = updateShoppingCart;
|
|
364
|
+
exports.validateShoppingCart = validateShoppingCart;
|
|
365
|
+
//# sourceMappingURL=bundle.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.cjs.js","sources":["../src/lib/fetchShoppingCart/fetchShoppingCart.ts","../src/utils/firestore.utils.ts","../src/lib/createShoppingCart/createShoppingCart.ts","../src/lib/addProduct/addProduct.ts","../src/lib/subtractProduct/subtractProduct.ts","../src/lib/removeProduct/removeProduct.ts","../src/lib/setProduct/setProduct.ts","../src/lib/replaceProduct/replaceProduct.ts","../src/lib/emptyShoppingCart/emptyShoppingCart.ts","../src/lib/deleteShoppingCart/deleteShoppingCart.ts","../src/lib/validateShoppingCart/validateShoppingCart.ts","../src/utils/benefits.utils.ts","../src/lib/listenBenefitsWallet/listenBenefitsWallet.ts","../src/lib/applyBenefit/applyBenefit.ts","../src/lib/removeBenefit/removeBenefit.ts","../src/lib/redeemCoupon/redeemCoupon.ts","../src/lib/mergeShoppingCart/mergeShoppingCart.ts","../src/utils/product.utils.ts","../src/lib/updateShoppingCart/updateShoppingCart.ts"],"sourcesContent":["import { 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":["reuseGlobalConfig","checkMinimumConfigProvided","getFirestore","collection","checkInit","query","where","getDocs","getShoppingCartHelper","setState","onSnapshot","logDebug","doc","FBSetDoc","FBDeleteDoc","__defProp","__defProps","__getOwnPropDescs","__getOwnPropSymbols","__hasOwnProp","__propIsEnum","__defNormalProp","__spreadValues","__spreadProps","buildInitialShoppingCart","getState","addDoc","setDoc","addProductHelper","subtractProductCore","removeProductCore","setProductCore","replaceProductCore","emptyShoppingCartCore","deleteShoppingCartCore","validateShoppingCartCore","getBenefitsNodeCore","getWalletCore","checkMinimumFetchWalletConfigProvided","verifyHeaders","unsubscriber","logError","getInitialBenefitsWallet","updateBenefitsWallets","fetchWalletByUser","firebaseOnSnapshot","mapCollectionToBenefits","applyBenefitCore","customSetDoc","applyBenefitsHelper","removeBenefitCore","removeBenefitsHelper","redeemCouponCore","mergeShoppingCartCore","findProductCore","updateShoppingCartCore"],"mappings":";;;;;;;AAQO,MAAM,oBAAoB,GAAG,OAAO,M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