@dashadmin/dash-auto-admin 1.3.24 → 1.3.26

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 (176) hide show
  1. package/dist/DashAutoAdminComponentRegistry.js +64 -1
  2. package/dist/DashAutoAdminForm.js +137 -1
  3. package/dist/DashAutoAdminResizableDrawer.js +63 -1
  4. package/dist/DashAutoAdminSaveButton.js +57 -1
  5. package/dist/DashAutoCreate.js +102 -1
  6. package/dist/DashAutoDrawer.js +256 -1
  7. package/dist/DashAutoEdit.js +99 -1
  8. package/dist/DashAutoFiltersGenerator.js +193 -1
  9. package/dist/DashAutoFormGroups.js +118 -1
  10. package/dist/DashAutoFormLayout.js +68 -1
  11. package/dist/DashAutoFormMuiTabs.js +291 -1
  12. package/dist/DashAutoFormTabs.js +132 -1
  13. package/dist/DashAutoGroup.js +27 -1
  14. package/dist/DashAutoLayout.js +31 -1
  15. package/dist/DashAutoList.js +218 -1
  16. package/dist/DashAutoPostFilterForm.js +47 -1
  17. package/dist/DashAutoReferenceTab.js +10 -1
  18. package/dist/DashAutoResource.js +77 -1
  19. package/dist/DashAutoResourceLayout.js +16 -1
  20. package/dist/DashAutoShow.js +195 -1
  21. package/dist/DashAutoTabbedForm.js +244 -1
  22. package/dist/DashAutoTabbedForm.review.js +221 -1
  23. package/dist/DashAutoTabs.js +11 -1
  24. package/dist/DashFilterWrapper.js +62 -1
  25. package/dist/DashRedirect.js +56 -1
  26. package/dist/TabbedLayout.js +38 -1
  27. package/dist/common/DashAutoTitle.js +33 -1
  28. package/dist/common/components/FabButton.js +59 -1
  29. package/dist/common/components/TranslatedLabel.js +60 -1
  30. package/dist/common/settings/Settings.js +196 -1
  31. package/dist/common/settings/SettingsBarIcons.js +61 -1
  32. package/dist/context/DashAutoAdminFormContext.js +15 -1
  33. package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
  34. package/dist/hooks/useAutoAdminTranslate.js +61 -1
  35. package/dist/hooks/useHash.js +24 -1
  36. package/dist/hooks/useLogger.js +20 -1
  37. package/dist/hooks/useRoutePathPattern.js +20 -1
  38. package/dist/hooks/useVirtualHash.js +28 -1
  39. package/dist/index.js +77 -3406
  40. package/dist/list/DashAutoListActions.js +57 -1
  41. package/dist/list/DashAutoListDatagridWrapper.js +68 -1
  42. package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
  43. package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
  44. package/dist/list/DashAutoListTopToolbar.js +180 -1
  45. package/dist/mui/AttributeToField.js +576 -1
  46. package/dist/mui/AttributeToInput.js +630 -1
  47. package/dist/mui/AutoAdminResizableDrawer.js +63 -1
  48. package/dist/mui/AutoDataGrid.js +120 -1
  49. package/dist/mui/AutoReferenceFormTab.js +53 -1
  50. package/dist/mui/AutoReferenceTab.js +46 -1
  51. package/dist/mui/AutoTabs.js +19 -1
  52. package/dist/mui/components/ExtendedPagination.js +34 -1
  53. package/dist/mui/components/ListStringField.js +25 -1
  54. package/dist/providers/DashAuthProvider.js +215 -1
  55. package/dist/providers/DashDataProvider.js +310 -1
  56. package/dist/providers/index.js +10 -1
  57. package/dist/react-admin.d.js +0 -0
  58. package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
  59. package/dist/toolbar/buttons/DashResourceButton.js +181 -1
  60. package/dist/toolbar/buttons/ListButtons.js +80 -1
  61. package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
  62. package/dist/types/ActionCallback.d.js +0 -0
  63. package/dist/utils/SimpleLogger.js +52 -1
  64. package/dist/utils/enumToChoices.js +5 -1
  65. package/dist/utils/evalActionPermission.js +11 -1
  66. package/dist/utils/groupByTabs.js +21 -1
  67. package/dist/utils/hashedGroupByTabs.js +12 -1
  68. package/dist/utils/invertMap.js +12 -1
  69. package/dist/utils/isClassComponent.js +7 -1
  70. package/dist/utils/isComponent.js +29 -1
  71. package/dist/utils/isEnum.js +5 -1
  72. package/dist/utils/isFC.js +8 -1
  73. package/dist/utils/replaceParams.js +9 -1
  74. package/dist/utils/validate.js +19 -1
  75. package/dist/wrappers/UserAction.js +60 -1
  76. package/dist/wrappers/index.js +4 -1
  77. package/package.json +135 -120
  78. package/src/DashAutoAdminComponentRegistry.tsx +75 -0
  79. package/src/DashAutoAdminForm.tsx +155 -0
  80. package/src/DashAutoAdminResizableDrawer.tsx +69 -0
  81. package/src/DashAutoAdminSaveButton.tsx +116 -0
  82. package/src/DashAutoCreate.tsx +118 -0
  83. package/src/DashAutoDrawer.tsx +288 -0
  84. package/src/DashAutoEdit.tsx +109 -0
  85. package/src/DashAutoFiltersGenerator.tsx +208 -0
  86. package/src/DashAutoFormGroups.tsx +146 -0
  87. package/src/DashAutoFormLayout.tsx.review +113 -0
  88. package/src/DashAutoFormMuiTabs.tsx +368 -0
  89. package/src/DashAutoFormTabs.tsx +177 -0
  90. package/src/DashAutoGroup.tsx +42 -0
  91. package/src/DashAutoLayout.tsx +57 -0
  92. package/src/DashAutoList.tsx +237 -0
  93. package/src/DashAutoPostFilterForm.tsx +35 -0
  94. package/src/DashAutoReferenceTab.tsx +9 -0
  95. package/src/DashAutoResource.tsx +85 -0
  96. package/src/DashAutoResourceLayout.tsx +50 -0
  97. package/src/DashAutoShow.tsx +200 -0
  98. package/src/DashAutoTabbedForm.review.tsx +262 -0
  99. package/src/DashAutoTabbedForm.tsx +324 -0
  100. package/src/DashAutoTabs.tsx +19 -0
  101. package/src/DashFilterWrapper.tsx +43 -0
  102. package/src/DashRedirect.tsx +46 -0
  103. package/src/TabbedLayout.tsx +29 -0
  104. package/src/common/DashAutoTitle.tsx +24 -0
  105. package/src/common/components/FabButton.tsx +40 -0
  106. package/src/common/components/TranslatedLabel.tsx +81 -0
  107. package/src/common/settings/Settings.tsx +236 -0
  108. package/src/common/settings/SettingsBarIcons.tsx +72 -0
  109. package/src/context/DashAutoAdminFormContext.tsx +31 -0
  110. package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
  111. package/src/hooks/useAutoAdminTranslate.tsx +106 -0
  112. package/src/hooks/useHash.tsx +27 -0
  113. package/src/hooks/useLogger.tsx +23 -0
  114. package/src/hooks/useRoutePathPattern.tsx +24 -0
  115. package/src/hooks/useVirtualHash.tsx +34 -0
  116. package/src/index.ts +85 -0
  117. package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
  118. package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
  119. package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
  120. package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
  121. package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
  122. package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
  123. package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
  124. package/src/interfaces/IDashAutoAdminReference.ts +16 -0
  125. package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
  126. package/src/interfaces/IDashAutoForm.ts +24 -0
  127. package/src/interfaces/IDashAutoGridButton.ts +35 -0
  128. package/src/interfaces/IDashAutoShow.ts +12 -0
  129. package/src/interfaces/IGroupExtraData.ts +8 -0
  130. package/src/interfaces/IRecord.ts +7 -0
  131. package/src/interfaces/IReferenceFilter.ts +55 -0
  132. package/src/interfaces/IResourceComponent.ts +8 -0
  133. package/src/interfaces/IToolbarButton.ts +11 -0
  134. package/src/list/DashAutoListActions.tsx +88 -0
  135. package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
  136. package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
  137. package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
  138. package/src/list/DashAutoListTopToolbar.tsx +240 -0
  139. package/src/mui/AttributeToField.tsx +657 -0
  140. package/src/mui/AttributeToInput.tsx +728 -0
  141. package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
  142. package/src/mui/AutoDataGrid.tsx +127 -0
  143. package/src/mui/AutoReferenceFormTab.tsx +51 -0
  144. package/src/mui/AutoReferenceTab.tsx +45 -0
  145. package/src/mui/AutoTabs.tsx +32 -0
  146. package/src/mui/components/ExtendedPagination.tsx +23 -0
  147. package/src/mui/components/ListStringField.tsx +32 -0
  148. package/src/providers/DashAuthProvider.ts +341 -0
  149. package/src/providers/DashDataProvider.ts +466 -0
  150. package/src/providers/index.ts +17 -0
  151. package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
  152. package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
  153. package/src/toolbar/buttons/ListButtons.tsx +137 -0
  154. package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
  155. package/src/utils/SimpleLogger.tsx +46 -0
  156. package/src/utils/enumToChoices.tsx +3 -0
  157. package/src/utils/evalActionPermission.tsx +14 -0
  158. package/src/utils/groupByTabs.tsx +23 -0
  159. package/src/utils/hashedGroupByTabs.tsx +16 -0
  160. package/src/utils/invertMap.tsx +10 -0
  161. package/src/utils/isClassComponent.tsx +9 -0
  162. package/src/utils/isComponent.tsx +45 -0
  163. package/src/utils/isEnum.tsx +3 -0
  164. package/src/utils/isFC.tsx +6 -0
  165. package/src/utils/replaceParams.tsx +6 -0
  166. package/src/utils/validate.tsx +24 -0
  167. package/src/wrappers/UserAction.tsx +67 -0
  168. package/src/wrappers/index.tsx +1 -0
  169. /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
  170. /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
  171. /package/{dist → src}/DashAutoFormTabs.review +0 -0
  172. /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
  173. /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
  174. /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
  175. /package/{dist → src}/react-admin.d.ts +0 -0
  176. /package/{dist → src}/types/ActionCallback.d.ts +0 -0
