@react-pakistan/util-functions 1.25.48 → 1.25.50

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 (62) hide show
  1. package/api/stellar-solutions/app-user/index.d.ts +1 -1
  2. package/api/stellar-solutions/bank/index.d.ts +1 -1
  3. package/api/stellar-solutions/branch/index.d.ts +1 -1
  4. package/api/stellar-solutions/company/index.d.ts +1 -1
  5. package/api/stellar-solutions/company-report/index.d.ts +1 -1
  6. package/api/stellar-solutions/contact/index.d.ts +1 -1
  7. package/api/stellar-solutions/currency/index.d.ts +1 -1
  8. package/api/stellar-solutions/customer/index.d.ts +1 -1
  9. package/api/stellar-solutions/expense/index.d.ts +1 -1
  10. package/api/stellar-solutions/expense-category/index.d.ts +1 -1
  11. package/api/stellar-solutions/lead/index.d.ts +1 -1
  12. package/api/stellar-solutions/menu-order/index.d.ts +1 -1
  13. package/api/stellar-solutions/payment/index.d.ts +1 -1
  14. package/api/stellar-solutions/payment/index.js +2 -2
  15. package/api/stellar-solutions/payment-mode/index.d.ts +1 -1
  16. package/api/stellar-solutions/preference/index.d.ts +1 -1
  17. package/api/stellar-solutions/product/index.d.ts +1 -1
  18. package/api/stellar-solutions/product-category/index.d.ts +1 -1
  19. package/api/stellar-solutions/profile/index.d.ts +1 -1
  20. package/api/stellar-solutions/quote-invoice/index.d.ts +1 -1
  21. package/api/stellar-solutions/quote-invoice-report/index.d.ts +1 -1
  22. package/api/stellar-solutions/tax/index.d.ts +1 -1
  23. package/api/stellar-solutions/types/common.d.ts +24 -0
  24. package/api/stellar-solutions/types/common.js +22 -0
  25. package/api/stellar-solutions/{type.d.ts → types/erp.d.ts} +1 -199
  26. package/api/stellar-solutions/types/erp.js +68 -0
  27. package/api/stellar-solutions/types/index.d.ts +3 -0
  28. package/api/stellar-solutions/types/index.js +19 -0
  29. package/api/stellar-solutions/types/pos.d.ts +176 -0
  30. package/api/stellar-solutions/types/pos.js +61 -0
  31. package/general/index.d.ts +0 -1
  32. package/general/index.js +0 -1
  33. package/index.d.ts +1 -1
  34. package/index.js +1 -1
  35. package/package.json +1 -1
  36. package/api/stellar-solutions/bank/cache.d.ts +0 -0
  37. package/api/stellar-solutions/bank/cache.js +0 -237
  38. package/api/stellar-solutions/branch/cache.d.ts +0 -0
  39. package/api/stellar-solutions/branch/cache.js +0 -241
  40. package/api/stellar-solutions/company/cache.d.ts +0 -0
  41. package/api/stellar-solutions/company/cache.js +0 -247
  42. package/api/stellar-solutions/contact/cache.d.ts +0 -0
  43. package/api/stellar-solutions/contact/cache.js +0 -247
  44. package/api/stellar-solutions/currency/cache.d.ts +0 -0
  45. package/api/stellar-solutions/currency/cache.js +0 -243
  46. package/api/stellar-solutions/customer/cache.d.ts +0 -0
  47. package/api/stellar-solutions/customer/cache.js +0 -249
  48. package/api/stellar-solutions/expense/cache.d.ts +0 -0
  49. package/api/stellar-solutions/expense/cache.js +0 -247
  50. package/api/stellar-solutions/expense-category/cache.d.ts +0 -0
  51. package/api/stellar-solutions/expense-category/cache.js +0 -224
  52. package/api/stellar-solutions/payment-mode/cache.d.ts +0 -0
  53. package/api/stellar-solutions/payment-mode/cache.js +0 -245
  54. package/api/stellar-solutions/preference/cache.d.ts +0 -0
  55. package/api/stellar-solutions/preference/cache.js +0 -218
  56. package/api/stellar-solutions/product/cache.d.ts +0 -0
  57. package/api/stellar-solutions/product/cache.js +0 -222
  58. package/api/stellar-solutions/product-category/cache.d.ts +0 -0
  59. package/api/stellar-solutions/product-category/cache.js +0 -224
  60. package/api/stellar-solutions/tax/cache.d.ts +0 -0
  61. package/api/stellar-solutions/tax/cache.js +0 -235
  62. package/api/stellar-solutions/type.js +0 -142
