@artisan-commerce/shopping-cart-core 0.12.0-canary.73
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 +2228 -0
- package/dist/bundle.cjs.js.map +1 -0
- package/dist/bundle.d.ts +873 -0
- package/dist/bundle.esm.js +2167 -0
- package/dist/bundle.esm.js.map +1 -0
- package/dist/bundle.umd.js +2232 -0
- package/dist/bundle.umd.js.map +1 -0
- package/package.json +64 -0
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
import * as _artisan_commerce_types from '@artisan-commerce/types';
|
|
2
|
+
import { Wallet, Vendor, ShippingCost, ProductDetails, ShoppingCart, CartProduct, Account, Store, PriceCategoryType, Product, Benefit, CartProductAnswer, CartProductQuestion, AdditionalInfo, CartStore, StoreCoupon, StoreCouponDetail, Alert } from '@artisan-commerce/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Representation of different user wallets.
|
|
6
|
+
*
|
|
7
|
+
* @interface Wallets
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @property {WalletInternal} [key: string] Object where its key is a string
|
|
10
|
+
* and its value is a {@link WalletInternal}
|
|
11
|
+
*/
|
|
12
|
+
interface Wallets {
|
|
13
|
+
[key: string]: WalletInternal;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wallet internal attributes.
|
|
17
|
+
*
|
|
18
|
+
* @interface WalletInternal
|
|
19
|
+
* @since 0.1.0
|
|
20
|
+
* @extends {{@link Wallet}
|
|
21
|
+
*/
|
|
22
|
+
interface WalletInternal extends Wallet {
|
|
23
|
+
/**
|
|
24
|
+
* The callback function that provides real time connection to the
|
|
25
|
+
* artisn database
|
|
26
|
+
*/
|
|
27
|
+
onSnapshot: (wallet: Wallet) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration object for benefits wallet.
|
|
31
|
+
*
|
|
32
|
+
* @interface BenefitsWalletConfig
|
|
33
|
+
* @since 0.1.0
|
|
34
|
+
*/
|
|
35
|
+
interface BenefitsWalletConfig extends ShoppingCartConfig {
|
|
36
|
+
/** The provided vendor id */
|
|
37
|
+
vendorId?: Vendor["id"];
|
|
38
|
+
apiURL: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Apply benefit configuration attributes.
|
|
42
|
+
*
|
|
43
|
+
* @interface ApplyBenefitConfig
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
* @extends {{@link BenefitsWalletConfig}
|
|
46
|
+
*/
|
|
47
|
+
interface ApplyBenefitConfig extends BenefitsWalletConfig {
|
|
48
|
+
/** The id ot fhe benefit to apply */
|
|
49
|
+
benefitId: number;
|
|
50
|
+
/** The store shipping cost, used to apply a `ALTER_DELIVERY` benefit */
|
|
51
|
+
shippingCost: ShippingCost | null;
|
|
52
|
+
/** Location latitude of the user, used to apply a `ALTER_DELIVERY` benefit */
|
|
53
|
+
latitude?: number;
|
|
54
|
+
/** Location longitude of the user, used to apply a `ALTER_DELIVERY` benefit */
|
|
55
|
+
longitude?: number;
|
|
56
|
+
/** The product to be applied as benefit, used to apply a `PRODUCT` benefit */
|
|
57
|
+
product?: ProductDetails;
|
|
58
|
+
/**
|
|
59
|
+
* The configuration of the benefit of type product,
|
|
60
|
+
* used to apply a `PRODUCT` benefit
|
|
61
|
+
*/
|
|
62
|
+
productConfig?: ProductActionConfig;
|
|
63
|
+
/** The customer unique identifier used to apply a `DISCOUNT` benefit */
|
|
64
|
+
customerId?: string;
|
|
65
|
+
/** The shoppingCart unique identifier used as a request body */
|
|
66
|
+
shoppingCartId?: ShoppingCart["id"];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Remove benefit configuration attributes.
|
|
70
|
+
*
|
|
71
|
+
* @interface RemoveBenefitConfig
|
|
72
|
+
* @since 0.1.0
|
|
73
|
+
* @extends {{@link BenefitsWalletConfig}
|
|
74
|
+
*/
|
|
75
|
+
interface RemoveBenefitConfig extends BenefitsWalletConfig {
|
|
76
|
+
/** The id ot fhe benefit to remove */
|
|
77
|
+
benefitId: number;
|
|
78
|
+
/** The store shipping cost, used to remove a `ALTER_DELIVERY` benefit */
|
|
79
|
+
shippingCost: ShippingCost | null;
|
|
80
|
+
/** The product to be applied as benefit, used to remove a `PRODUCT` benefit */
|
|
81
|
+
product?: CartProduct;
|
|
82
|
+
/** The configuration of the product, used to remove a `PRODUCT` benefit */
|
|
83
|
+
productConfig?: ProductRemoveConfig;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The allowed headers to fetch the users wallet.
|
|
87
|
+
*
|
|
88
|
+
* @typedef WalletHeaders
|
|
89
|
+
* @since 0.1.0
|
|
90
|
+
*/
|
|
91
|
+
declare type WalletHeaders = Headers & {
|
|
92
|
+
uid: string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
declare class ActionQueue {
|
|
96
|
+
private queue;
|
|
97
|
+
constructor();
|
|
98
|
+
get length(): number;
|
|
99
|
+
enqueue(newItem: () => Promise<ShoppingCart | null>): void;
|
|
100
|
+
dequeue(): (() => 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>) | undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare class EventLoop {
|
|
104
|
+
private running;
|
|
105
|
+
constructor();
|
|
106
|
+
private run;
|
|
107
|
+
get isRunning(): boolean;
|
|
108
|
+
start(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Current state of the library.
|
|
113
|
+
*
|
|
114
|
+
* @interface GlobalState
|
|
115
|
+
* @since 0.1.0
|
|
116
|
+
*/
|
|
117
|
+
interface GlobalState {
|
|
118
|
+
/** The provided account id of the application */
|
|
119
|
+
accountId?: ShoppingCartConfig["accountId"];
|
|
120
|
+
/** The provided customer id of the user */
|
|
121
|
+
customerId?: ShoppingCartConfig["customerId"];
|
|
122
|
+
/** The provided store information */
|
|
123
|
+
store?: ShoppingCartConfig["store"];
|
|
124
|
+
/** The name of the currently shopping cart in use */
|
|
125
|
+
activeShoppingCart: string;
|
|
126
|
+
/**
|
|
127
|
+
* The maximum number of shopping carts that an application is allowed
|
|
128
|
+
* to create
|
|
129
|
+
*/
|
|
130
|
+
maxShoppingCarts: number;
|
|
131
|
+
/** An array of wallets that a shopping cart can initiate */
|
|
132
|
+
wallets: Wallets;
|
|
133
|
+
/**
|
|
134
|
+
* The attribute that indicates if a cart must be created like
|
|
135
|
+
* anonymous or not
|
|
136
|
+
*/
|
|
137
|
+
anonymous?: boolean;
|
|
138
|
+
/** Indicates whether or not the cart has been initialized */
|
|
139
|
+
initialized: boolean;
|
|
140
|
+
/** The queue of actions to be called one after the other has resolved */
|
|
141
|
+
queue: ActionQueue;
|
|
142
|
+
/** The event loop of actions to be ran */
|
|
143
|
+
eventLoop: EventLoop;
|
|
144
|
+
/** Show debug messages */
|
|
145
|
+
debug?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Configuration object that can be applied globally or at function level.
|
|
149
|
+
*
|
|
150
|
+
* @interface ShoppingCartConfig
|
|
151
|
+
* @since 0.1.0
|
|
152
|
+
*/
|
|
153
|
+
interface ShoppingCartConfig {
|
|
154
|
+
/** The provided account id of the application */
|
|
155
|
+
accountId?: Account["accountId"];
|
|
156
|
+
/** The provided customer id of the user */
|
|
157
|
+
customerId?: number | string;
|
|
158
|
+
/** The provided store information */
|
|
159
|
+
store?: Store;
|
|
160
|
+
/** The provided name of the shopping cart */
|
|
161
|
+
shoppingCartName?: string;
|
|
162
|
+
/** The max number of shopping carts an application is allowed to create */
|
|
163
|
+
maxShoppingCarts?: number;
|
|
164
|
+
/**
|
|
165
|
+
* The attribute that indicates if a cart must be created as anonymous or not
|
|
166
|
+
*/
|
|
167
|
+
anonymous?: boolean;
|
|
168
|
+
/** Show debug messages */
|
|
169
|
+
debug?: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Configuration object to create a shopping cart.
|
|
173
|
+
*
|
|
174
|
+
* @interface ProductActionConfig
|
|
175
|
+
* @since 0.1.0
|
|
176
|
+
* @extends {{@link ShoppingCartConfig}
|
|
177
|
+
*/
|
|
178
|
+
interface ShoppingCartCreateConfig extends ShoppingCartConfig {
|
|
179
|
+
/** The id of the sales channel of the shopping cart */
|
|
180
|
+
channelId?: number;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Configuration object to make an action on the shopping cart.
|
|
184
|
+
*
|
|
185
|
+
* @interface ProductActionConfig
|
|
186
|
+
* @since 0.1.0
|
|
187
|
+
* @extends {{@link ShoppingCartConfig}
|
|
188
|
+
*/
|
|
189
|
+
interface ProductActionConfig extends ShoppingCartConfig {
|
|
190
|
+
/** The amount of products to be added */
|
|
191
|
+
amount: number;
|
|
192
|
+
/** The price category associated with the product */
|
|
193
|
+
priceCategory?: PriceCategoryType;
|
|
194
|
+
/** The comment associated with the product */
|
|
195
|
+
comment?: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Configuration object to add a product from the shopping cart.
|
|
199
|
+
*
|
|
200
|
+
* @interface ProductAddConfig
|
|
201
|
+
* @since 0.1.0
|
|
202
|
+
* @extends {{@link ProductActionConfig}
|
|
203
|
+
*/
|
|
204
|
+
interface ProductAddConfig extends ProductActionConfig {
|
|
205
|
+
/** If no cart is found it first creates a shopping cart */
|
|
206
|
+
createCart?: boolean | Partial<ShoppingCart>;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Configuration object to remove a product from the shopping cart.
|
|
210
|
+
*
|
|
211
|
+
* @interface ProductRemoveConfig
|
|
212
|
+
* @since 0.1.0
|
|
213
|
+
* @extends {{@link ShoppingCartConfig}
|
|
214
|
+
*/
|
|
215
|
+
interface ProductRemoveConfig extends ShoppingCartConfig {
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Configuration object to set a product on the shopping cart.
|
|
219
|
+
*
|
|
220
|
+
* @interface ProductSetConfig
|
|
221
|
+
* @since 0.1.0
|
|
222
|
+
* @extends {{@link ProductActionConfig}
|
|
223
|
+
*/
|
|
224
|
+
interface ProductSetConfig extends Omit<ProductActionConfig, "amount"> {
|
|
225
|
+
/** The amount of products to be set */
|
|
226
|
+
amount?: number;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Configuration object to replace a product from the shopping cart.
|
|
230
|
+
*
|
|
231
|
+
* @interface ProductReplaceConfig
|
|
232
|
+
* @since 0.1.0
|
|
233
|
+
* @extends {{@link ProductActionConfig}
|
|
234
|
+
*/
|
|
235
|
+
interface ProductReplaceConfig extends ProductActionConfig {
|
|
236
|
+
/** The hash of product to be replaced */
|
|
237
|
+
hash?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Representation of a shopping cart totals.
|
|
241
|
+
*
|
|
242
|
+
* @interface ShoppingCartTotals
|
|
243
|
+
* @since 0.1.0
|
|
244
|
+
*/
|
|
245
|
+
interface ShoppingCartTotals$1 {
|
|
246
|
+
/** Cart subtotal without taxes */
|
|
247
|
+
subtotal: number;
|
|
248
|
+
/** Cart discounts total */
|
|
249
|
+
totalDiscounts: number | null;
|
|
250
|
+
/** Cart taxes total */
|
|
251
|
+
totalTaxes: number | null;
|
|
252
|
+
/** Cart shipping cost total */
|
|
253
|
+
shippingCost: number | null;
|
|
254
|
+
/** Cart points total */
|
|
255
|
+
totalPoints: number | null;
|
|
256
|
+
/** Cart total with taxes */
|
|
257
|
+
total: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Configuration object to find a product in a shopping cart. Inherits the
|
|
261
|
+
* shopping cart configuration omitting `anonymous` and
|
|
262
|
+
* `maxShoppingCarts` properties
|
|
263
|
+
*
|
|
264
|
+
* @interface FindProductConfig
|
|
265
|
+
* @since 0.1.0
|
|
266
|
+
* @extends {{@link ShoppingCartConfig}
|
|
267
|
+
*/
|
|
268
|
+
interface FindProductConfig extends Omit<ShoppingCartConfig, "anonymous" | "maxShoppingCarts"> {
|
|
269
|
+
/** Product unique identifier */
|
|
270
|
+
productId?: Product["productId"];
|
|
271
|
+
/** Product hash */
|
|
272
|
+
hash?: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Configuration object to empty the shopping cart.
|
|
276
|
+
*
|
|
277
|
+
* @interface FindProductConfig
|
|
278
|
+
* @since 0.1.0
|
|
279
|
+
* @extends {{@link ShoppingCartConfig}
|
|
280
|
+
*/
|
|
281
|
+
interface EmptyShoppingCartConfig extends ShoppingCartConfig {
|
|
282
|
+
/** The vendor's unique identifier */
|
|
283
|
+
vendorId?: Vendor["id"];
|
|
284
|
+
}
|
|
285
|
+
interface SettingsHeaders {
|
|
286
|
+
token: string;
|
|
287
|
+
platform: string;
|
|
288
|
+
accountId: string;
|
|
289
|
+
}
|
|
290
|
+
interface DocumentNode {
|
|
291
|
+
[key: string]: any;
|
|
292
|
+
}
|
|
293
|
+
interface SetDoc {
|
|
294
|
+
reusedConfig?: ProductAddConfig | ProductRemoveConfig;
|
|
295
|
+
shoppingCartNode?: ShoppingCartNode;
|
|
296
|
+
payload: any;
|
|
297
|
+
}
|
|
298
|
+
interface DeleteDoc {
|
|
299
|
+
reusedConfig?: ProductAddConfig | ProductRemoveConfig;
|
|
300
|
+
shoppingCartNode?: ShoppingCartNode;
|
|
301
|
+
}
|
|
302
|
+
interface Metadata {
|
|
303
|
+
hasPendingWrites: boolean;
|
|
304
|
+
fromCache: boolean;
|
|
305
|
+
isEqual(other: Metadata): boolean;
|
|
306
|
+
}
|
|
307
|
+
declare type ServerTimestamps = "estimate" | "previous" | "none";
|
|
308
|
+
interface SnapshotOptions {
|
|
309
|
+
serverTimestamps: ServerTimestamps;
|
|
310
|
+
}
|
|
311
|
+
interface ShoppingCartNode {
|
|
312
|
+
id: string;
|
|
313
|
+
metadata: Metadata;
|
|
314
|
+
data: (options?: Record<string, any>) => Record<string, any>;
|
|
315
|
+
get: (fieldPath: string, options?: SnapshotOptions) => any;
|
|
316
|
+
ref: any;
|
|
317
|
+
exists: any;
|
|
318
|
+
}
|
|
319
|
+
interface ShoppingCartBuilders {
|
|
320
|
+
getShoppingCartNode: (config: ShoppingCartConfig | undefined) => Promise<ShoppingCartNode | undefined>;
|
|
321
|
+
setDoc?: (config: SetDoc) => Promise<void>;
|
|
322
|
+
deleteDoc?: (config: DeleteDoc) => Promise<void>;
|
|
323
|
+
createShoppingCart?: (reusedConfig: ProductAddConfig | ShoppingCartCreateConfig, overrides: Partial<ShoppingCart> | undefined) => Promise<any>;
|
|
324
|
+
applyBenefitsToCart?: (config: ApplyBenefitConfig, benefit: Benefit, shippingCost?: ShippingCost) => Promise<void>;
|
|
325
|
+
getWallet?: (config?: ShoppingCartConfig | undefined) => Promise<Benefit[] | undefined>;
|
|
326
|
+
removeBenefitsFromCart?: (config: RemoveBenefitConfig, benefit: Benefit, shippingCost?: ShippingCost) => Promise<void>;
|
|
327
|
+
removeProduct?: (product: Product, config: ProductRemoveConfig | undefined) => Promise<any>;
|
|
328
|
+
}
|
|
329
|
+
interface BenefitsBuilders {
|
|
330
|
+
getBenefitsCollection?: (collectionName: string, ...path: string[]) => Promise<any>;
|
|
331
|
+
getBenefitsDocuments?: (collectionReference: any) => Promise<any>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Initialize shopping cart metadata, stores initial global state
|
|
336
|
+
* for future needs and establishes connection with artisnDB.
|
|
337
|
+
*
|
|
338
|
+
* @since 0.1.0
|
|
339
|
+
* @param {ShoppingCartConfig} config Global shopping cart state that can
|
|
340
|
+
* be configure at the function call level
|
|
341
|
+
*/
|
|
342
|
+
declare const initShoppingCart: (config?: ShoppingCartConfig) => void;
|
|
343
|
+
/**
|
|
344
|
+
* Closes all connections and resets the library to its default state.
|
|
345
|
+
*
|
|
346
|
+
* @since 0.1.0
|
|
347
|
+
*/
|
|
348
|
+
declare const closeShoppingCart: () => void;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Fetches a shopping cart of the given customer and account, given by the
|
|
352
|
+
* specified name. It will first try to look at the function config.
|
|
353
|
+
* If it cannot find any of the needed parameters, it will look into the global
|
|
354
|
+
* config provided in initShoppingCart.
|
|
355
|
+
*
|
|
356
|
+
* @template T Shopping cart generic type
|
|
357
|
+
* @since 0.1.0
|
|
358
|
+
* @param name The name of the wanted shopping cart, if none is given it will
|
|
359
|
+
* use the default shopping cart name to find one
|
|
360
|
+
* @param config Function call level shopping cart configuration
|
|
361
|
+
* @returns The shopping cart of a given customer given by its specified name
|
|
362
|
+
*/
|
|
363
|
+
declare const getShoppingCart: <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>>(builders: ShoppingCartBuilders, config?: ShoppingCartConfig) => Promise<T | null>;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Adds a product amount async to the remote shopping cart.
|
|
367
|
+
*
|
|
368
|
+
* @template T Shopping cart generic type
|
|
369
|
+
* @since 0.1.0
|
|
370
|
+
* @param {Product} product The product object that will be added to the cart.
|
|
371
|
+
* It can be a BaseProduct, a DetailedProduct or a CartProduct.
|
|
372
|
+
* @param {ProductAddConfig} config A configuration that specifies how to
|
|
373
|
+
* make an action over a product. E.g specify the amount.
|
|
374
|
+
*/
|
|
375
|
+
declare const addProduct: <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>>(builders: ShoppingCartBuilders, product: Product, config: ProductAddConfig) => Promise<T | null>;
|
|
376
|
+
declare const addProductToCartHelper: <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, product: Product, config: ProductAddConfig) => T;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Subtracts a product amount async to the remote shopping cart.
|
|
380
|
+
*
|
|
381
|
+
* @template T Shopping cart generic type
|
|
382
|
+
* @since 0.1.0
|
|
383
|
+
* @param {Product} product The product object that will be subtracted from the
|
|
384
|
+
* cart. It can be a BaseProduct, a DetailedProduct or a CartProduct
|
|
385
|
+
* @param {ProductActionConfig} config A configuration that specifies how to
|
|
386
|
+
* make an action over a product. E.g specify the amount
|
|
387
|
+
*/
|
|
388
|
+
declare const subtractProduct: <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>>(builders: ShoppingCartBuilders, product: Product, config: ProductActionConfig) => Promise<T | null>;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Removes a product async from the remote shopping cart
|
|
392
|
+
*
|
|
393
|
+
* @template T Shopping cart generic type
|
|
394
|
+
* @since 0.1.0
|
|
395
|
+
* @param {Product} product the product object that will be removed from the
|
|
396
|
+
* cart. It can be a BaseProduct, a DetailedProduct or a CartProduct
|
|
397
|
+
* @param {ProductRemoveConfig} config global configuration overrides. E.g
|
|
398
|
+
* storeId
|
|
399
|
+
*/
|
|
400
|
+
declare const removeProduct: <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>>(builders: ShoppingCartBuilders, product: Product, config?: ProductRemoveConfig) => Promise<T | null>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Sets a product async in the remote shopping cart
|
|
404
|
+
*
|
|
405
|
+
* @template T Shopping cart generic type
|
|
406
|
+
* @since 0.1.0
|
|
407
|
+
* @param {Product} product The product object that will be set in the cart. It
|
|
408
|
+
* can be a BaseProduct, a DetailedProduct or a CartProduct
|
|
409
|
+
* @param {ProductSetConfig} config A configuration that specifies how to make
|
|
410
|
+
* an action over a product. E.g specify the amount
|
|
411
|
+
*/
|
|
412
|
+
declare const setProduct: <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>>(builders: ShoppingCartBuilders, product: Product, config?: ProductSetConfig) => Promise<T | null>;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Replaces an existing product async in the remote shopping cart
|
|
416
|
+
*
|
|
417
|
+
* @template T Shopping cart generic type
|
|
418
|
+
* @since 0.1.0
|
|
419
|
+
* @param {CartProduct} product The product object that will be replaced in the
|
|
420
|
+
* cart. It can only be a CartProduct
|
|
421
|
+
* @param {ProductReplaceConfig} config A configuration that specifies how to
|
|
422
|
+
* make an action over a product. E.g specify the store
|
|
423
|
+
*/
|
|
424
|
+
declare const replaceProduct: <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>>(builders: ShoppingCartBuilders, product: CartProduct, config: ProductReplaceConfig) => Promise<T | null>;
|
|
425
|
+
|
|
426
|
+
declare const buildInitialShoppingCart: <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>>(overrides?: Partial<T>) => ShoppingCart;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Removes all products in all stores of a given cart. It will attempt to delete
|
|
430
|
+
* the last active shopping cart otherwise the default.
|
|
431
|
+
*
|
|
432
|
+
* If a vendor identifier is specified in the configuration object, it will
|
|
433
|
+
* remove all stores that have the specified vendor.
|
|
434
|
+
*
|
|
435
|
+
* @template T Shopping cart generic type
|
|
436
|
+
* @since 0.1.0
|
|
437
|
+
* @param {ShoppingCartConfig} config Empty shopping cart configuration
|
|
438
|
+
*/
|
|
439
|
+
declare const emptyShoppingCart: <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>>(builders: ShoppingCartBuilders, config?: EmptyShoppingCartConfig) => Promise<T | null>;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Deletes a customer shopping cart given by its name. It will attempt to delete
|
|
443
|
+
* the last active shopping cart otherwise the default.
|
|
444
|
+
*
|
|
445
|
+
* @template T Shopping cart generic type
|
|
446
|
+
* @since 0.1.0
|
|
447
|
+
* @param {ShoppingCartConfig} config Function call level shopping cart
|
|
448
|
+
* configuration
|
|
449
|
+
*/
|
|
450
|
+
declare const deleteShoppingCart: <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>>(builders: ShoppingCartBuilders, config?: ShoppingCartConfig) => Promise<T | null>;
|
|
451
|
+
|
|
452
|
+
interface ShoppingCartTotals {
|
|
453
|
+
subtotal: number;
|
|
454
|
+
totalDiscounts: number | null;
|
|
455
|
+
totalTaxes: number | null;
|
|
456
|
+
shippingCost: number | null;
|
|
457
|
+
totalPoints: number | null;
|
|
458
|
+
total: number;
|
|
459
|
+
}
|
|
460
|
+
interface ShoppingCartTotalsConfig {
|
|
461
|
+
shippingCost?: ShippingCost;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
declare const getProductHash: (product: CartProduct | CartProductAnswer) => string;
|
|
465
|
+
declare const pruneQuestionsAndAnswers: <T extends CartProductQuestion<AdditionalInfo> = CartProductQuestion<AdditionalInfo>>(questions: T[]) => T[];
|
|
466
|
+
/**
|
|
467
|
+
* Calculate the given shopping cart total values
|
|
468
|
+
*
|
|
469
|
+
* @since 0.1.0
|
|
470
|
+
* @param products the products in the shopping cart
|
|
471
|
+
* @param config additional info to calculate shopping cart summary
|
|
472
|
+
* @returns an object with a summary of the shopping cart totals
|
|
473
|
+
*/
|
|
474
|
+
declare const getShoppingCartTotal: (shoppingCart: ShoppingCart, config?: ShoppingCartTotalsConfig) => ShoppingCartTotals;
|
|
475
|
+
declare const getShoppingCartProducts: <T extends AdditionalInfo = AdditionalInfo, U extends AdditionalInfo = AdditionalInfo>(shoppingCart: ShoppingCart<AdditionalInfo, T, U, AdditionalInfo, AdditionalInfo, AdditionalInfo, AdditionalInfo>, storeId?: Store["storeId"]) => CartProduct<T, U>[];
|
|
476
|
+
/**
|
|
477
|
+
* Returns the specified product based on its id or hash if it exists on the
|
|
478
|
+
* active shopping cart. If both are provided, the hash takes precedence
|
|
479
|
+
* over the product id.
|
|
480
|
+
*
|
|
481
|
+
* @param {FindProductConfig} config Configuration provided to find the
|
|
482
|
+
* desired product
|
|
483
|
+
* @returns {Promise<Product|undefined>} The product if found in the
|
|
484
|
+
* shopping cart
|
|
485
|
+
*/
|
|
486
|
+
declare const findProduct: <T extends AdditionalInfo = AdditionalInfo, U extends AdditionalInfo = AdditionalInfo>(builders: ShoppingCartBuilders, config: FindProductConfig) => Promise<CartProduct<T, U> | undefined>;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Shopping cart validation options.
|
|
490
|
+
*
|
|
491
|
+
* @interface ValidateConfig
|
|
492
|
+
* @since 0.1.0
|
|
493
|
+
*/
|
|
494
|
+
interface ValidateConfig extends ShoppingCartConfig {
|
|
495
|
+
/** Location latitude of the user */
|
|
496
|
+
latitude?: number;
|
|
497
|
+
/** Location latitude of the user */
|
|
498
|
+
longitude?: number;
|
|
499
|
+
/** Artisn project api url */
|
|
500
|
+
apiURL?: string;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Validate shopping cart integrity.
|
|
505
|
+
*
|
|
506
|
+
* @since 0.1.0
|
|
507
|
+
* @param {ValidateConfig} config Object that defines the properties to check
|
|
508
|
+
* whether the shopping cart is valid.
|
|
509
|
+
* @param {Partial<Headers>} headers The shopping cart that will be
|
|
510
|
+
* validated. If none provided, then it will use default as its name.
|
|
511
|
+
* @return {Promise<ValidateShoppingCartResult | undefined>} An object which
|
|
512
|
+
* contains stores and products alerts
|
|
513
|
+
*/
|
|
514
|
+
declare const validateShoppingCart$1: (builders: ShoppingCartBuilders, config: ValidateConfig | undefined, headers: Headers) => Promise<ValidateShoppingCartResult | undefined>;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Close firestore connection.
|
|
518
|
+
*
|
|
519
|
+
* @since 0.1.0
|
|
520
|
+
* @param {string} selectedName The user's shopping cart name
|
|
521
|
+
* @param {Function} unsubscribe Reference to firestore node.
|
|
522
|
+
*/
|
|
523
|
+
declare const unsubscriber: (shoppingCartName: string, unsubscribe?: () => void) => void;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Apply a benefit with the given configuration on the current shopping cart.
|
|
527
|
+
*
|
|
528
|
+
* @since 0.1.0
|
|
529
|
+
* @param {ApplyBenefitConfig} config Benefits wallet configuration and
|
|
530
|
+
* @param {Headers} headers Supported headers to pass to the endpoint
|
|
531
|
+
* parameters to be passed to apply in shopping cart
|
|
532
|
+
*/
|
|
533
|
+
declare const applyBenefit: (builders: ShoppingCartBuilders, config: ApplyBenefitConfig, headers: Headers) => Promise<void>;
|
|
534
|
+
/**
|
|
535
|
+
* Helper apply a benefit provided to benefits array in shopping cart.
|
|
536
|
+
*
|
|
537
|
+
* @since 0.1.0
|
|
538
|
+
* @param {ShoppingCart} shoppingCart User's shopping cart
|
|
539
|
+
* @param {Benefit} benefit Benefit object to be applied
|
|
540
|
+
* @param {ShippingCost} shippingCost ShippingCost object to be added
|
|
541
|
+
* in shopping cart
|
|
542
|
+
* @returns {ShoppingCart} A shopping cart with the benefits applied
|
|
543
|
+
*/
|
|
544
|
+
declare const applyBenefitsHelper: (shoppingCart: ShoppingCart, benefit: Benefit, shippingCost?: ShippingCost) => ShoppingCart;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Remove a benefit with the given config on the current shopping cart.
|
|
548
|
+
*
|
|
549
|
+
* @since 0.1.0
|
|
550
|
+
* @param {RemoveBenefitConfig} config Benefits wallet configuration and
|
|
551
|
+
* parameters to be passed to remove in shopping cart
|
|
552
|
+
*/
|
|
553
|
+
declare const removeBenefit: (builders: ShoppingCartBuilders, config: RemoveBenefitConfig) => Promise<void>;
|
|
554
|
+
/**
|
|
555
|
+
* Helper to find and remove a benefit provided from benefits array
|
|
556
|
+
* in the shopping cart.
|
|
557
|
+
*
|
|
558
|
+
* @since 0.1.0
|
|
559
|
+
* @param {ShoppingCart} shoppingCart User's shopping cart
|
|
560
|
+
* @param {Benefit} benefit Benefit object to be removed
|
|
561
|
+
* @param {ShippingCost} shippingCost ShippingCost object to be restored
|
|
562
|
+
* in shopping cart
|
|
563
|
+
* @returns {ShoppingCart} Returns an updated shopping cart
|
|
564
|
+
*/
|
|
565
|
+
declare const removeBenefitsHelper: (shoppingCart: ShoppingCart, benefit: Benefit, shippingCost?: ShippingCost) => ShoppingCart;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Redeems a coupon based on the code given.
|
|
569
|
+
*
|
|
570
|
+
* @since 0.1.0
|
|
571
|
+
* @param {BenefitsWalletConfig} config Benefits wallet configuration parameters
|
|
572
|
+
* to be passed to call the endpoint.
|
|
573
|
+
* @param {string} code The code that the user inputs on the app.
|
|
574
|
+
* @param {Partial<WalletHeaders>} headers Headers to be passed to call the
|
|
575
|
+
* endpoint, as a default header, the uid is fetched internally
|
|
576
|
+
*/
|
|
577
|
+
declare const redeemCoupon: (builders: ShoppingCartBuilders, config: BenefitsWalletConfig, code: string, headers: Headers) => Promise<void>;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Merge a shopping cart to the current shopping cart or to the one specified
|
|
581
|
+
* through the configuration.
|
|
582
|
+
*
|
|
583
|
+
* @template T Shopping cart generic type
|
|
584
|
+
* @since 0.1.0
|
|
585
|
+
* @param {ShoppingCart} shoppingCart Shopping cart to be merged
|
|
586
|
+
* @param {ShoppingCartConfig} config Configuration to get the current shopping
|
|
587
|
+
* cart
|
|
588
|
+
*/
|
|
589
|
+
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>>(builders: ShoppingCartBuilders, shoppingCart: T, config?: ShoppingCartConfig) => Promise<T | null>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Function to obtain a cart store based on the store provided and the stores
|
|
593
|
+
* already in the cart.
|
|
594
|
+
*
|
|
595
|
+
* @template T Store additional info
|
|
596
|
+
* @template U Product additional info
|
|
597
|
+
* @template V Categories additional info
|
|
598
|
+
* @template W Vendor additional info
|
|
599
|
+
* @template X Catalogues additional info
|
|
600
|
+
* @since 0.1.0
|
|
601
|
+
* @param {number|Store} storeData Store data
|
|
602
|
+
* @param {CartStore} stores Shopping cart store data
|
|
603
|
+
* @returns {CartStore} The complete CartStore object
|
|
604
|
+
*/
|
|
605
|
+
declare const getStore: (storeData: ShoppingCartConfig["store"], stores: ShoppingCart["stores"]) => CartStore;
|
|
606
|
+
/**
|
|
607
|
+
* Checks if the shopping cart package has been initialized.
|
|
608
|
+
*
|
|
609
|
+
* @since 0.1.0
|
|
610
|
+
* @returns {boolean} The attribute that indicates whether or not the cart has
|
|
611
|
+
* been initialized
|
|
612
|
+
*/
|
|
613
|
+
declare const checkInit: () => boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Checks if the product to be modified is inside shopping cart benefits.
|
|
616
|
+
* If true, the benefits and benefits hash of the cart are deleted.
|
|
617
|
+
*
|
|
618
|
+
* @template T Shopping cart generic type
|
|
619
|
+
* @since 0.1.0
|
|
620
|
+
* @param {ShoppingCart} shoppingCart Provided shopping cart to be modified
|
|
621
|
+
* @param {Product} product Provided product to be modified, if none provided,
|
|
622
|
+
* assume the shopping cart is being emptied
|
|
623
|
+
* @returns {ShoppingCart} A shopping cart with the benefit and benefitsHash
|
|
624
|
+
* deleted
|
|
625
|
+
*/
|
|
626
|
+
declare const cleanShoppingCart: <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, product?: Product) => T;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Configuration to fetch store coupons.
|
|
630
|
+
*
|
|
631
|
+
* @interface StoreCouponsConfig
|
|
632
|
+
* @since 0.1.0
|
|
633
|
+
*/
|
|
634
|
+
interface StoreCouponsConfig {
|
|
635
|
+
/** Provided vendor id */
|
|
636
|
+
vendorId: Vendor["id"];
|
|
637
|
+
/** Provided api URL */
|
|
638
|
+
apiURL: string;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Configuration to fetch a store coupon detail, extends
|
|
642
|
+
* {@link StoreCouponsConfig} omitting the vendor id
|
|
643
|
+
*
|
|
644
|
+
* @interface StoreCouponDetailConfig
|
|
645
|
+
* @since 0.1.0
|
|
646
|
+
* @extends {{@link StoreCouponsConfig}
|
|
647
|
+
*/
|
|
648
|
+
interface StoreCouponDetailConfig extends Omit<StoreCouponsConfig, "vendorId"> {
|
|
649
|
+
/** Provided coupon id */
|
|
650
|
+
couponId: number;
|
|
651
|
+
/** Provided country id */
|
|
652
|
+
countryId: number;
|
|
653
|
+
/** Provided api URL */
|
|
654
|
+
apiURL: string;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* The endpoint to fetch a wallet of a user.
|
|
659
|
+
*
|
|
660
|
+
* @since 0.1.0
|
|
661
|
+
* @param {BenefitsWalletConfig} config Benefits wallet configuration
|
|
662
|
+
* @param {Headers} headers Supported headers to pass to the endpoint
|
|
663
|
+
*/
|
|
664
|
+
declare const fetchWalletByUser: (config: BenefitsWalletConfig, headers: Headers) => Promise<void>;
|
|
665
|
+
/**
|
|
666
|
+
* The endpoint to redeem a coupon.
|
|
667
|
+
*
|
|
668
|
+
* @since 0.1.0
|
|
669
|
+
* @param {BenefitsWalletConfig} config Benefits wallet configuration
|
|
670
|
+
* @param {string} code The code to redeem a coupon
|
|
671
|
+
* @param {Headers} headers Supported headers to pass to the endpoint
|
|
672
|
+
* @returns {Promise<boolean>} True if the coupon was redeemed correctly, false
|
|
673
|
+
* if otherwise.
|
|
674
|
+
*/
|
|
675
|
+
declare const redeemCouponService: (config: BenefitsWalletConfig, code: string, headers: Headers) => Promise<boolean>;
|
|
676
|
+
/**
|
|
677
|
+
* The endpoint to fetch a store coupons.
|
|
678
|
+
*
|
|
679
|
+
* @since 0.1.0
|
|
680
|
+
* @param {StoreCouponsConfig} config Store coupons configuration
|
|
681
|
+
* @param {Headers} headers Supported headers to pass to the endpoint
|
|
682
|
+
* @returns {Promise<StoreCoupon[]>} An array of store coupons
|
|
683
|
+
*/
|
|
684
|
+
declare const fetchStoreCoupons: (config: StoreCouponsConfig, headers: Headers) => Promise<StoreCoupon[]>;
|
|
685
|
+
/**
|
|
686
|
+
* The endpoint to fetch a store coupon detail.
|
|
687
|
+
*
|
|
688
|
+
* @since 0.1.0
|
|
689
|
+
* @param {StoreCouponDetailConfig} config Store coupon detail configuration
|
|
690
|
+
* @param {Headers} headers Supported headers to pass to the endpoint
|
|
691
|
+
* @returns {Promise<StoreCouponDetail>} A store coupon detail object
|
|
692
|
+
*/
|
|
693
|
+
declare const fetchStoreCouponDetail: (config: StoreCouponDetailConfig, headers: Headers) => Promise<StoreCouponDetail>;
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Sets properties in the shopping cart remotely.
|
|
697
|
+
*
|
|
698
|
+
* @template T Shopping cart generic type
|
|
699
|
+
* @since 0.1.0
|
|
700
|
+
* @param {Function} shoppingCart The cart that will be set remotely
|
|
701
|
+
* @param {ShoppingCartConfig} config Shopping cart configuration
|
|
702
|
+
*/
|
|
703
|
+
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>>(builders: ShoppingCartBuilders, setShoppingCart: (previousShoppingCart: T) => T, config?: ShoppingCartConfig) => Promise<T | null>;
|
|
704
|
+
|
|
705
|
+
declare const initialState: GlobalState;
|
|
706
|
+
declare const setState: (overrides: Partial<GlobalState>) => void;
|
|
707
|
+
declare const getState: () => {
|
|
708
|
+
accountId?: number | undefined;
|
|
709
|
+
customerId?: string | number | undefined;
|
|
710
|
+
store?: _artisan_commerce_types.Store<_artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo, _artisan_commerce_types.AdditionalInfo> | undefined;
|
|
711
|
+
activeShoppingCart: string;
|
|
712
|
+
maxShoppingCarts: number;
|
|
713
|
+
wallets: Wallets;
|
|
714
|
+
anonymous?: boolean | undefined;
|
|
715
|
+
initialized: boolean;
|
|
716
|
+
queue: ActionQueue;
|
|
717
|
+
eventLoop: EventLoop;
|
|
718
|
+
debug?: boolean | undefined;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Gets the initial state of an empty benefits wallet.
|
|
723
|
+
*
|
|
724
|
+
* @since 0.1.0
|
|
725
|
+
* @returns An empty benefits wallet
|
|
726
|
+
*/
|
|
727
|
+
declare const getInitialBenefitsWallet: (overrides?: Partial<Wallet>) => Wallet;
|
|
728
|
+
/**
|
|
729
|
+
* Transforms the benefits node to an array of benefits.
|
|
730
|
+
*
|
|
731
|
+
* @since 0.1.0
|
|
732
|
+
* @param {DocumentNode} benefitsNode Benefits by user node
|
|
733
|
+
* @param {string} hash Realtime db node id
|
|
734
|
+
* @returns {Benefit[]} An array of benefits with the hash inside them
|
|
735
|
+
*/
|
|
736
|
+
declare const mapCollectionToBenefits: (benefitsNode: DocumentNode, hash: string) => Benefit[];
|
|
737
|
+
/**
|
|
738
|
+
* Updates the current benefits wallets with a new wallet.
|
|
739
|
+
*
|
|
740
|
+
* @since 0.1.0
|
|
741
|
+
* @param {string} walletName The name of the target wallet
|
|
742
|
+
* @param {WalletInternal} newWallet The new wallet to be set in the state
|
|
743
|
+
*/
|
|
744
|
+
declare const updateBenefitsWallets: (walletName: string, newWallet: WalletInternal) => void;
|
|
745
|
+
/**
|
|
746
|
+
* Fetches all Artisn benefits of the given customer and account. It will first
|
|
747
|
+
* try to look at the function config. If it cannot find any of the needed
|
|
748
|
+
* parameters, it will look into the global config provided in initShoppingCart.
|
|
749
|
+
*
|
|
750
|
+
* @since 0.1.0
|
|
751
|
+
* @param {ShoppingCartConfig} config Shopping cart configuration
|
|
752
|
+
* @returns {Promise<ShoppingCartNodes | undefined>} A collection of benefits
|
|
753
|
+
* of the given customer in the form of firestore document nodes
|
|
754
|
+
*/
|
|
755
|
+
declare const getBenefitsNode: (builders: BenefitsBuilders, config?: ShoppingCartConfig) => Promise<any | undefined>;
|
|
756
|
+
/**
|
|
757
|
+
* Fetches the wallet node of the given customer and account. It will first try
|
|
758
|
+
* to look at the function config. If it cannot find any of the needed
|
|
759
|
+
* parameters, it will look into the global config provided in initShoppingCart.
|
|
760
|
+
*
|
|
761
|
+
* @since 0.1.0
|
|
762
|
+
* @param {ShoppingCartConfig} config Shopping cart configuration
|
|
763
|
+
* @returns {Promise<any | undefined>} The benefits of a given
|
|
764
|
+
* customer in the form of firestore document nodes
|
|
765
|
+
*/
|
|
766
|
+
declare const getWalletNode: (builders: BenefitsBuilders, config?: ShoppingCartConfig) => Promise<any | undefined>;
|
|
767
|
+
/**
|
|
768
|
+
* Fetches an array of benefits of the given customer and account. It will first
|
|
769
|
+
* try to look at the function config. If it cannot find any of the needed
|
|
770
|
+
* parameters, it will look into the global config provided in initShoppingCart.
|
|
771
|
+
*
|
|
772
|
+
* @since 0.1.0
|
|
773
|
+
* @param {ShoppingCartConfig} config Shopping cart configuration
|
|
774
|
+
* @returns {Promise<Benefit[] | undefined>} An array of benefits of the given
|
|
775
|
+
* customer, each benefit has the firestore hash inside them.
|
|
776
|
+
*/
|
|
777
|
+
declare const getWallet: (builders: BenefitsBuilders, config?: ShoppingCartConfig | undefined) => Promise<Benefit[] | undefined>;
|
|
778
|
+
|
|
779
|
+
declare const defaultSort: (a: number | string, b: number | string) => 1 | -1 | 0;
|
|
780
|
+
declare const sortByField: (field: string, a: any, b: any) => 1 | -1 | 0;
|
|
781
|
+
declare const sortByProductId: (a: CartProductAnswer, b: CartProductAnswer) => 1 | -1 | 0;
|
|
782
|
+
declare const sortByQuestionId: (a: CartProductQuestion, b: CartProductQuestion) => 1 | -1 | 0;
|
|
783
|
+
/**
|
|
784
|
+
* Functions that throws an error when running on development environment
|
|
785
|
+
* and logs the error if running on production environment
|
|
786
|
+
* @since 0.1.0
|
|
787
|
+
* @param message: the message to be displayed
|
|
788
|
+
*/
|
|
789
|
+
declare const logError: (message: string) => void;
|
|
790
|
+
/**
|
|
791
|
+
* Functions that logs a warning only if on debug mode
|
|
792
|
+
* @since 0.1.0
|
|
793
|
+
* @param message: the message to be displayed
|
|
794
|
+
*/
|
|
795
|
+
declare const logDebug: (message: string) => void;
|
|
796
|
+
/**
|
|
797
|
+
* Utility function to reuse global configuration.
|
|
798
|
+
*
|
|
799
|
+
* @since 0.1.0
|
|
800
|
+
* @param {ShoppingCartConfig} config Custom configuration
|
|
801
|
+
* @returns {ShoppingCartConfig} Configuration prioritizing custom over global
|
|
802
|
+
* values
|
|
803
|
+
*/
|
|
804
|
+
declare const reuseGlobalConfig: <T extends ShoppingCartConfig>(config?: T | undefined) => T;
|
|
805
|
+
|
|
806
|
+
declare const buildServiceHeaders: (settings: SettingsHeaders, headers: Headers) => Promise<Headers>;
|
|
807
|
+
|
|
808
|
+
declare const checkInitialized: () => void;
|
|
809
|
+
declare const checkMinimumConfigProvided: (config?: ShoppingCartConfig) => void;
|
|
810
|
+
/**
|
|
811
|
+
* Check minimum fetch wallet configuration provided.
|
|
812
|
+
*
|
|
813
|
+
* @since 0.1.0
|
|
814
|
+
* @param {BenefitsWalletConfig} config Benefits wallet configuration parameters to pass to call the endpoint.
|
|
815
|
+
*/
|
|
816
|
+
declare const checkMinimumFetchWalletConfigProvided: (config?: BenefitsWalletConfig) => void;
|
|
817
|
+
|
|
818
|
+
declare const verifyHeaders: (headers: Headers) => void;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Configuration object to validate a shopping cart.
|
|
822
|
+
*
|
|
823
|
+
* @interface ValidateShoppingCartConfig
|
|
824
|
+
* @since 0.1.0
|
|
825
|
+
*/
|
|
826
|
+
interface ValidateShoppingCartConfig {
|
|
827
|
+
/** Shopping cart node id */
|
|
828
|
+
id: string;
|
|
829
|
+
/** Location latitude of the user */
|
|
830
|
+
latitude?: number;
|
|
831
|
+
/** Location latitude of the user */
|
|
832
|
+
longitude?: number;
|
|
833
|
+
/** Provide api URL */
|
|
834
|
+
apiURL: string;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* The validation result of a shopping cart.
|
|
838
|
+
*
|
|
839
|
+
* @interface ValidateShoppingCartResult
|
|
840
|
+
* @since 0.1.0
|
|
841
|
+
*/
|
|
842
|
+
interface ValidateShoppingCartResult {
|
|
843
|
+
/**
|
|
844
|
+
* An array of shopping cart alerts associated with the stores,
|
|
845
|
+
* see {@link Alert}
|
|
846
|
+
*/
|
|
847
|
+
stores: Alert[];
|
|
848
|
+
/**
|
|
849
|
+
* An array of shopping cart alerts associated with the products,
|
|
850
|
+
* see {@link Alert}
|
|
851
|
+
*/
|
|
852
|
+
products: Alert[];
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* The endpoint to validate a shopping cart.
|
|
857
|
+
*
|
|
858
|
+
* @since 0.1.0
|
|
859
|
+
* @param {ValidateShoppingCartConfig} config Validate shopping cart
|
|
860
|
+
* configuration
|
|
861
|
+
* @param {ValidateHeaders} headers Headers to validate the shopping cart
|
|
862
|
+
* @returns {Promise<ValidateShoppingCartResult>} An object which contains stores and
|
|
863
|
+
* products alerts.
|
|
864
|
+
*/
|
|
865
|
+
declare const validateShoppingCart: (config: ValidateShoppingCartConfig, headers: Headers) => Promise<ValidateShoppingCartResult>;
|
|
866
|
+
|
|
867
|
+
declare const CONSTANTS: {
|
|
868
|
+
PRODUCT_DATE_FORMAT: string;
|
|
869
|
+
DEFAULT_SHOPPING_CART_NAME: string;
|
|
870
|
+
DEFAULT_MAX_SHOPPING_CARTS: number;
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
export { ActionQueue, ApplyBenefitConfig, BenefitsWalletConfig, CONSTANTS, EmptyShoppingCartConfig, EventLoop, FindProductConfig, GlobalState, ProductActionConfig, ProductAddConfig, ProductRemoveConfig, ProductReplaceConfig, ProductSetConfig, RemoveBenefitConfig, ShoppingCartConfig, ShoppingCartCreateConfig, ShoppingCartTotals$1 as ShoppingCartTotals, ValidateShoppingCartResult, WalletHeaders, WalletInternal, Wallets, addProduct, addProductToCartHelper, applyBenefit, applyBenefitsHelper, buildInitialShoppingCart, buildServiceHeaders, checkInit, checkInitialized, checkMinimumConfigProvided, checkMinimumFetchWalletConfigProvided, cleanShoppingCart, closeShoppingCart, defaultSort, deleteShoppingCart, emptyShoppingCart, fetchStoreCouponDetail, fetchStoreCoupons, fetchWalletByUser, findProduct, getBenefitsNode, getInitialBenefitsWallet, getProductHash, getShoppingCart, getShoppingCartProducts, getShoppingCartTotal, getState, getStore, getWallet, getWalletNode, initShoppingCart, initialState, logDebug, logError, mapCollectionToBenefits, mergeShoppingCart, pruneQuestionsAndAnswers, redeemCoupon, redeemCouponService, removeBenefit, removeBenefitsHelper, removeProduct, replaceProduct, reuseGlobalConfig, setProduct, setState, sortByField, sortByProductId, sortByQuestionId, subtractProduct, unsubscriber, updateBenefitsWallets, updateShoppingCart, validateShoppingCart$1 as validateShoppingCart, validateShoppingCart as validateShoppingCartService, verifyHeaders };
|