ingeniuscliq-core 0.5.21 → 0.5.24

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.
Files changed (28) hide show
  1. package/dist/classes/CoreBaseBuilder.d.ts +67 -0
  2. package/dist/classes/CoreBaseBuilder.d.ts.map +1 -0
  3. package/dist/classes/CoreBaseBuilder.js +65 -0
  4. package/dist/classes/index.d.ts +1 -0
  5. package/dist/classes/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/modules/CoreAuth/classes/CoreAuthBuilder.d.ts +10 -9
  8. package/dist/modules/CoreAuth/classes/CoreAuthBuilder.d.ts.map +1 -1
  9. package/dist/modules/CoreAuth/classes/CoreAuthBuilder.js +153 -147
  10. package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.d.ts +10 -9
  11. package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.d.ts.map +1 -1
  12. package/dist/modules/CoreCustomization/classes/CoreCustomizationBuilder.js +66 -60
  13. package/dist/modules/CoreOrder/classes/CoreOrderBuilder.d.ts +10 -9
  14. package/dist/modules/CoreOrder/classes/CoreOrderBuilder.d.ts.map +1 -1
  15. package/dist/modules/CoreOrder/classes/CoreOrderBuilder.js +95 -89
  16. package/dist/modules/CorePayForm/classes/CorePayFormBuilder.d.ts +10 -9
  17. package/dist/modules/CorePayForm/classes/CorePayFormBuilder.d.ts.map +1 -1
  18. package/dist/modules/CorePayForm/classes/CorePayFormBuilder.js +50 -44
  19. package/dist/modules/CoreProduct/classes/CoreProductBuilder.d.ts +10 -9
  20. package/dist/modules/CoreProduct/classes/CoreProductBuilder.d.ts.map +1 -1
  21. package/dist/modules/CoreProduct/classes/CoreProductBuilder.js +119 -113
  22. package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts +10 -9
  23. package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts.map +1 -1
  24. package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.js +174 -165
  25. package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts +10 -19
  26. package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.d.ts.map +1 -1
  27. package/dist/modules/CoreShopCart/classes/CoreShopCartBuilder.js +159 -150
  28. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
1
  import { create } from 'zustand';
2
2
  import { persist } from '../../../node_modules/zustand/esm/middleware.js';
3
3
  import { CoreCustomizationBaseService } from '../services/base.js';
4
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
4
5
 