@@ -1,241 +0,0 @@
1
- // import { API_ROUTES } from '../constants';
2
- // import { BranchBE, LS_KEYS } from '../type';
3
- // import { API_METHODS } from '../../../constants/api-methods';
4
- // import { fetchData } from '../../../general/fetch-data';
5
- // import { getStorageValue } from '../../../local-storage/get-storage-value';
6
- // import { setStorageValue } from '../../../local-storage/set-storage-value';
7
- // import { ONE_WEEK_IN_MS } from '../../../constants';
8
- // interface CachedBranches {
9
- // branches: BranchBE[];
10
- // cachedAt: string;
11
- // }
12
- // /**
13
- // * Synchronous utility function to get branches from cache only
14
- // * Returns cached data immediately if available and fresh, otherwise returns empty array
15
- // * Does not trigger any API calls
16
- // *
17
- // * @returns BranchBE[] - Array of cached branches or empty array wrapper ({count, items})
18
- // *
19
- // * @example
20
- // * const branches = getCachedBranchesSync();
21
- // * if (branches.items.length > 0) {
22
- // * console.log(branches.items[0].branchName);
23
- // * }
24
- // */
25
- // export const getCachedBranchesSync = (): {
26
- // count: number;
27
- // items: BranchBE[];
28
- // } => {
29
- // try {
30
- // const cachedData = getStorageValue(
31
- // LS_KEYS.BRANCHES
32
- // ) as CachedBranches | null;
33
- // if (!cachedData) {
34
- // return { count: 0, items: [] };
35
- // }
36
- // const currentTime = new Date().getTime();
37
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
38
- // const ageInMs = currentTime - cachedTime;
39
- // // If cached data is less than 1 week old, return it
40
- // if (ageInMs < ONE_WEEK_IN_MS) {
41
- // return {
42
- // count: cachedData.branches.length,
43
- // items: cachedData.branches,
44
- // };
45
- // }
46
- // return { count: 0, items: [] };
47
- // } catch (error) {
48
- // console.error('Error getting cached branches:', error);
49
- // return { count: 0, items: [] };
50
- // }
51
- // };
52
- // /**
53
- // * Utility function to get branches from cache or fetch from API
54
- // *
55
- // * This function manages a localStorage cache of branches with the following logic:
56
- // * - If branches exist in cache and are less than 1 week old, return cached version
57
- // * - If branches exist but are older than 1 week, fetch fresh data and update cache
58
- // * - If branches don't exist in cache, fetch from API and cache them
59
- // *
60
- // * @param searchQuery - Optional search query to filter branches
61
- // * @param pageLimit - Number of branches to fetch (default: 100)
62
- // * @returns Promise<{count:number, items: BranchBE[]}> - Paged branches
63
- // *
64
- // * @example
65
- // * const branches = await getCachedBranches();
66
- // * console.log(branches.items[0].branchName);
67
- // *
68
- // * // With search
69
- // * const filtered = await getCachedBranches('Main Branch');
70
- // */
71
- // export const getCachedBranches = async (
72
- // searchQuery?: string,
73
- // pageLimit: number = 100
74
- // ): Promise<{
75
- // count: number;
76
- // items: BranchBE[];
77
- // }> => {
78
- // try {
79
- // // If there's a search query, always fetch fresh data (don't use cache)
80
- // if (searchQuery && searchQuery.trim()) {
81
- // const response = await fetchData({
82
- // url: API_ROUTES.BRANCHES,
83
- // body: JSON.stringify({
84
- // searchQuery,
85
- // pageLimit,
86
- // currentPage: 1,
87
- // }),
88
- // method: API_METHODS.POST,
89
- // });
90
- // return response?.data || { count: 0, items: [] };
91
- // }
92
- // // Get the cached data from localStorage
93
- // const cachedData = getStorageValue(
94
- // LS_KEYS.BRANCHES
95
- // ) as CachedBranches | null;
96
- // const currentTime = new Date().getTime();
97
- // // Check if cached data exists and is still fresh
98
- // if (cachedData) {
99
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
100
- // const ageInMs = currentTime - cachedTime;
101
- // // If cached data is less than 1 week old, return it
102
- // if (ageInMs < ONE_WEEK_IN_MS) {
103
- // return {
104
- // count: cachedData.branches.length,
105
- // items: cachedData.branches,
106
- // };
107
- // }
108
- // }
109
- // // If no cached data or data is older than 1 week, fetch fresh data
110
- // const response = await fetchData({
111
- // url: API_ROUTES.BRANCHES,
112
- // body: JSON.stringify({
113
- // pageLimit,
114
- // currentPage: 1,
115
- // }),
116
- // method: API_METHODS.POST,
117
- // });
118
- // if (response?.data?.items) {
119
- // // Update the cache with fresh data
120
- // const updatedCache: CachedBranches = {
121
- // branches: response.data.items,
122
- // cachedAt: new Date().toISOString(),
123
- // };
124
- // setStorageValue(LS_KEYS.BRANCHES, updatedCache);
125
- // return response.data;
126
- // }
127
- // return { count: 0, items: [] };
128
- // } catch (error) {
129
- // console.error('Error fetching branches:', error);
130
- // return { count: 0, items: [] };
131
- // }
132
- // };
133
- // /**
134
- // * Utility function to get a specific branch by ID from cache
135
- // * If not found in cache, returns null (does not trigger API call)
136
- // *
137
- // * @param branchId - The ID of the branch to retrieve
138
- // * @returns BranchBE | null - The branch or null if not found
139
- // *
140
- // * @example
141
- // * const branch = getCachedBranchById('branch-123');
142
- // * if (branch) {
143
- // * console.log(branch.branchName);
144
- // * }
145
- // */
146
- // export const getCachedBranchById = (branchId: string): BranchBE | null => {
147
- // if (!branchId) {
148
- // return null;
149
- // }
150
- // try {
151
- // const branches = getCachedBranchesSync().items;
152
- // return branches.find((branch) => branch.id === branchId) || null;
153
- // } catch (error) {
154
- // console.error('Error getting cached branch by ID:', error);
155
- // return null;
156
- // }
157
- // };
158
- // /**
159
- // * Utility function to get branches by name from cache
160
- // * If not found in cache, returns empty array (does not trigger API call)
161
- // *
162
- // * @param branchName - The name of the branch to search for
163
- // * @returns BranchBE[] - Array of matching branches or empty array
164
- // *
165
- // * @example
166
- // * const branches = getCachedBranchesByName('Main Branch');
167
- // * console.log(branches.length);
168
- // */
169
- // export const getCachedBranchesByName = (branchName: string): BranchBE[] => {
170
- // if (!branchName) {
171
- // return [];
172
- // }
173
- // try {
174
- // const branches = getCachedBranchesSync().items;
175
- // return branches.filter((branch) =>
176
- // branch.branchName.toLowerCase().includes(branchName.toLowerCase())
177
- // );
178
- // } catch (error) {
179
- // console.error('Error getting cached branches by name:', error);
180
- // return [];
181
- // }
182
- // };
183
- // /**
184
- // * Utility function to invalidate (remove) branches from cache
185
- // * Useful when branches have been updated and you want to force a refresh
186
- // *
187
- // * @example
188
- // * invalidateBranchesCache();
189
- // * const freshBranches = await getCachedBranches();
190
- // */
191
- // export const invalidateBranchesCache = (): void => {
192
- // try {
193
- // localStorage.removeItem(LS_KEYS.BRANCHES);
194
- // } catch (error) {
195
- // console.error('Error invalidating branches cache:', error);
196
- // }
197
- // };
198
- // /**
199
- // * Utility function to preload branches into cache
200
- // * Useful to call on app initialization or login
201
- // *
202
- // * @returns Promise<{count:number, items: BranchBE[]}> - Array of preloaded branches
203
- // *
204
- // * @example
205
- // * // On app initialization
206
- // * await preloadBranches();
207
- // */
208
- // export const preloadBranches = async (): Promise<{
209
- // count: number;
210
- // items: BranchBE[];
211
- // }> => {
212
- // return getCachedBranches();
213
- // };
214
- // /**
215
- // * Utility function to check if branches cache is stale
216
- // * Returns true if cache is older than 1 week or doesn't exist
217
- // *
218
- // * @returns boolean - True if cache is stale or doesn't exist
219
- // *
220
- // * @example
221
- // * if (isBranchesCacheStale()) {
222
- // * await getCachedBranches(); // This will fetch fresh data
223
- // * }
224
- // */
225
- // export const isBranchesCacheStale = (): boolean => {
226
- // try {
227
- // const cachedData = getStorageValue(
228
- // LS_KEYS.BRANCHES
229
- // ) as CachedBranches | null;
230
- // if (!cachedData) {
231
- // return true;
232
- // }
233
- // const currentTime = new Date().getTime();
234
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
235
- // const ageInMs = currentTime - cachedTime;
236
- // return ageInMs >= ONE_WEEK_IN_MS;
237
- // } catch (error) {
238
- // console.error('Error checking branches cache staleness:', error);
239
- // return true;
240
- // }
241
- // };
File without changes
@@ -1,247 +0,0 @@
1
- // import { API_ROUTES } from '../constants';
2
- // import { CompanyBE, LS_KEYS } from '../type';
3
- // import { API_METHODS } from '../../../constants/api-methods';
4
- // import { fetchData } from '../../../general/fetch-data';
5
- // import { getStorageValue } from '../../../local-storage/get-storage-value';
6
- // import { setStorageValue } from '../../../local-storage/set-storage-value';
7
- // import { ONE_DAY_IN_MS } from '../../../constants';
8
- // interface CachedCompanies {
9
- // companies: CompanyBE[];
10
- // cachedAt: string;
11
- // }
12
- // /**
13
- // * Synchronous utility function to get companies from cache only
14
- // * Returns cached data immediately if available and fresh, otherwise returns empty array
15
- // * Does not trigger any API calls
16
- // *
17
- // * @returns CompanyBE[] - Array of cached companies or empty array wrapper ({count, items})
18
- // *
19
- // * @example
20
- // * const companies = getCachedCompaniesSync();
21
- // * if (companies.items.length > 0) {
22
- // * console.log(companies.items[0].name);
23
- // * }
24
- // */
25
- // export const getCachedCompaniesSync = (): {
26
- // count: number;
27
- // items: CompanyBE[];
28
- // } => {
29
- // try {
30
- // const cachedData = getStorageValue(
31
- // LS_KEYS.COMPANIES
32
- // ) as CachedCompanies | null;
33
- // if (!cachedData) {
34
- // return { count: 0, items: [] };
35
- // }
36
- // const currentTime = new Date().getTime();
37
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
38
- // const ageInMs = currentTime - cachedTime;
39
- // // If cached data is less than 1 day old, return it
40
- // if (ageInMs < ONE_DAY_IN_MS) {
41
- // return {
42
- // count: cachedData.companies.length,
43
- // items: cachedData.companies,
44
- // };
45
- // }
46
- // return { count: 0, items: [] };
47
- // } catch (error) {
48
- // console.error('Error getting cached companies:', error);
49
- // return { count: 0, items: [] };
50
- // }
51
- // };
52
- // /**
53
- // * Utility function to get companies from cache or fetch from API
54
- // *
55
- // * This function manages a localStorage cache of companies with the following logic:
56
- // * - If companies exist in cache and are less than 1 day old, return cached version
57
- // * - If companies exist but are older than 1 day, fetch fresh data and update cache
58
- // * - If companies don't exist in cache, fetch from API and cache them
59
- // *
60
- // * @param searchQuery - Optional search query to filter companies
61
- // * @param filters - Optional filters object to apply additional filtering (bypasses cache)
62
- // * @param pageLimit - Number of companies to fetch (default: 100)
63
- // * @returns Promise<{count:number, items: CompanyBE[]}> - Paged companies
64
- // *
65
- // * @example
66
- // * const companies = await getCachedCompanies();
67
- // * console.log(companies.items[0].name);
68
- // *
69
- // * // With search
70
- // * const filtered = await getCachedCompanies('Tech Corp');
71
- // *
72
- // * // With filters
73
- // * const filteredByCountry = await getCachedCompanies(undefined, { country: 'USA' });
74
- // */
75
- // export const getCachedCompanies = async (
76
- // searchQuery?: string,
77
- // filters?: Record<string, unknown>,
78
- // pageLimit: number = 100
79
- // ): Promise<{ count: number; items: CompanyBE[] }> => {
80
- // try {
81
- // // If there's a search query or filters, always fetch fresh data (don't use cache)
82
- // if (
83
- // (searchQuery && searchQuery.trim()) ||
84
- // (filters && Object.keys(filters).length > 0)
85
- // ) {
86
- // const response = await fetchData({
87
- // url: API_ROUTES.COMPANIES,
88
- // body: JSON.stringify({
89
- // searchQuery,
90
- // ...filters,
91
- // pageLimit,
92
- // currentPage: 1,
93
- // }),
94
- // method: API_METHODS.POST,
95
- // });
96
- // return response?.data || { count: 0, items: [] };
97
- // }
98
- // // Get the cached data from localStorage
99
- // const cachedData = getStorageValue(
100
- // LS_KEYS.COMPANIES
101
- // ) as CachedCompanies | null;
102
- // const currentTime = new Date().getTime();
103
- // // Check if cached data exists and is still fresh
104
- // if (cachedData) {
105
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
106
- // const ageInMs = currentTime - cachedTime;
107
- // // If cached data is less than 1 day old, return it
108
- // if (ageInMs < ONE_DAY_IN_MS) {
109
- // return {
110
- // count: cachedData.companies.length,
111
- // items: cachedData.companies,
112
- // };
113
- // }
114
- // }
115
- // // If no cached data or data is older than 1 day, fetch fresh data
116
- // const response = await fetchData({
117
- // url: API_ROUTES.COMPANIES,
118
- // body: JSON.stringify({
119
- // pageLimit,
120
- // currentPage: 1,
121
- // }),
122
- // method: API_METHODS.POST,
123
- // });
124
- // if (response?.data?.items) {
125
- // // Update the cache with fresh data
126
- // const updatedCache: CachedCompanies = {
127
- // companies: response.data.items,
128
- // cachedAt: new Date().toISOString(),
129
- // };
130
- // setStorageValue(LS_KEYS.COMPANIES, updatedCache);
131
- // return response.data;
132
- // }
133
- // return { count: 0, items: [] };
134
- // } catch (error) {
135
- // console.error('Error fetching companies:', error);
136
- // return { count: 0, items: [] };
137
- // }
138
- // };
139
- // /**
140
- // * Utility function to get a specific company by ID from cache
141
- // * If not found in cache, returns null (does not trigger API call)
142
- // *
143
- // * @param companyId - The ID of the company to retrieve
144
- // * @returns CompanyBE | null - The company or null if not found
145
- // *
146
- // * @example
147
- // * const company = getCachedCompanyById('company-123');
148
- // * if (company) {
149
- // * console.log(company.name);
150
- // * }
151
- // */
152
- // export const getCachedCompanyById = (companyId: string): CompanyBE | null => {
153
- // if (!companyId) {
154
- // return null;
155
- // }
156
- // try {
157
- // const companies = getCachedCompaniesSync().items;
158
- // return companies.find((company) => company.id === companyId) || null;
159
- // } catch (error) {
160
- // console.error('Error getting cached company by ID:', error);
161
- // return null;
162
- // }
163
- // };
164
- // /**
165
- // * Utility function to get companies by name from cache
166
- // * If not found in cache, returns empty array (does not trigger API call)
167
- // *
168
- // * @param name - The name of the company to search for
169
- // * @returns CompanyBE[] - Array of matching companies or empty array
170
- // *
171
- // * @example
172
- // * const companies = getCachedCompaniesByName('Tech');
173
- // * console.log(companies.length);
174
- // */
175
- // export const getCachedCompaniesByName = (name: string): CompanyBE[] => {
176
- // if (!name) {
177
- // return [];
178
- // }
179
- // try {
180
- // const companies = getCachedCompaniesSync().items;
181
- // return companies.filter((company) =>
182
- // company.name.toLowerCase().includes(name.toLowerCase())
183
- // );
184
- // } catch (error) {
185
- // console.error('Error getting cached companies by name:', error);
186
- // return [];
187
- // }
188
- // };
189
- // /**
190
- // * Utility function to invalidate (remove) companies from cache
191
- // * Useful when companies have been updated and you want to force a refresh
192
- // *
193
- // * @example
194
- // * invalidateCompaniesCache();
195
- // * const freshCompanies = await getCachedCompanies();
196
- // */
197
- // export const invalidateCompaniesCache = (): void => {
198
- // try {
199
- // localStorage.removeItem(LS_KEYS.COMPANIES);
200
- // } catch (error) {
201
- // console.error('Error invalidating companies cache:', error);
202
- // }
203
- // };
204
- // /**
205
- // * Utility function to preload companies into cache
206
- // * Useful to call on app initialization or login
207
- // *
208
- // * @returns Promise<{count:number, items: CompanyBE[]}> - Array of preloaded companies
209
- // *
210
- // * @example
211
- // * // On app initialization
212
- // * await preloadCompanies();
213
- // */
214
- // export const preloadCompanies = async (): Promise<{
215
- // count: number;
216
- // items: CompanyBE[];
217
- // }> => {
218
- // return getCachedCompanies();
219
- // };
220
- // /**
221
- // * Utility function to check if companies cache is stale
222
- // * Returns true if cache is older than 1 day or doesn't exist
223
- // *
224
- // * @returns boolean - True if cache is stale or doesn't exist
225
- // *
226
- // * @example
227
- // * if (isCompaniesCacheStale()) {
228
- // * await getCachedCompanies(); // This will fetch fresh data
229
- // * }
230
- // */
231
- // export const isCompaniesCacheStale = (): boolean => {
232
- // try {
233
- // const cachedData = getStorageValue(
234
- // LS_KEYS.COMPANIES
235
- // ) as CachedCompanies | null;
236
- // if (!cachedData) {
237
- // return true;
238
- // }
239
- // const currentTime = new Date().getTime();
240
- // const cachedTime = new Date(cachedData.cachedAt).getTime();
241
- // const ageInMs = currentTime - cachedTime;
242
- // return ageInMs >= ONE_DAY_IN_MS;
243
- // } catch (error) {
244
- // console.error('Error checking companies cache staleness:', error);
245
- // return true;
246
- // }
247
- // };
File without changes