ingeniuscliq-core 0.3.44 → 0.3.46

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/dist/index.js CHANGED
@@ -2525,40 +2525,60 @@ class J5 {
2525
2525
  ...this.initialState,
2526
2526
  setLoading: (r) => t({ loading: r }),
2527
2527
  setError: (r) => t({ error: r }),
2528
- addToCart: async (r, o) => {
2528
+ addToCart: async (r, o, { onSuccess: a = () => {
2529
+ }, onError: s = () => {
2530
+ }, onFinish: i = () => {
2531
+ } }) => {
2529
2532
  try {
2530
2533
  t({ loading: !0, error: null }), await this.shopCartService.addToCart(r, o);
2531
- let a = await this.shopCartService.getCart();
2532
- t(() => ({ cart: a.data.data, cartItems: a.data.data.items, loading: !1 }));
2533
- } catch (a) {
2534
- throw console.error(a), t((s) => ({ ...s, error: a, loading: !1 })), a;
2534
+ let c = await this.shopCartService.getCart();
2535
+ t(() => ({ cart: c.data.data, cartItems: c.data.data.items, loading: !1 })), a(c);
2536
+ } catch (c) {
2537
+ throw console.error(c), t((u) => ({ ...u, error: c, loading: !1 })), s(c), c;
2538
+ } finally {
2539
+ i();
2535
2540
  }
2536
2541
  },
2537
- removeFromCart: async (r) => {
2542
+ removeFromCart: async (r, { onSuccess: o = () => {
2543
+ }, onError: a = () => {
2544
+ }, onFinish: s = () => {
2545
+ } }) => {
2538
2546
  try {
2539
2547
  t({ loading: !0, error: null }), await this.shopCartService.removeFromCart(r);
2540
- let o = await this.shopCartService.getCart();
2541
- t(() => ({ cart: o.data.data, cartItems: o.data.data.items, loading: !1 }));
2542
- } catch (o) {
2543
- throw console.error(o), t((a) => ({ ...a, error: o, loading: !1 })), o;
2548
+ let i = await this.shopCartService.getCart();
2549
+ t(() => ({ cart: i.data.data, cartItems: i.data.data.items, loading: !1 })), o(i);
2550
+ } catch (i) {
2551
+ throw console.error(i), t((c) => ({ ...c, error: i, loading: !1 })), a(i), i;
2552
+ } finally {
2553
+ s();
2544
2554
  }
2545
2555
  },
2546
- removeItemFromCart: async (r) => {
2556
+ removeItemFromCart: async (r, { onSuccess: o = () => {
2557
+ }, onError: a = () => {
2558
+ }, onFinish: s = () => {
2559
+ } }) => {
2547
2560
  try {
2548
2561
  t({ loading: !0, error: null }), await this.shopCartService.removeItemFromCart(r);
2549
- let o = await this.shopCartService.getCart();
2550
- t(() => ({ cart: o.data.data, cartItems: o.data.data.items, loading: !1 }));
2551
- } catch (o) {
2552
- throw console.error(o), t((a) => ({ ...a, error: o, loading: !1 })), o;
2562
+ let i = await this.shopCartService.getCart();
2563
+ t(() => ({ cart: i.data.data, cartItems: i.data.data.items, loading: !1 })), o(i);
2564
+ } catch (i) {
2565
+ throw console.error(i), t((c) => ({ ...c, error: i, loading: !1 })), a(i), i;
2566
+ } finally {
2567
+ s();
2553
2568
  }
2554
2569
  },
2555
- clearCart: async () => {
2570
+ clearCart: async ({ onSuccess: r = () => {
2571
+ }, onError: o = () => {
2572
+ }, onFinish: a = () => {
2573
+ } }) => {
2556
2574
  try {
2557
2575
  t({ loading: !0, error: null }), await this.shopCartService.clearCart();
2558
- let r = await this.shopCartService.getCart();
2559
- t(() => ({ cart: r.data.data, cartItems: r.data.data.items, loading: !1 }));
2560
- } catch (r) {
2561
- throw console.error(r), t((o) => ({ ...o, error: r, loading: !1 })), r;
2576
+ let s = await this.shopCartService.getCart();
2577
+ t(() => ({ cart: s.data.data, cartItems: s.data.data.items, loading: !1 })), r(s);
2578
+ } catch (s) {
2579
+ throw console.error(s), t((i) => ({ ...i, error: s, loading: !1 })), o(s), s;
2580
+ } finally {
2581
+ a();
2562
2582
  }
2563
2583
  },
2564
2584
  getCartItems: () => n().cartItems,
@@ -2569,22 +2589,32 @@ class J5 {
2569
2589
  setCartItems: (r) => {
2570
2590
  t({ cartItems: r });
2571
2591
  },
2572
- fetchCart: async () => {
2592
+ fetchCart: async ({ onSuccess: r = () => {
2593
+ }, onError: o = () => {
2594
+ }, onFinish: a = () => {
2595
+ } }) => {
2573
2596
  try {
2574
2597
  t({ loading: !0, error: null });
2575
- let r = await this.shopCartService.getCart();
2576
- return t(() => ({ cart: r.data.data, cartItems: r.data.data.items, loading: !1 })), r.data;
2577
- } catch (r) {
2578
- throw console.error(r), t((o) => ({ ...o, error: r, loading: !1 })), r;
2598
+ let s = await this.shopCartService.getCart();
2599
+ return t(() => ({ cart: s.data.data, cartItems: s.data.data.items, loading: !1 })), r(s), s.data;
2600
+ } catch (s) {
2601
+ throw console.error(s), t((i) => ({ ...i, error: s, loading: !1 })), o(s), s;
2602
+ } finally {
2603
+ a();
2579
2604
  }
2580
2605
  },
2581
- fetchCartItems: async () => {
2606
+ fetchCartItems: async ({ onSuccess: r = () => {
2607
+ }, onError: o = () => {
2608
+ }, onFinish: a = () => {
2609
+ } }) => {
2582
2610
  try {
2583
2611
  t({ loading: !0, error: null });
2584
- let r = await this.shopCartService.getCartItems();
2585
- return t(() => ({ cartItems: r.data.data, loading: !1 })), r.data;
2586
- } catch (r) {
2587
- throw console.error(r), t((o) => ({ ...o, error: r, loading: !1 })), r;
2612
+ let s = await this.shopCartService.getCartItems();
2613
+ return t(() => ({ cartItems: s.data.data, loading: !1 })), r(s), s.data;
2614
+ } catch (s) {
2615
+ throw console.error(s), t((i) => ({ ...i, error: s, loading: !1 })), o(s), s;
2616
+ } finally {
2617
+ a();
2588
2618
  }
2589
2619
  },
2590
2620
  reset: () => t(this.initialState)
@@ -8,8 +8,8 @@ export declare class CoreShopCartBuilder<T> implements CoreBuilder {
8
8
  build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreShopCartStore<T>>, "persist"> & {
9
9
  persist: {
10
10
  setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CoreShopCartStore<T>, {
11
- cart: import('../types').CoreShopCart<T>;
12
- cartItems: import('../types').CoreCartItem<T>[];
11
+ cart: import('../../../types').CoreShopCart<T>;
12
+ cartItems: import('../../../types').CoreCartItem<T>[];
13
13
  }>>) => void;
14
14
  clearStorage: () => void;
15
15
  rehydrate: () => Promise<void> | void;
@@ -17,8 +17,8 @@ export declare class CoreShopCartBuilder<T> implements CoreBuilder {
17
17
  onHydrate: (fn: (state: CoreShopCartStore<T>) => void) => () => void;
18
18
  onFinishHydration: (fn: (state: CoreShopCartStore<T>) => void) => () => void;
19
19
  getOptions: () => Partial<import('zustand/middleware').PersistOptions<CoreShopCartStore<T>, {
20
- cart: import('../types').CoreShopCart<T>;
21
- cartItems: import('../types').CoreCartItem<T>[];
20
+ cart: import('../../../types').CoreShopCart<T>;
21
+ cartItems: import('../../../types').CoreCartItem<T>[];
22
22
  }>>;
23
23
  };
24
24
  }>;
@@ -1,17 +1,18 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { CoreShopCart, CoreCartItem } from '../CoreShopCart';
3
3
  import { BaseApiResponse } from '../../../../types/contracts/BaseApiResponse';
4
+ import { CoreActions } from '../../../../types';
4
5
  export interface ICartActions<T> {
5
- addToCart: (product_id: string | number, quantity: number) => void;
6
- removeFromCart: (product_id: string | number) => void;
7
- removeItemFromCart: (product_id: string | number) => void;
8
- clearCart: () => void;
6
+ addToCart: (product_id: string | number, quantity: number, actions: CoreActions) => void;
7
+ removeFromCart: (product_id: string | number, actions: CoreActions) => void;
8
+ removeItemFromCart: (product_id: string | number, actions: CoreActions) => void;
9
+ clearCart: (actions: CoreActions) => void;
9
10
  getCart: () => CoreShopCart<T>;
10
11
  setCart: (cart: CoreShopCart<T>) => void;
11
12
  getCartItems: () => CoreCartItem<T>[];
12
13
  setCartItems: (cartItems: CoreCartItem<T>[]) => void;
13
- fetchCart: () => Promise<BaseApiResponse<CoreShopCart<T>>>;
14
- fetchCartItems: () => Promise<BaseApiResponse<CoreCartItem<T>[]>>;
14
+ fetchCart: (actions: CoreActions) => Promise<BaseApiResponse<CoreShopCart<T>>>;
15
+ fetchCartItems: (actions: CoreActions) => Promise<BaseApiResponse<CoreCartItem<T>[]>>;
15
16
  }
16
17
  export interface ICartActionsService<T> {
17
18
  addToCart: (product_id: string | number, quantity: number) => Promise<AxiosResponse<BaseApiResponse<CoreCartItem<T>>>>;
@@ -0,0 +1,8 @@
1
+ export interface CoreActions {
2
+ onSuccess?: CoreSuccessAction;
3
+ onError?: CoreErrorAction;
4
+ onFinish?: CoreFinishAction;
5
+ }
6
+ export type CoreSuccessAction = (response: any) => void;
7
+ export type CoreErrorAction = (error: any) => void;
8
+ export type CoreFinishAction = () => void;
@@ -1,3 +1,4 @@
1
1
  export * from './BaseImageType';
2
2
  export * from './BaseSlugType';
3
3
  export * from './BaseVisibleType';
4
+ export * from '../BaseResponseActions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeniuscliq-core",
3
- "version": "0.3.44",
3
+ "version": "0.3.46",
4
4
  "description": "IngeniusCliq Core UI y lógica compartida",
5
5
  "license": "MIT",
6
6
  "type": "module",