@@ -0,0 +1,341 @@
1
+ /**
2
+ * Dash Auth Provider
3
+ *
4
+ * Default authentication provider for Dash applications.
5
+ * This provider handles login, logout, identity, and auth checks.
6
+ *
7
+ * Can be extended or overridden by apps for custom behavior.
8
+ */
9
+ import type { AuthProvider } from 'react-admin';
10
+
11
+ // ============================================================================
12
+ // TYPES
13
+ // ============================================================================
14
+
15
+ export interface DashAuthProviderConfig {
16
+ /**
17
+ * Axios instance or hook to use for API calls
18
+ */
19
+ useAxios: () => any;
20
+
21
+ /**
22
+ * Storage utility (dashStorage from dash-utils)
23
+ */
24
+ storage: {
25
+ getItem: (key: string) => string | null;
26
+ setItem: (key: string, value: string) => void;
27
+ removeItem: (key: string) => void;
28
+ clear: () => void;
29
+ };
30
+
31
+ /**
32
+ * Auth persistence service
33
+ */
34
+ authPersistence: {
35
+ saveAuth: (auth: any) => void;
36
+ getAuth: () => any;
37
+ clearAuth: () => void;
38
+ };
39
+
40
+ /**
41
+ * Function to sync localStorage to device store (for Electron/Capacitor)
42
+ */
43
+ syncToDeviceStore: () => Promise<void>;
44
+
45
+ /**
46
+ * Function to sync device store to localStorage
47
+ */
48
+ syncFromDeviceStore: () => Promise<void>;
49
+
50
+ /**
51
+ * Function to trigger auth context events
52
+ */
53
+ setAuthEvent?: (data: any) => void;
54
+
55
+ /**
56
+ * Logout utility function
57
+ */
58
+ logoutFromStorage: (reason?: string) => Promise<void>;
59
+
60
+ /**
61
+ * Get the auth endpoint URL
62
+ */
63
+ getAuthEndpoint: () => string;
64
+
65
+ /**
66
+ * Default guest role
67
+ */
68
+ guestRole?: any;
69
+
70
+ /**
71
+ * Enable tenant impersonation
72
+ */
73
+ enableTenantImpersonation?: boolean;
74
+ }
75
+
76
+ export interface DashAuthProviderOverrides {
77
+ /**
78
+ * Custom login handler
79
+ */
80
+ login?: AuthProvider['login'];
81
+
82
+ /**
83
+ * Custom logout handler
84
+ */
85
+ logout?: AuthProvider['logout'];
86
+
87
+ /**
88
+ * Custom getIdentity handler
89
+ */
90
+ getIdentity?: AuthProvider['getIdentity'];
91
+
92
+ /**
93
+ * Custom checkAuth handler
94
+ */
95
+ checkAuth?: AuthProvider['checkAuth'];
96
+
97
+ /**
98
+ * Custom checkError handler
99
+ */
100
+ checkError?: AuthProvider['checkError'];
101
+
102
+ /**
103
+ * Custom getPermissions handler (if needed)
104
+ */
105
+ getPermissions?: AuthProvider['getPermissions'];
106
+ }
107
+
108
+ // ============================================================================
109
+ // FACTORY FUNCTION
110
+ // ============================================================================
111
+
112
+ /**
113
+ * Create a Dash auth provider with the given configuration
114
+ *
115
+ * @param config - Configuration for the auth provider
116
+ * @param overrides - Optional method overrides
117
+ * @returns AuthProvider compatible with react-admin
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * import { createDashAuthProvider } from 'dash-auto-admin';
122
+ *
123
+ * const authProvider = createDashAuthProvider({
124
+ * useAxios: () => axiosInstance,
125
+ * storage: dashStorage,
126
+ * authPersistence: AuthPersistenceService,
127
+ * // ... other config
128
+ * });
129
+ * ```
130
+ */
131
+ export const createDashAuthProvider = (
132
+ config: DashAuthProviderConfig,
133
+ overrides: DashAuthProviderOverrides = {}
134
+ ): AuthProvider => {
135
+ const {
136
+ useAxios,
137
+ storage,
138
+ authPersistence,
139
+ syncToDeviceStore,
140
+ syncFromDeviceStore,
141
+ setAuthEvent,
142
+ logoutFromStorage,
143
+ getAuthEndpoint,
144
+ guestRole = { name: 'guest' },
145
+ enableTenantImpersonation = false
146
+ } = config;
147
+
148
+ const defaultProvider: AuthProvider = {
149
+ login: async ({ username, password }) => {
150
+ await syncFromDeviceStore();
151
+
152
+ const axios = useAxios();
153
+
154
+ if (!(username && password)) {
155
+ return Promise.reject();
156
+ }
157
+
158
+ try {
159
+ const loginResponse = await axios.post('/login', {
160
+ email: username,
161
+ password,
162
+ });
163
+
164
+ if (loginResponse.status >= 200 && loginResponse.status <= 299) {
165
+ const redirectTo = loginResponse.data.redirectTo;
166
+
167
+ if (loginResponse.data !== "") {
168
+ storage.setItem('token', loginResponse.data.token);
169
+ }
170
+
171
+ try {
172
+ const { data: auth } = await axios.get(getAuthEndpoint());
173
+
174
+ authPersistence.saveAuth(auth);
175
+
176
+ storage.setItem('authenticated', 'true');
177
+ storage.setItem('user', JSON.stringify(auth.user));
178
+ storage.setItem(
179
+ 'roles',
180
+ auth.user?.roles
181
+ ? JSON.stringify(auth.user.roles)
182
+ : JSON.stringify(guestRole),
183
+ );
184
+
185
+ if (setAuthEvent) {
186
+ setAuthEvent({
187
+ authenticated: true,
188
+ user: auth.user,
189
+ auth: auth.auth,
190
+ token: loginResponse.data.token,
191
+ roles: auth.user?.roles
192
+ });
193
+ }
194
+
195
+ await syncToDeviceStore();
196
+
197
+ if (redirectTo) {
198
+ return Promise.resolve({ redirectTo });
199
+ } else {
200
+ return Promise.resolve(auth);
201
+ }
202
+
203
+ } catch (error) {
204
+ console.error('Error getting user auth data');
205
+ await logoutFromStorage("login get auth error");
206
+ return Promise.reject(error);
207
+ }
208
+ }
209
+ } catch (error) {
210
+ console.error(error);
211
+ await logoutFromStorage("login error logout");
212
+ return Promise.reject(error);
213
+ }
214
+
215
+ await logoutFromStorage("login default error logout");
216
+ return Promise.reject();
217
+ },
218
+
219
+ logout: async (params?: any) => {
220
+ await logoutFromStorage("logout");
221
+ return Promise.resolve("/login");
222
+ },
223
+
224
+ getIdentity: async () => {
225
+ const axios = useAxios();
226
+ const token = storage.getItem('token');
227
+
228
+ if (!token) {
229
+ return Promise.reject('No token present');
230
+ }
231
+
232
+ try {
233
+ const { data: auth } = await axios.get(getAuthEndpoint());
234
+
235
+ storage.setItem(
236
+ 'roles',
237
+ auth.user?.roles
238
+ ? JSON.stringify(auth.user.roles)
239
+ : JSON.stringify(guestRole),
240
+ );
241
+ storage.setItem('authenticated', 'true');
242
+ storage.setItem('user', JSON.stringify(auth.user));
243
+
244
+ if (enableTenantImpersonation && auth.user?.tenant_id) {
245
+ storage.setItem('tenant_id', auth.user?.tenant_id);
246
+ storage.setItem('user_id', auth.user?.id);
247
+ }
248
+
249
+ return await Promise.resolve(auth);
250
+ } catch (error) {
251
+ await logoutFromStorage("get identity error logout");
252
+ return Promise.reject(error);
253
+ } finally {
254
+ await syncToDeviceStore();
255
+ }
256
+ },
257
+
258
+ checkAuth: async () => {
259
+ const isAuthenticated = JSON.parse(storage.getItem('authenticated') || 'false');
260
+ const user = JSON.parse(storage.getItem('user') || 'null');
261
+
262
+ if (isAuthenticated && user?.id) {
263
+ const persistedAuth = authPersistence.getAuth();
264
+ if (persistedAuth) {
265
+ return Promise.resolve();
266
+ }
267
+ }
268
+
269
+ return Promise.reject();
270
+ },
271
+
272
+ checkError: (error) => {
273
+ const errorStatus = error?.response?.status;
274
+
275
+ window.dispatchEvent(
276
+ new MessageEvent('dash-global-loader', { data: false }),
277
+ );
278
+
279
+ if (errorStatus) {
280
+ const errors: any = {};
281
+ switch (errorStatus) {
282
+ case 400:
283
+ case 401:
284
+ case 403:
285
+ case 500:
286
+ window.dispatchEvent(
287
+ new MessageEvent('GlobalError', {
288
+ data: { error: error.response.data || error }
289
+ }),
290
+ );
291
+ return Promise.resolve();
292
+ case 422:
293
+ case 409:
294
+ errors.error =
295
+ 'An undefined error occurred, please try again later';
296
+ if (error.response.data?.errors) {
297
+ Object.keys(error.response.data?.errors).forEach((key) => {
298
+ errors[key] = error.response.data?.errors[key].join(' , ');
299
+ });
300
+ } else if (error.response.data?.message) {
301
+ errors.error = error.response.data?.message;
302
+ }
303
+
304
+ window.dispatchEvent(
305
+ new MessageEvent('GlobalError', { data: { error: errors } }),
306
+ );
307
+ return Promise.resolve();
308
+ default:
309
+ window.dispatchEvent(
310
+ new MessageEvent('GlobalError', {
311
+ data: { error: error.response.data || error }
312
+ }),
313
+ );
314
+ return Promise.resolve();
315
+ }
316
+ } else {
317
+ const _errors: any = {};
318
+ Object.keys(error).forEach((key) => {
319
+ _errors[key] = Array.isArray(error[key])
320
+ ? error[key].join(' , ')
321
+ : error[key];
322
+ });
323
+ return Promise.resolve();
324
+ }
325
+ },
326
+ };
327
+
328
+ // Merge default provider with overrides
329
+ return {
330
+ ...defaultProvider,
331
+ ...overrides,
332
+ // Ensure required methods are always present
333
+ login: overrides.login || defaultProvider.login,
334
+ logout: overrides.logout || defaultProvider.logout,
335
+ checkAuth: overrides.checkAuth || defaultProvider.checkAuth,
336
+ checkError: overrides.checkError || defaultProvider.checkError,
337
+ getIdentity: overrides.getIdentity || defaultProvider.getIdentity,
338
+ };
339
+ };
340
+
341
+ export default createDashAuthProvider;