@dashadmin/dash-utils 1.3.73 → 1.3.74-srcfree.2
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/components/LazyAppLoader.d.ts +17 -0
- package/dist/components/MinimalLayout.d.ts +6 -0
- package/dist/components/RouterComponent.d.ts +22 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/contexts/IPCMessageBrokerContext.d.ts +42 -0
- package/dist/hooks/useCapacitorAppStateRefresh.d.ts +2 -0
- package/dist/hooks/useCapacitorKeyboard.d.ts +19 -0
- package/dist/hooks/useDeviceStorageSync.d.ts +4 -0
- package/dist/hooks/useDraggable.d.ts +24 -0
- package/dist/hooks/useMenuStateInit.d.ts +10 -0
- package/dist/hooks/useMobileDetection.d.ts +20 -0
- package/dist/hooks/useNotifications.d.ts +51 -0
- package/dist/hooks/useQuickSearch.d.ts +6 -0
- package/dist/hooks/useWindowSize.d.ts +6 -0
- package/dist/index.d.ts +30 -0
- package/dist/utils/authProviderUtils.d.ts +37 -0
- package/dist/utils/dashBootstrapApp.d.ts +9 -0
- package/dist/utils/dashDtorage.d.ts +8 -0
- package/dist/utils/dashIPCService.d.ts +93 -0
- package/dist/utils/dataProviderUtils.d.ts +44 -0
- package/dist/utils/electronStoreSync.d.ts +3 -0
- package/dist/utils/envUtils.d.ts +1 -0
- package/dist/utils/environmentBodyClasses.d.ts +11 -0
- package/dist/utils/isDev.d.ts +5 -0
- package/dist/utils/notificationPermission.d.ts +5 -0
- package/dist/utils/platformDetection.d.ts +13 -0
- package/dist/utils/priceFormatter.d.ts +2 -0
- package/dist/utils/resourceLoader.d.ts +8 -0
- package/dist/utils/speechService.d.ts +7 -0
- package/dist/utils/storedTheme.d.ts +11 -0
- package/dist/utils/updateDomCssVariables.d.ts +6 -0
- package/dist/utils/validation.d.ts +12 -0
- package/package.json +13 -10
- package/src/components/LazyAppLoader.tsx +0 -143
- package/src/components/MinimalLayout.tsx +0 -22
- package/src/components/RouterComponent.tsx +0 -169
- package/src/components/index.ts +0 -16
- package/src/contexts/IPCMessageBrokerContext.tsx +0 -303
- package/src/hooks/useCapacitorAppStateRefresh.ts +0 -34
- package/src/hooks/useCapacitorKeyboard.ts +0 -213
- package/src/hooks/useDeviceStorageSync.ts +0 -70
- package/src/hooks/useDraggable.ts +0 -133
- package/src/hooks/useMenuStateInit.ts +0 -85
- package/src/hooks/useMobileDetection.ts +0 -165
- package/src/hooks/useNotifications.ts +0 -220
- package/src/hooks/useQuickSearch.ts +0 -42
- package/src/hooks/useWindowSize.tsx +0 -36
- package/src/index.ts +0 -202
- package/src/utils/authProviderUtils.ts +0 -170
- package/src/utils/dashBootstrapApp.ts +0 -104
- package/src/utils/dashDtorage.tsx +0 -51
- package/src/utils/dashDtorage.tsx.old +0 -78
- package/src/utils/dashIPCService.ts +0 -204
- package/src/utils/dataProviderUtils.ts +0 -221
- package/src/utils/electronStoreSync.ts +0 -34
- package/src/utils/envUtils.tsx +0 -27
- package/src/utils/environmentBodyClasses.ts +0 -72
- package/src/utils/isDev.ts +0 -65
- package/src/utils/notificationPermission.ts +0 -57
- package/src/utils/platformDetection.ts +0 -98
- package/src/utils/priceFormatter.ts +0 -36
- package/src/utils/resourceLoader.ts +0 -107
- package/src/utils/speechService.ts +0 -112
- package/src/utils/storedTheme.ts +0 -60
- package/src/utils/updateDomCssVariables.tsx +0 -181
- package/src/utils/validation.ts +0 -147
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a processed notification with standardized fields
|
|
5
|
-
*/
|
|
6
|
-
export interface ProcessedNotification {
|
|
7
|
-
id: string;
|
|
8
|
-
title: string;
|
|
9
|
-
message: string;
|
|
10
|
-
customer?: string;
|
|
11
|
-
store?: string;
|
|
12
|
-
timestamp: string;
|
|
13
|
-
isRead: boolean;
|
|
14
|
-
data?: any;
|
|
15
|
-
severity?: 'info' | 'warning' | 'error' | 'success';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Toast notification for snackbar display
|
|
20
|
-
*/
|
|
21
|
-
export interface ToastNotification {
|
|
22
|
-
id: string;
|
|
23
|
-
title: string;
|
|
24
|
-
message: string;
|
|
25
|
-
severity: 'info' | 'warning' | 'error' | 'success';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Dialog notification with position for draggable dialogs
|
|
30
|
-
*/
|
|
31
|
-
export interface DialogNotification extends ProcessedNotification {
|
|
32
|
-
position: { x: number; y: number };
|
|
33
|
-
zIndex: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Options for useNotifications hook
|
|
38
|
-
*/
|
|
39
|
-
export interface UseNotificationsOptions {
|
|
40
|
-
/** Maximum number of notifications to keep in history */
|
|
41
|
-
maxNotifications?: number;
|
|
42
|
-
/** Initial z-index for dialog notifications */
|
|
43
|
-
initialZIndex?: number;
|
|
44
|
-
/** Auto-dismiss toast notifications after ms (0 = no auto dismiss) */
|
|
45
|
-
toastAutoDismiss?: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Hook return type
|
|
50
|
-
*/
|
|
51
|
-
export interface UseNotificationsReturn {
|
|
52
|
-
notifications: ProcessedNotification[];
|
|
53
|
-
toastNotifications: ToastNotification[];
|
|
54
|
-
dialogNotifications: DialogNotification[];
|
|
55
|
-
unreadCount: number;
|
|
56
|
-
addNotification: (notification: Omit<ProcessedNotification, 'id' | 'timestamp' | 'isRead'>) => ProcessedNotification;
|
|
57
|
-
addToast: (toast: Omit<ToastNotification, 'id'>) => string;
|
|
58
|
-
addDialogNotification: (notification: Omit<ProcessedNotification, 'id' | 'timestamp' | 'isRead'>) => DialogNotification;
|
|
59
|
-
markAsRead: (notificationId: string) => void;
|
|
60
|
-
markAllAsRead: () => void;
|
|
61
|
-
removeNotification: (notificationId: string) => void;
|
|
62
|
-
clearAllNotifications: () => void;
|
|
63
|
-
removeToast: (toastId: string) => void;
|
|
64
|
-
removeDialogNotification: (notificationId: string) => void;
|
|
65
|
-
bringDialogToFront: (notificationId: string) => void;
|
|
66
|
-
updateDialogPosition: (notificationId: string, position: { x: number; y: number }) => void;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Generate a unique ID for notifications
|
|
71
|
-
*/
|
|
72
|
-
const generateId = (): string => `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Hook for managing notifications state
|
|
76
|
-
* Handles notifications list, toast notifications, and draggable dialog notifications
|
|
77
|
-
*/
|
|
78
|
-
export const useNotifications = (options: UseNotificationsOptions = {}): UseNotificationsReturn => {
|
|
79
|
-
const {
|
|
80
|
-
maxNotifications = 50,
|
|
81
|
-
initialZIndex = 100000,
|
|
82
|
-
toastAutoDismiss = 8000,
|
|
83
|
-
} = options;
|
|
84
|
-
|
|
85
|
-
const [notifications, setNotifications] = useState<ProcessedNotification[]>([]);
|
|
86
|
-
const [toastNotifications, setToastNotifications] = useState<ToastNotification[]>([]);
|
|
87
|
-
const [dialogNotifications, setDialogNotifications] = useState<DialogNotification[]>([]);
|
|
88
|
-
const [nextZIndex, setNextZIndex] = useState(initialZIndex);
|
|
89
|
-
|
|
90
|
-
const unreadCount = notifications.filter(n => !n.isRead).length;
|
|
91
|
-
|
|
92
|
-
// Add a new notification to the list
|
|
93
|
-
const addNotification = useCallback((
|
|
94
|
-
notification: Omit<ProcessedNotification, 'id' | 'timestamp' | 'isRead'>
|
|
95
|
-
): ProcessedNotification => {
|
|
96
|
-
const processedNotification: ProcessedNotification = {
|
|
97
|
-
...notification,
|
|
98
|
-
id: generateId(),
|
|
99
|
-
timestamp: new Date().toISOString(),
|
|
100
|
-
isRead: false,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
setNotifications(prev => [processedNotification, ...prev.slice(0, maxNotifications - 1)]);
|
|
104
|
-
return processedNotification;
|
|
105
|
-
}, [maxNotifications]);
|
|
106
|
-
|
|
107
|
-
// Add a toast notification
|
|
108
|
-
const addToast = useCallback((toast: Omit<ToastNotification, 'id'>): string => {
|
|
109
|
-
const id = `toast-${generateId()}`;
|
|
110
|
-
setToastNotifications(prev => [...prev, { ...toast, id }]);
|
|
111
|
-
return id;
|
|
112
|
-
}, []);
|
|
113
|
-
|
|
114
|
-
// Add a dialog notification with position
|
|
115
|
-
const addDialogNotification = useCallback((
|
|
116
|
-
notification: Omit<ProcessedNotification, 'id' | 'timestamp' | 'isRead'>
|
|
117
|
-
): DialogNotification => {
|
|
118
|
-
const processedNotification = addNotification(notification);
|
|
119
|
-
|
|
120
|
-
let dialogNotification: DialogNotification;
|
|
121
|
-
|
|
122
|
-
setDialogNotifications(prev => {
|
|
123
|
-
const dialogCount = prev.length;
|
|
124
|
-
const baseX = 20;
|
|
125
|
-
const baseY = typeof window !== 'undefined' ? window.innerHeight - 250 : 500;
|
|
126
|
-
const offsetY = dialogCount * -220;
|
|
127
|
-
|
|
128
|
-
dialogNotification = {
|
|
129
|
-
...processedNotification,
|
|
130
|
-
position: { x: baseX, y: baseY + offsetY },
|
|
131
|
-
zIndex: initialZIndex + dialogCount + 1,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
return [...prev, dialogNotification];
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
setNextZIndex(prev => prev + 1);
|
|
138
|
-
|
|
139
|
-
return dialogNotification!;
|
|
140
|
-
}, [addNotification, initialZIndex]);
|
|
141
|
-
|
|
142
|
-
// Mark a notification as read
|
|
143
|
-
const markAsRead = useCallback((notificationId: string) => {
|
|
144
|
-
setNotifications(prev =>
|
|
145
|
-
prev.map(n => n.id === notificationId ? { ...n, isRead: true } : n)
|
|
146
|
-
);
|
|
147
|
-
}, []);
|
|
148
|
-
|
|
149
|
-
// Mark all notifications as read
|
|
150
|
-
const markAllAsRead = useCallback(() => {
|
|
151
|
-
setNotifications(prev => prev.map(n => ({ ...n, isRead: true })));
|
|
152
|
-
}, []);
|
|
153
|
-
|
|
154
|
-
// Remove a notification
|
|
155
|
-
const removeNotification = useCallback((notificationId: string) => {
|
|
156
|
-
setNotifications(prev => prev.filter(n => n.id !== notificationId));
|
|
157
|
-
}, []);
|
|
158
|
-
|
|
159
|
-
// Clear all notifications
|
|
160
|
-
const clearAllNotifications = useCallback(() => {
|
|
161
|
-
setNotifications([]);
|
|
162
|
-
}, []);
|
|
163
|
-
|
|
164
|
-
// Remove a toast notification
|
|
165
|
-
const removeToast = useCallback((toastId: string) => {
|
|
166
|
-
setToastNotifications(prev => prev.filter(t => t.id !== toastId));
|
|
167
|
-
}, []);
|
|
168
|
-
|
|
169
|
-
// Remove a dialog notification
|
|
170
|
-
const removeDialogNotification = useCallback((notificationId: string) => {
|
|
171
|
-
setDialogNotifications(prev => prev.filter(d => d.id !== notificationId));
|
|
172
|
-
markAsRead(notificationId);
|
|
173
|
-
}, [markAsRead]);
|
|
174
|
-
|
|
175
|
-
// Bring a dialog to front
|
|
176
|
-
const bringDialogToFront = useCallback((notificationId: string) => {
|
|
177
|
-
setDialogNotifications(prev => {
|
|
178
|
-
const maxZ = Math.max(...prev.map(p => p.zIndex), initialZIndex);
|
|
179
|
-
return prev.map(d =>
|
|
180
|
-
d.id === notificationId
|
|
181
|
-
? { ...d, zIndex: maxZ + 1 }
|
|
182
|
-
: d
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
}, [initialZIndex]);
|
|
186
|
-
|
|
187
|
-
// Update dialog position
|
|
188
|
-
const updateDialogPosition = useCallback((
|
|
189
|
-
notificationId: string,
|
|
190
|
-
position: { x: number; y: number }
|
|
191
|
-
) => {
|
|
192
|
-
setDialogNotifications(prev =>
|
|
193
|
-
prev.map(d =>
|
|
194
|
-
d.id === notificationId
|
|
195
|
-
? { ...d, position }
|
|
196
|
-
: d
|
|
197
|
-
)
|
|
198
|
-
);
|
|
199
|
-
}, []);
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
notifications,
|
|
203
|
-
toastNotifications,
|
|
204
|
-
dialogNotifications,
|
|
205
|
-
unreadCount,
|
|
206
|
-
addNotification,
|
|
207
|
-
addToast,
|
|
208
|
-
addDialogNotification,
|
|
209
|
-
markAsRead,
|
|
210
|
-
markAllAsRead,
|
|
211
|
-
removeNotification,
|
|
212
|
-
clearAllNotifications,
|
|
213
|
-
removeToast,
|
|
214
|
-
removeDialogNotification,
|
|
215
|
-
bringDialogToFront,
|
|
216
|
-
updateDialogPosition,
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export default useNotifications;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface UseQuickSearchReturn {
|
|
4
|
-
quickSearchUseState: [string | null, React.Dispatch<React.SetStateAction<string | null>>];
|
|
5
|
-
sendQuickSearchEvent: (quickSearchString: string) => void;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Hook for managing quick search events across components
|
|
10
|
-
* Uses window events for cross-component communication
|
|
11
|
-
*/
|
|
12
|
-
export const useQuickSearch = (): UseQuickSearchReturn => {
|
|
13
|
-
const quickSearchUseState = useState<string | null>(null);
|
|
14
|
-
|
|
15
|
-
const sendQuickSearchEvent = (quickSearchString: string) => {
|
|
16
|
-
if (typeof window !== 'undefined') {
|
|
17
|
-
window.dispatchEvent(
|
|
18
|
-
new MessageEvent('quickSearch', { data: { value: quickSearchString } }),
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const eventHook = (e: MessageEvent) => {
|
|
24
|
-
quickSearchUseState[1](e.data?.value ?? null);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (typeof window !== 'undefined') {
|
|
29
|
-
window.addEventListener('quickSearch', eventHook as EventListener);
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener('quickSearch', eventHook as EventListener);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
quickSearchUseState,
|
|
38
|
-
sendQuickSearchEvent,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default useQuickSearch;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
interface IWindowSize {
|
|
4
|
-
width: number | undefined;
|
|
5
|
-
height: number | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const useWindowSize = (): IWindowSize => {
|
|
9
|
-
// Initialize state with undefined width/height so server and client renders match
|
|
10
|
-
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
|
11
|
-
const [windowSize, setWindowSize] = useState<IWindowSize>({
|
|
12
|
-
width: undefined,
|
|
13
|
-
height: undefined,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
// Handler to call on window resize
|
|
18
|
-
function handleResize() {
|
|
19
|
-
// Set window width/height to state
|
|
20
|
-
setWindowSize({
|
|
21
|
-
width: window.innerWidth,
|
|
22
|
-
height: window.innerHeight,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
// Add event listener
|
|
26
|
-
window.addEventListener('resize', handleResize);
|
|
27
|
-
// Call handler right away so state gets updated with initial window size
|
|
28
|
-
handleResize();
|
|
29
|
-
// Remove event listener on cleanup
|
|
30
|
-
return () => window.removeEventListener('resize', handleResize);
|
|
31
|
-
}, []); // Empty array ensures that effect is only run on mount
|
|
32
|
-
|
|
33
|
-
return windowSize;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//export default useWindowSize;
|
package/src/index.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// Hooks
|
|
2
|
-
export { useWindowSize } from './hooks/useWindowSize';
|
|
3
|
-
export { useCapacitorAppStateRefresh } from './hooks/useCapacitorAppStateRefresh';
|
|
4
|
-
export { useDeviceStorageSync } from './hooks/useDeviceStorageSync';
|
|
5
|
-
export {
|
|
6
|
-
useCapacitorKeyboard,
|
|
7
|
-
isCapacitorKeyboardAvailable,
|
|
8
|
-
getCapacitorKeyboard,
|
|
9
|
-
type KeyboardState,
|
|
10
|
-
type UseCapacitorKeyboardOptions
|
|
11
|
-
} from './hooks/useCapacitorKeyboard';
|
|
12
|
-
export {
|
|
13
|
-
useMobileDetection,
|
|
14
|
-
checkMobileDevice,
|
|
15
|
-
isWebView,
|
|
16
|
-
isAndroid,
|
|
17
|
-
isIOS,
|
|
18
|
-
isWindows,
|
|
19
|
-
isMacOS,
|
|
20
|
-
isLinux,
|
|
21
|
-
type MobileDetectionState,
|
|
22
|
-
type UseMobileDetectionOptions
|
|
23
|
-
} from './hooks/useMobileDetection';
|
|
24
|
-
export {
|
|
25
|
-
useDraggable,
|
|
26
|
-
type DraggablePosition,
|
|
27
|
-
type UseDraggableOptions,
|
|
28
|
-
type UseDraggableReturn
|
|
29
|
-
} from './hooks/useDraggable';
|
|
30
|
-
export {
|
|
31
|
-
useNotifications,
|
|
32
|
-
type ProcessedNotification,
|
|
33
|
-
type ToastNotification,
|
|
34
|
-
type DialogNotification,
|
|
35
|
-
type UseNotificationsOptions,
|
|
36
|
-
type UseNotificationsReturn
|
|
37
|
-
} from './hooks/useNotifications';
|
|
38
|
-
export {
|
|
39
|
-
useQuickSearch,
|
|
40
|
-
type UseQuickSearchReturn
|
|
41
|
-
} from './hooks/useQuickSearch';
|
|
42
|
-
export {
|
|
43
|
-
useMenuStateInit,
|
|
44
|
-
getInitialMenuState,
|
|
45
|
-
getInitialNavSize,
|
|
46
|
-
type UseMenuStateInitOptions
|
|
47
|
-
} from './hooks/useMenuStateInit';
|
|
48
|
-
|
|
49
|
-
// Utils
|
|
50
|
-
export { updateDomCssVariables } from './utils/updateDomCssVariables';
|
|
51
|
-
export { getEnv } from './utils/envUtils';
|
|
52
|
-
export { dashStorage } from './utils/dashDtorage';
|
|
53
|
-
export {
|
|
54
|
-
EMAIL_REGEX,
|
|
55
|
-
PHONE_REGEX,
|
|
56
|
-
URL_REGEX,
|
|
57
|
-
validateEmail,
|
|
58
|
-
validatePhone,
|
|
59
|
-
validateUrl,
|
|
60
|
-
validateRequired,
|
|
61
|
-
validateMinLength,
|
|
62
|
-
validateMaxLength,
|
|
63
|
-
validateRut,
|
|
64
|
-
checkPasswordStrength,
|
|
65
|
-
type PasswordStrength
|
|
66
|
-
} from './utils/validation';
|
|
67
|
-
|
|
68
|
-
// IPC Service for Electron
|
|
69
|
-
export {
|
|
70
|
-
isDashIPCServiceAvailable,
|
|
71
|
-
isElectron,
|
|
72
|
-
getDashIPCService,
|
|
73
|
-
windowControl,
|
|
74
|
-
startWindowDrag,
|
|
75
|
-
executeIPCAction,
|
|
76
|
-
onIPCStdout,
|
|
77
|
-
useDashIPCService,
|
|
78
|
-
type DashIPCServiceType
|
|
79
|
-
} from './utils/dashIPCService';
|
|
80
|
-
|
|
81
|
-
// Text-to-speech (platform-routed: native Android / Electron+Python / no-op web)
|
|
82
|
-
export { speak, speakAsync } from './utils/speechService';
|
|
83
|
-
|
|
84
|
-
// Stored Theme
|
|
85
|
-
export {
|
|
86
|
-
getStoredTheme,
|
|
87
|
-
setStoredTheme,
|
|
88
|
-
initializeStoredTheme,
|
|
89
|
-
clearStoredTheme
|
|
90
|
-
} from './utils/storedTheme';
|
|
91
|
-
|
|
92
|
-
// Development Environment Detection
|
|
93
|
-
export {
|
|
94
|
-
isDev,
|
|
95
|
-
isProd,
|
|
96
|
-
isTest,
|
|
97
|
-
getEnvironment
|
|
98
|
-
} from './utils/isDev';
|
|
99
|
-
|
|
100
|
-
// Environment Body Classes
|
|
101
|
-
export {
|
|
102
|
-
setupEnvironmentBodyClasses,
|
|
103
|
-
useEnvironmentBodyClasses,
|
|
104
|
-
type EnvironmentVars
|
|
105
|
-
} from './utils/environmentBodyClasses';
|
|
106
|
-
|
|
107
|
-
// Platform Detection
|
|
108
|
-
export {
|
|
109
|
-
isWebView as isWebViewPlatform,
|
|
110
|
-
isAndroid as isAndroidPlatform,
|
|
111
|
-
isIOS as isIOSPlatform,
|
|
112
|
-
isWindows as isWindowsPlatform,
|
|
113
|
-
applyPlatformBodyClasses
|
|
114
|
-
} from './utils/platformDetection';
|
|
115
|
-
|
|
116
|
-
// Electron Store Sync
|
|
117
|
-
export {
|
|
118
|
-
syncElectronStore,
|
|
119
|
-
hasElectronStore
|
|
120
|
-
} from './utils/electronStoreSync';
|
|
121
|
-
|
|
122
|
-
// Notification Permission
|
|
123
|
-
export {
|
|
124
|
-
requestNotificationPermission,
|
|
125
|
-
isNotificationSupported,
|
|
126
|
-
hasNotificationPermission,
|
|
127
|
-
isNotificationDenied,
|
|
128
|
-
getNotificationPermission
|
|
129
|
-
} from './utils/notificationPermission';
|
|
130
|
-
|
|
131
|
-
// Dash Bootstrap App
|
|
132
|
-
export {
|
|
133
|
-
dashInitializeApp,
|
|
134
|
-
dashBootstrapApp,
|
|
135
|
-
type DashInitializeAppConfig
|
|
136
|
-
} from './utils/dashBootstrapApp';
|
|
137
|
-
|
|
138
|
-
// Resource Loader
|
|
139
|
-
export {
|
|
140
|
-
createResourceLoader,
|
|
141
|
-
createSimpleResourceLoader
|
|
142
|
-
} from './utils/resourceLoader';
|
|
143
|
-
|
|
144
|
-
// Auth Provider Utils
|
|
145
|
-
export {
|
|
146
|
-
createLogoutFromStorage,
|
|
147
|
-
isUserAuthenticated,
|
|
148
|
-
getCurrentUser,
|
|
149
|
-
getAuthToken,
|
|
150
|
-
getTenantId,
|
|
151
|
-
getUserRoles,
|
|
152
|
-
setAuthData,
|
|
153
|
-
type LogoutConfig
|
|
154
|
-
} from './utils/authProviderUtils';
|
|
155
|
-
|
|
156
|
-
// Data Provider Utils
|
|
157
|
-
export {
|
|
158
|
-
getResourceConfigManager,
|
|
159
|
-
setResourceConfigs,
|
|
160
|
-
getResourceConfig,
|
|
161
|
-
processPostData,
|
|
162
|
-
processFormData,
|
|
163
|
-
buildQueryString,
|
|
164
|
-
isFormDataResource,
|
|
165
|
-
type IResourceConfig
|
|
166
|
-
} from './utils/dataProviderUtils';
|
|
167
|
-
|
|
168
|
-
// Components
|
|
169
|
-
export {
|
|
170
|
-
MinimalLayout,
|
|
171
|
-
type MinimalLayoutProps
|
|
172
|
-
} from './components/MinimalLayout';
|
|
173
|
-
|
|
174
|
-
export {
|
|
175
|
-
DashRouterComponent,
|
|
176
|
-
RouterComponent, // Backward compatibility alias
|
|
177
|
-
shouldUseHashRouter,
|
|
178
|
-
createRouterComponent,
|
|
179
|
-
type DashRouterComponentProps,
|
|
180
|
-
type RouterComponentProps // Backward compatibility alias
|
|
181
|
-
} from './components/RouterComponent';
|
|
182
|
-
|
|
183
|
-
// IPC Message Broker Context (Electron)
|
|
184
|
-
export {
|
|
185
|
-
IPCMessageBrokerContext,
|
|
186
|
-
IPCMessageBrokerProvider,
|
|
187
|
-
useIPCMessageBroker,
|
|
188
|
-
type LogMessage,
|
|
189
|
-
type SubprocessOutput,
|
|
190
|
-
type IPCMessageBrokerContextType,
|
|
191
|
-
type IPCMessageBrokerConfig
|
|
192
|
-
} from './contexts/IPCMessageBrokerContext';
|
|
193
|
-
|
|
194
|
-
// Lazy App Loader
|
|
195
|
-
export {
|
|
196
|
-
createLazyAppComponent,
|
|
197
|
-
createSimpleLazyApp,
|
|
198
|
-
DefaultLoadFailedComponent,
|
|
199
|
-
type LazyAppLoaderConfig
|
|
200
|
-
} from './components/LazyAppLoader';
|
|
201
|
-
|
|
202
|
-
export { priceFormatter } from "./utils/priceFormatter";
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Provider Utilities
|
|
3
|
-
*
|
|
4
|
-
* Helper functions for authentication operations.
|
|
5
|
-
* These utilities are used by auth providers across Dash applications.
|
|
6
|
-
*/
|
|
7
|
-
import { dashStorage } from './dashDtorage';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for logout function
|
|
11
|
-
*/
|
|
12
|
-
export interface LogoutConfig {
|
|
13
|
-
/** Function to clear auth persistence service */
|
|
14
|
-
clearAuthPersistence?: () => void;
|
|
15
|
-
/** Function to sync to device store (Electron/Capacitor) */
|
|
16
|
-
syncToDeviceStore?: () => Promise<void>;
|
|
17
|
-
/** Function to remove cookies */
|
|
18
|
-
removeCookies?: (names: string[]) => void;
|
|
19
|
-
/** Additional storage keys to clear */
|
|
20
|
-
additionalKeys?: string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Default storage keys to clear on logout
|
|
25
|
-
*/
|
|
26
|
-
const DEFAULT_AUTH_STORAGE_KEYS = [
|
|
27
|
-
'token',
|
|
28
|
-
'authenticated',
|
|
29
|
-
'user',
|
|
30
|
-
'roles',
|
|
31
|
-
'tenant_id',
|
|
32
|
-
'user_id'
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Default cookie names to clear on logout
|
|
37
|
-
*/
|
|
38
|
-
const DEFAULT_AUTH_COOKIE_NAMES = [
|
|
39
|
-
'token',
|
|
40
|
-
'tenant_id',
|
|
41
|
-
'user_id'
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Create a logout function with the given configuration
|
|
46
|
-
* This factory allows apps to customize the logout behavior
|
|
47
|
-
*/
|
|
48
|
-
export const createLogoutFromStorage = (config: LogoutConfig = {}) => {
|
|
49
|
-
return async (reason?: string): Promise<void> => {
|
|
50
|
-
console.log('🔓 logoutFromStorage called:', reason || 'no reason provided');
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
// Clear auth persistence service if provided
|
|
54
|
-
if (config.clearAuthPersistence) {
|
|
55
|
-
config.clearAuthPersistence();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Clear localStorage items
|
|
59
|
-
const keysToRemove = [...DEFAULT_AUTH_STORAGE_KEYS, ...(config.additionalKeys || [])];
|
|
60
|
-
keysToRemove.forEach(key => {
|
|
61
|
-
dashStorage.removeItem(key);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Clear cookies if removeCookies function is provided
|
|
65
|
-
if (config.removeCookies) {
|
|
66
|
-
config.removeCookies(DEFAULT_AUTH_COOKIE_NAMES);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Sync to device store (Electron/Capacitor) if provided
|
|
70
|
-
if (config.syncToDeviceStore) {
|
|
71
|
-
await config.syncToDeviceStore();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
console.log('✅ Auth data cleared successfully');
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error('❌ Error clearing auth data:', error);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Check if user is currently authenticated
|
|
83
|
-
* Based on localStorage values
|
|
84
|
-
*/
|
|
85
|
-
export const isUserAuthenticated = (): boolean => {
|
|
86
|
-
try {
|
|
87
|
-
const authenticated = JSON.parse(dashStorage.getItem('authenticated') || 'false');
|
|
88
|
-
const user = JSON.parse(dashStorage.getItem('user') || 'null');
|
|
89
|
-
return authenticated && user?.id;
|
|
90
|
-
} catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Get current user from storage
|
|
97
|
-
*/
|
|
98
|
-
export const getCurrentUser = <T = any>(): T | null => {
|
|
99
|
-
try {
|
|
100
|
-
return JSON.parse(dashStorage.getItem('user') || 'null');
|
|
101
|
-
} catch {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Get current token from storage
|
|
108
|
-
*/
|
|
109
|
-
export const getAuthToken = (): string | null => {
|
|
110
|
-
return dashStorage.getItem('token');
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get current tenant ID from storage
|
|
115
|
-
*/
|
|
116
|
-
export const getTenantId = (): string | null => {
|
|
117
|
-
return dashStorage.getItem('tenant_id');
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Get user roles from storage
|
|
122
|
-
*/
|
|
123
|
-
export const getUserRoles = <T = any>(): T[] => {
|
|
124
|
-
try {
|
|
125
|
-
return JSON.parse(dashStorage.getItem('roles') || '[]');
|
|
126
|
-
} catch {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Set authentication data in storage
|
|
133
|
-
*/
|
|
134
|
-
export const setAuthData = (data: {
|
|
135
|
-
token?: string;
|
|
136
|
-
user?: any;
|
|
137
|
-
roles?: any[];
|
|
138
|
-
authenticated?: boolean;
|
|
139
|
-
tenant_id?: string;
|
|
140
|
-
user_id?: string;
|
|
141
|
-
}): void => {
|
|
142
|
-
if (data.token !== undefined) {
|
|
143
|
-
dashStorage.setItem('token', data.token);
|
|
144
|
-
}
|
|
145
|
-
if (data.user !== undefined) {
|
|
146
|
-
dashStorage.setItem('user', JSON.stringify(data.user));
|
|
147
|
-
}
|
|
148
|
-
if (data.roles !== undefined) {
|
|
149
|
-
dashStorage.setItem('roles', JSON.stringify(data.roles));
|
|
150
|
-
}
|
|
151
|
-
if (data.authenticated !== undefined) {
|
|
152
|
-
dashStorage.setItem('authenticated', JSON.stringify(data.authenticated));
|
|
153
|
-
}
|
|
154
|
-
if (data.tenant_id !== undefined) {
|
|
155
|
-
dashStorage.setItem('tenant_id', data.tenant_id);
|
|
156
|
-
}
|
|
157
|
-
if (data.user_id !== undefined) {
|
|
158
|
-
dashStorage.setItem('user_id', data.user_id);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export default {
|
|
163
|
-
createLogoutFromStorage,
|
|
164
|
-
isUserAuthenticated,
|
|
165
|
-
getCurrentUser,
|
|
166
|
-
getAuthToken,
|
|
167
|
-
getTenantId,
|
|
168
|
-
getUserRoles,
|
|
169
|
-
setAuthData
|
|
170
|
-
};
|