5
- class CoreCustomizationBuilder {
6
+ class CoreCustomizationBuilder extends CoreBaseBuilder {
6
7
  customizationService;
7
8
  initialState = {
8
9
  template: null,
@@ -13,79 +14,84 @@ class CoreCustomizationBuilder {
13
14
  error: null
14
15
  };
15
16
  constructor(service = new CoreCustomizationBaseService(), initialState) {
17
+ super();
16
18
  this.customizationService = service;
17
19
  if (initialState) {
18
20
  this.initialState = { ...this.initialState, ...initialState };
19
21
  }
20
22
  }
23
+ getBaseState(set, _get) {
24
+ return {
25
+ ...this.initialState,
26
+ // Setters
27
+ setLoading: (loading) => set({ loading }),
28
+ setError: (error) => set({ error }),
29
+ setTemplate: (template) => set({ template }),
30
+ setComponents: (components) => set({ components }),
31
+ setStyles: (styles) => set({ styles }),
32
+ setSettings: (settings) => set({ settings }),
33
+ // Actions
34
+ fetchTemplate: async (params) => {
35
+ const { onlyFetch } = params || {};
36
+ try {
37
+ if (!onlyFetch) {
38
+ set({ loading: true, error: null });
39
+ }
40
+ const response = await this.customizationService.fetchTemplate();
41
+ const template = response.data.data;
42
+ if (!onlyFetch) {
43
+ set({
44
+ template: template.template || null,
45
+ styles: template.styles || null,
46
+ loading: false
47
+ });
48
+ }
49
+ return template;
50
+ } catch (error) {
51
+ if (!onlyFetch) {
52
+ set({ loading: false, error });
53
+ }
54
+ throw error;
55
+ }
56
+ },
57
+ fetchSettings: async (params) => {
58
+ const { onlyFetch } = params || {};
59
+ try {
60
+ if (!onlyFetch) {
61
+ set({ loading: true, error: null });
62
+ }
63
+ const response = await this.customizationService.fetchSettings();
64
+ const settings = response.data.data.configuration;
65
+ if (!onlyFetch) {
66
+ set({
67
+ settings,
68
+ loading: false
69
+ });
70
+ }
71
+ return settings;
72
+ } catch (error) {
73
+ if (!onlyFetch) {
74
+ set({ loading: false, error });
75
+ }
76
+ throw error;
77
+ }
78
+ },
79
+ // Reset
80
+ reset: () => set({ ...this.initialState, ...this.extendInitialState() })
81
+ };
82
+ }
21
83
  build() {
22
84
  return create()(
23
85
  persist(
24
- (set) => ({
25
- ...this.initialState,
26
- // Setters
27
- setLoading: (loading) => set({ loading }),
28
- setError: (error) => set({ error }),
29
- setTemplate: (template) => set({ template }),
30
- setComponents: (components) => set({ components }),
31
- setStyles: (styles) => set({ styles }),
32
- setSettings: (settings) => set({ settings }),
33
- // Actions
34
- fetchTemplate: async (params) => {
35
- const { onlyFetch } = params || {};
36
- try {
37
- if (!onlyFetch) {
38
- set({ loading: true, error: null });
39
- }
40
- const response = await this.customizationService.fetchTemplate();
41
- const template = response.data.data;
42
- if (!onlyFetch) {
43
- set({
44
- template: template.template || null,
45
- styles: template.styles || null,
46
- loading: false
47
- });
48
- }
49
- return template;
50
- } catch (error) {
51
- if (!onlyFetch) {
52
- set({ loading: false, error });
53
- }
54
- throw error;
55
- }
56
- },
57
- fetchSettings: async (params) => {
58
- const { onlyFetch } = params || {};
59
- try {
60
- if (!onlyFetch) {
61
- set({ loading: true, error: null });
62
- }
63
- const response = await this.customizationService.fetchSettings();
64
- const settings = response.data.data.configuration;
65
- if (!onlyFetch) {
66
- set({
67
- settings,
68
- loading: false
69
- });
70
- }
71
- return settings;
72
- } catch (error) {
73
- if (!onlyFetch) {
74
- set({ loading: false, error });
75
- }
76
- throw error;
77
- }
78
- },
79
- // Reset
80
- reset: () => set(this.initialState)
81
- }),
86
+ (set, get) => this.buildStoreState(set, get),
82
87
  {
83
88
  name: "customization-storage",
84
89
  partialize: (state) => ({
85
90
  template: state.template,
86
91
  components: state.components,
87
92
  styles: state.styles,
88
- settings: state.settings
93
+ settings: state.settings,
94
+ ...this.extendPartialize(state)
89
95
  })
90
96
  }
91
97
  )
@@ -1,21 +1,22 @@
1
1
  import { CoreOrderBaseService } from '../services/base';
2
2
  import { CoreOrder, CoreOrderStore } from '../types/CoreOrder';
3
- import { CoreBuilder } from '../../../classes/CoreBuilder';
4
- export declare class CoreOrderBuilder<T> implements CoreBuilder {
3
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
4
+ export declare class CoreOrderBuilder<T, TStore extends CoreOrderStore<T> = CoreOrderStore<T>> extends CoreBaseBuilder<TStore> {
5
5
  protected orderService: CoreOrderBaseService;
6
- protected initialState: Pick<CoreOrderStore<T>, "orderDetails" | "orders" | "loading" | "error">;
7
- constructor(orderService?: CoreOrderBaseService, initialState?: Partial<CoreOrderStore<T>>);
8
- build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreOrderStore<T>>, "persist"> & {
6
+ protected initialState: Pick<TStore, "orderDetails" | "orders" | "loading" | "error">;
7
+ constructor(orderService?: CoreOrderBaseService, initialState?: Partial<TStore>);
8
+ protected getBaseState(set: any, get: any): TStore;
9
+ build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<TStore>, "persist"> & {
9
10
  persist: {
10
- setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CoreOrderStore<T>, {
11
+ setOptions: (options: Partial<import('zustand/middleware').PersistOptions<TStore, {
11
12
  orderDetails: CoreOrder<T>;
12
13
  }>>) => void;
13
14
  clearStorage: () => void;
14
15
  rehydrate: () => Promise<void> | void;
15
16
  hasHydrated: () => boolean;
16
- onHydrate: (fn: (state: CoreOrderStore<T>) => void) => () => void;
17
- onFinishHydration: (fn: (state: CoreOrderStore<T>) => void) => () => void;
18
- getOptions: () => Partial<import('zustand/middleware').PersistOptions<CoreOrderStore<T>, {
17
+ onHydrate: (fn: (state: TStore) => void) => () => void;
18
+ onFinishHydration: (fn: (state: TStore) => void) => () => void;
19
+ getOptions: () => Partial<import('zustand/middleware').PersistOptions<TStore, {
19
20
  orderDetails: CoreOrder<T>;
20
21
  }>>;
21
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CoreOrderBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreOrder/classes/CoreOrderBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAiB,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D,qBAAa,gBAAgB,CAAC,CAAC,CAAE,YAAW,WAAW;IACrD,SAAS,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC7C,SAAS,CAAC,YAAY,EAKjB,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;gBAG5E,YAAY,GAAE,oBAAiD,EAC/D,YAAY,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAQpC,KAAK;;;;;;;;;;;;;;;CAmHb"}
1
+ {"version":3,"file":"CoreOrderBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreOrder/classes/CoreOrderBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAiB,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,qBAAa,gBAAgB,CAAC,CAAC,EAAE,MAAM,SAAS,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,MAAM,CAAC;IACpH,SAAS,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC7C,SAAS,CAAC,YAAY,EAKjB,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;gBAGjE,YAAY,GAAE,oBAAiD,EAC/D,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC;IAShC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM;IA0G3C,KAAK;;;;;;;;;;;;;;;CAcb"}
@@ -1,8 +1,9 @@
1
1
  import { create } from 'zustand';
2
2
  import { persist } from '../../../node_modules/zustand/esm/middleware.js';
3
3
  import { CoreOrderBaseService } from '../services/base.js';
4
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
4
5
 
5
- class CoreOrderBuilder {
6
+ class CoreOrderBuilder extends CoreBaseBuilder {
6
7
  orderService;
7
8
  initialState = {
8
9
  orderDetails: {},
@@ -11,105 +12,110 @@ class CoreOrderBuilder {
11
12
  error: null
12
13
  };
13
14
  constructor(orderService = new CoreOrderBaseService(), initialState) {
15
+ super();
14
16
  this.orderService = orderService;
15
17
  if (initialState) {
16
18
  this.initialState = { ...this.initialState, ...initialState };
17
19
  }
18
20
  }
21
+ getBaseState(set, get) {
22
+ return {
23
+ ...this.initialState,
24
+ // Setters
25
+ setLoading: (loading) => set({ loading }),
26
+ setError: (error) => set({ error }),
27
+ // Getters
28
+ getOrderDetails: () => get().orderDetails,
29
+ // Actions
30
+ createOrder: async (orderData, actions) => {
31
+ const { onSuccess = () => {
32
+ }, onError = () => {
33
+ }, onFinish = () => {
34
+ } } = actions || {};
35
+ try {
36
+ set({ loading: true, error: null });
37
+ const response = await this.orderService.createOrder(orderData);
38
+ const orderDetails = response.data.data.order;
39
+ set({
40
+ orderDetails,
41
+ loading: false
42
+ });
43
+ onSuccess(response);
44
+ return response.data;
45
+ } catch (error) {
46
+ set({ loading: false, error });
47
+ onError(error);
48
+ throw error;
49
+ } finally {
50
+ onFinish();
51
+ }
52
+ },
53
+ fetchOrderDetails: async (orderId, actions) => {
54
+ const { onSuccess = () => {
55
+ }, onError = () => {
56
+ }, onFinish = () => {
57
+ } } = actions || {};
58
+ try {
59
+ set({ loading: true, error: null });
60
+ const response = await this.orderService.fetchOrderById(orderId);
61
+ const orderDetails = response.data.data;
62
+ set({
63
+ orderDetails,
64
+ loading: false
65
+ });
66
+ onSuccess(response);
67
+ return response.data;
68
+ } catch (error) {
69
+ set({ loading: false, error });
70
+ onError(error);
71
+ throw error;
72
+ } finally {
73
+ onFinish();
74
+ }
75
+ },
76
+ fetchOrders: async (params, actions) => {
77
+ const { onSuccess = () => {
78
+ }, onError = () => {
79
+ }, onFinish = () => {
80
+ } } = actions || {};
81
+ const { onlyFetch, ...queryParams } = params || {};
82
+ try {
83
+ if (!onlyFetch) {
84
+ set({ loading: true, error: null });
85
+ }
86
+ const response = await this.orderService.fetchOrders(queryParams);
87
+ const orders = response.data.data;
88
+ if (!onlyFetch) {
89
+ set({
90
+ orders,
91
+ loading: false
92
+ });
93
+ }
94
+ onSuccess(response);
95
+ return response.data;
96
+ } catch (error) {
97
+ if (!onlyFetch) {
98
+ set({ loading: false, error });
99
+ }
100
+ onError(error);
101
+ throw error;
102
+ } finally {
103
+ onFinish();
104
+ }
105
+ },
106
+ // Reset
107
+ reset: () => set({ ...this.initialState, ...this.extendInitialState() })
108
+ };
109
+ }
19
110
  build() {
20
111
  return create()(
21
112
  persist(
22
- (set, get) => ({
23
- ...this.initialState,
24
- // Setters
25
- setLoading: (loading) => set({ loading }),
26
- setError: (error) => set({ error }),
27
- // Getters
28
- getOrderDetails: () => get().orderDetails,
29
- // Actions
30
- createOrder: async (orderData, actions) => {
31
- const { onSuccess = () => {
32
- }, onError = () => {
33
- }, onFinish = () => {
34
- } } = actions || {};
35
- try {
36
- set({ loading: true, error: null });
37
- const response = await this.orderService.createOrder(orderData);
38
- const orderDetails = response.data.data.order;
39
- set({
40
- orderDetails,
41
- loading: false
42
- });
43
- onSuccess(response);
44
- return response.data;
45
- } catch (error) {
46
- set({ loading: false, error });
47
- onError(error);
48
- throw error;
49
- } finally {
50
- onFinish();
51
- }
52
- },
53
- fetchOrderDetails: async (orderId, actions) => {
54
- const { onSuccess = () => {
55
- }, onError = () => {
56
- }, onFinish = () => {
57
- } } = actions || {};
58
- try {
59
- set({ loading: true, error: null });
60
- const response = await this.orderService.fetchOrderById(orderId);
61
- const orderDetails = response.data.data;
62
- set({
63
- orderDetails,
64
- loading: false
65
- });
66
- onSuccess(response);
67
- return response.data;
68
- } catch (error) {
69
- set({ loading: false, error });
70
- onError(error);
71
- throw error;
72
- } finally {
73
- onFinish();
74
- }
75
- },
76
- fetchOrders: async (params, actions) => {
77
- const { onSuccess = () => {
78
- }, onError = () => {
79
- }, onFinish = () => {
80
- } } = actions || {};
81
- const { onlyFetch, ...queryParams } = params || {};
82
- try {
83
- if (!onlyFetch) {
84
- set({ loading: true, error: null });
85
- }
86
- const response = await this.orderService.fetchOrders(queryParams);
87
- const orders = response.data.data;
88
- if (!onlyFetch) {
89
- set({
90
- orders,
91
- loading: false
92
- });
93
- }
94
- onSuccess(response);
95
- return response.data;
96
- } catch (error) {
97
- if (!onlyFetch) {
98
- set({ loading: false, error });
99
- }
100
- onError(error);
101
- throw error;
102
- } finally {
103
- onFinish();
104
- }
105
- },
106
- // Reset
107
- reset: () => set(this.initialState)
108
- }),
113
+ (set, get) => this.buildStoreState(set, get),
109
114
  {
110
115
  name: "order-storage",
111
116
  partialize: (state) => ({
112
- orderDetails: state.orderDetails
117
+ orderDetails: state.orderDetails,
118
+ ...this.extendPartialize(state)
113
119
  })
114
120
  }
115
121
  )
@@ -1,21 +1,22 @@
1
1
  import { CorePayFormBaseService } from '../services/base';
2
2
  import { CorePayForm, CorePayFormStore } from '../types/CorePayForm';
3
- import { CoreBuilder } from '../../../classes/CoreBuilder';
4
- export declare class CorePayFormBuilder<T extends CorePayForm = CorePayForm> implements CoreBuilder {
3
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
4
+ export declare class CorePayFormBuilder<T extends CorePayForm = CorePayForm, TStore extends CorePayFormStore<T> = CorePayFormStore<T>> extends CoreBaseBuilder<TStore> {
5
5
  protected payFormService: CorePayFormBaseService;
6
- protected initialState: Pick<CorePayFormStore<T>, "payForms" | "loading" | "error">;
7
- constructor(service?: CorePayFormBaseService, initialState?: Partial<CorePayFormStore<T>>);
8
- build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CorePayFormStore<T>>, "persist"> & {
6
+ protected initialState: Pick<TStore, "payForms" | "loading" | "error">;
7
+ constructor(service?: CorePayFormBaseService, initialState?: Partial<TStore>);
8
+ protected getBaseState(set: any, get: any): TStore;
9
+ build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<TStore>, "persist"> & {
9
10
  persist: {
10
- setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CorePayFormStore<T>, {
11
+ setOptions: (options: Partial<import('zustand/middleware').PersistOptions<TStore, {
11
12
  payForms: T[];
12
13
  }>>) => void;
13
14
  clearStorage: () => void;
14
15
  rehydrate: () => Promise<void> | void;
15
16
  hasHydrated: () => boolean;
16
- onHydrate: (fn: (state: CorePayFormStore<T>) => void) => () => void;
17
- onFinishHydration: (fn: (state: CorePayFormStore<T>) => void) => () => void;
18
- getOptions: () => Partial<import('zustand/middleware').PersistOptions<CorePayFormStore<T>, {
17
+ onHydrate: (fn: (state: TStore) => void) => () => void;
18
+ onFinishHydration: (fn: (state: TStore) => void) => () => void;
19
+ getOptions: () => Partial<import('zustand/middleware').PersistOptions<TStore, {
19
20
  payForms: T[];
20
21
  }>>;
21
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CorePayFormBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CorePayForm/classes/CorePayFormBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EA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;;;;;;CAcb"}
@@ -1,8 +1,9 @@
1
1
  import { create } from 'zustand';
2
2
  import { persist } from '../../../node_modules/zustand/esm/middleware.js';
3
3
  import { CorePayFormBaseService } from '../services/base.js';
4
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder.js';
4
5
 
5
- class CorePayFormBuilder {
6
+ class CorePayFormBuilder extends CoreBaseBuilder {
6
7
  payFormService;
7
8
  initialState = {
8
9
  payForms: null,
@@ -10,60 +11,65 @@ class CorePayFormBuilder {
10
11
  error: null
11
12
  };
12
13
  constructor(service = new CorePayFormBaseService(), initialState) {
14
+ super();
13
15
  this.payFormService = service;
14
16
  if (initialState) {
15
17
  this.initialState = { ...this.initialState, ...initialState };
16
18
  }
17
19
  }
20
+ getBaseState(set, get) {
21
+ return {
22
+ ...this.initialState,
23
+ // Setters
24
+ setLoading: (loading) => set({ loading }),
25
+ setError: (error) => set({ error }),
26
+ setPayForms: (payForms) => set({ payForms }),
27
+ // Getters
28
+ getPayForms: () => get().payForms,
29
+ // Actions
30
+ fetchPayForms: async (params, actions) => {
31
+ const { onSuccess = () => {
32
+ }, onError = () => {
33
+ }, onFinish = () => {
34
+ } } = actions || {};
35
+ const { onlyFetch, ...queryParams } = params || {};
36
+ try {
37
+ if (!onlyFetch) {
38
+ set({ loading: true, error: null });
39
+ }
40
+ const response = await this.payFormService.fetchPayForms(queryParams);
41
+ const payForms = response.data.data;
42
+ if (!onlyFetch) {
43
+ set({
44
+ payForms,
45
+ loading: false
46
+ });
47
+ }
48
+ onSuccess(response);
49
+ return payForms;
50
+ } catch (error) {
51
+ if (!onlyFetch) {
52
+ set({ loading: false, error });
53
+ }
54
+ onError(error);
55
+ throw error;
56
+ } finally {
57
+ onFinish();
58
+ }
59
+ },
60
+ // Reset
61
+ reset: () => set({ ...this.initialState, ...this.extendInitialState() })
62
+ };
63
+ }
18
64
  build() {
19
65
  return create()(
20
66
  persist(
21
- (set, get) => ({
22
- ...this.initialState,
23
- // Setters
24
- setLoading: (loading) => set({ loading }),
25
- setError: (error) => set({ error }),
26
- setPayForms: (payForms) => set({ payForms }),
27
- // Getters
28
- getPayForms: () => get().payForms,
29
- // Actions
30
- fetchPayForms: async (params, actions) => {
31
- const { onSuccess = () => {
32
- }, onError = () => {
33
- }, onFinish = () => {
34
- } } = actions || {};
35
- const { onlyFetch, ...queryParams } = params || {};
36
- try {
37
- if (!onlyFetch) {
38
- set({ loading: true, error: null });
39
- }
40
- const response = await this.payFormService.fetchPayForms(queryParams);
41
- const payForms = response.data.data;
42
- if (!onlyFetch) {
43
- set({
44
- payForms,
45
- loading: false
46
- });
47
- }
48
- onSuccess(response);
49
- return payForms;
50
- } catch (error) {
51
- if (!onlyFetch) {
52
- set({ loading: false, error });
53
- }
54
- onError(error);
55
- throw error;
56
- } finally {
57
- onFinish();
58
- }
59
- },
60
- // Reset
61
- reset: () => set(this.initialState)
62
- }),
67
+ (set, get) => this.buildStoreState(set, get),
63
68
  {
64
69
  name: "payform-storage",
65
70
  partialize: (state) => ({
66
- payForms: state.payForms
71
+ payForms: state.payForms,
72
+ ...this.extendPartialize(state)
67
73
  })
68
74
  }
69
75
  )
@@ -1,14 +1,15 @@
1
1
  import { CoreProductBaseService } from '../services/base';
2
2
  import { CoreProduct, CoreProductStore } from '../types/CoreProduct';
3
3
  import { CoreProductCategory } from '../types/CoreProductCategory';
4
- import { CoreBuilder } from '../../../classes/CoreBuilder';
5
- export declare class CoreProductBuilder<T extends CoreProduct = CoreProduct, K extends CoreProductCategory = CoreProductCategory> implements CoreBuilder {
4
+ import { CoreBaseBuilder } from '../../../classes/CoreBaseBuilder';
5
+ export declare class CoreProductBuilder<T extends CoreProduct = CoreProduct, K extends CoreProductCategory = CoreProductCategory, TStore extends CoreProductStore<T, K> = CoreProductStore<T, K>> extends CoreBaseBuilder<TStore> {
6
6
  protected productService: CoreProductBaseService;
7
- protected initialState: Pick<CoreProductStore<T, K>, "productDetails" | "products" | "categories" | "bestSellers" | "loading" | "error">;
8
- constructor(service?: CoreProductBaseService, initialState?: Partial<CoreProductStore<T, K>>);
9
- build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<CoreProductStore<T, K>>, "persist"> & {
7
+ protected initialState: Pick<TStore, "productDetails" | "products" | "categories" | "bestSellers" | "loading" | "error">;
8
+ constructor(service?: CoreProductBaseService, initialState?: Partial<TStore>);
9
+ protected getBaseState(set: any, get: any): TStore;
10
+ build(): import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<TStore>, "persist"> & {
10
11
  persist: {
11
- setOptions: (options: Partial<import('zustand/middleware').PersistOptions<CoreProductStore<T, K>, {
12
+ setOptions: (options: Partial<import('zustand/middleware').PersistOptions<TStore, {
12
13
  productDetails: T;
13
14
  products: import('../../../types').BasePagination<T>;
14
15
  categories: K[];
@@ -17,9 +18,9 @@ export declare class CoreProductBuilder<T extends CoreProduct = CoreProduct, K e
17
18
  clearStorage: () => void;
18
19
  rehydrate: () => Promise<void> | void;
19
20
  hasHydrated: () => boolean;
20
- onHydrate: (fn: (state: CoreProductStore<T, K>) => void) => () => void;
21
- onFinishHydration: (fn: (state: CoreProductStore<T, K>) => void) => () => void;
22
- getOptions: () => Partial<import('zustand/middleware').PersistOptions<CoreProductStore<T, K>, {
21
+ onHydrate: (fn: (state: TStore) => void) => () => void;
22
+ onFinishHydration: (fn: (state: TStore) => void) => () => void;
23
+ getOptions: () => Partial<import('zustand/middleware').PersistOptions<TStore, {
23
24
  productDetails: T;
24
25
  products: import('../../../types').BasePagination<T>;
25
26
  categories: K[];
@@ -1 +1 @@
1
- {"version":3,"file":"CoreProductBuilder.d.ts","sourceRoot":"","sources":["../../../../src/modules/CoreProduct/classes/CoreProductBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BA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