@firecms/user_management 3.0.0-canary.83 → 3.0.0-canary.85
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/hooks/index.d.ts +1 -1
- package/dist/hooks/{useFirestoreUserManagement.d.ts → useBuildUserManagement.d.ts} +6 -7
- package/dist/index.es.js +96 -83
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +95 -81
- package/dist/index.umd.js.map +1 -1
- package/package.json +8 -9
- package/src/hooks/index.ts +1 -1
- package/src/hooks/{useFirestoreUserManagement.tsx → useBuildUserManagement.tsx} +102 -92
package/dist/index.umd.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
(function(global, factory) {
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("
|
3
|
-
})(this, function(exports2, React,
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react/jsx-runtime"), require("@firecms/ui"), require("yup"), require("@firecms/core"), require("@firecms/formex"), require("date-fns"), require("date-fns/locale")) : typeof define === "function" && define.amd ? define(["exports", "react", "react/jsx-runtime", "@firecms/ui", "yup", "@firecms/core", "@firecms/formex", "date-fns", "date-fns/locale"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.FireCMS = {}, global.React, global.jsxRuntime, global.ui, global.Yup, global.core, global.formex, global.dateFns, global.locales));
|
3
|
+
})(this, function(exports2, React, jsxRuntime, ui, Yup, core, formex, dateFns, locales) {
|
4
4
|
"use strict";
|
5
5
|
function _interopNamespaceDefault(e) {
|
6
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
@@ -153,8 +153,8 @@
|
|
153
153
|
const alpha = opacity / 100;
|
154
154
|
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
155
155
|
}
|
156
|
-
function
|
157
|
-
|
156
|
+
function useBuildUserManagement({
|
157
|
+
dataSourceDelegate,
|
158
158
|
usersPath = "__FIRECMS/config/users",
|
159
159
|
rolesPath = "__FIRECMS/config/roles",
|
160
160
|
usersLimit,
|
@@ -174,59 +174,52 @@
|
|
174
174
|
const [usersError, setUsersError] = React.useState();
|
175
175
|
const loading = rolesLoading || usersLoading;
|
176
176
|
React.useEffect(() => {
|
177
|
-
if (!
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
setRoles(newRoles);
|
187
|
-
} catch (e) {
|
188
|
-
console.error("Error loading roles", e);
|
189
|
-
setRolesError(e);
|
190
|
-
}
|
191
|
-
setRolesLoading(false);
|
192
|
-
},
|
193
|
-
error: (e) => {
|
177
|
+
if (!dataSourceDelegate || !rolesPath) return;
|
178
|
+
dataSourceDelegate.listenCollection?.({
|
179
|
+
path: rolesPath,
|
180
|
+
onUpdate(entities) {
|
181
|
+
setRolesError(void 0);
|
182
|
+
try {
|
183
|
+
const newRoles = entityToRoles(entities);
|
184
|
+
setRoles(newRoles);
|
185
|
+
} catch (e) {
|
194
186
|
console.error("Error loading roles", e);
|
195
187
|
setRolesError(e);
|
196
|
-
setRolesLoading(false);
|
197
188
|
}
|
189
|
+
setRolesLoading(false);
|
190
|
+
},
|
191
|
+
onError(e) {
|
192
|
+
console.error("Error loading roles", e);
|
193
|
+
setRolesError(e);
|
194
|
+
setRolesLoading(false);
|
198
195
|
}
|
199
|
-
);
|
200
|
-
}, [
|
196
|
+
});
|
197
|
+
}, [dataSourceDelegate, rolesPath]);
|
201
198
|
React.useEffect(() => {
|
202
|
-
if (!
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
setUsersWithRoleIds(newUsers);
|
212
|
-
} catch (e) {
|
213
|
-
console.error("Error loading users", e);
|
214
|
-
setUsersError(e);
|
215
|
-
}
|
216
|
-
setUsersLoading(false);
|
217
|
-
},
|
218
|
-
error: (e) => {
|
199
|
+
if (!dataSourceDelegate || !usersPath) return;
|
200
|
+
dataSourceDelegate.listenCollection?.({
|
201
|
+
path: usersPath,
|
202
|
+
onUpdate(entities) {
|
203
|
+
setUsersError(void 0);
|
204
|
+
try {
|
205
|
+
const newUsers = entitiesToUsers(entities);
|
206
|
+
setUsersWithRoleIds(newUsers);
|
207
|
+
} catch (e) {
|
219
208
|
console.error("Error loading users", e);
|
220
209
|
setUsersError(e);
|
221
|
-
setUsersLoading(false);
|
222
210
|
}
|
211
|
+
setUsersLoading(false);
|
212
|
+
},
|
213
|
+
onError(e) {
|
214
|
+
console.error("Error loading users", e);
|
215
|
+
setUsersError(e);
|
216
|
+
setUsersLoading(false);
|
223
217
|
}
|
224
|
-
);
|
225
|
-
}, [
|
218
|
+
});
|
219
|
+
}, [dataSourceDelegate, usersPath]);
|
226
220
|
const saveUser = React.useCallback(async (user) => {
|
227
|
-
if (!
|
228
|
-
|
229
|
-
if (!firestore$1 || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
221
|
+
if (!dataSourceDelegate) throw Error("useFirestoreUserManagement Firebase not initialised");
|
222
|
+
if (!usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
230
223
|
console.debug("Persisting user", user);
|
231
224
|
const roleIds = user.roles?.map((r) => r.id);
|
232
225
|
const {
|
@@ -238,45 +231,66 @@
|
|
238
231
|
roles: roleIds
|
239
232
|
};
|
240
233
|
if (uid) {
|
241
|
-
return
|
234
|
+
return dataSourceDelegate.saveEntity({
|
235
|
+
status: "existing",
|
236
|
+
path: usersPath,
|
237
|
+
entityId: uid,
|
238
|
+
values: data
|
239
|
+
}).then(() => user);
|
242
240
|
} else {
|
243
|
-
return
|
241
|
+
return dataSourceDelegate.saveEntity({
|
242
|
+
status: "new",
|
243
|
+
path: usersPath,
|
244
|
+
values: data
|
245
|
+
}).then(() => user);
|
244
246
|
}
|
245
|
-
}, [usersPath,
|
247
|
+
}, [usersPath, dataSourceDelegate]);
|
246
248
|
const saveRole = React.useCallback((role) => {
|
247
|
-
if (!
|
248
|
-
|
249
|
-
if (!firestore$1 || !rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
249
|
+
if (!dataSourceDelegate) throw Error("useFirestoreUserManagement Firebase not initialised");
|
250
|
+
if (!rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
250
251
|
console.debug("Persisting role", role);
|
251
252
|
const {
|
252
253
|
id,
|
253
254
|
...roleData
|
254
255
|
} = role;
|
255
|
-
|
256
|
-
|
257
|
-
|
256
|
+
return dataSourceDelegate.saveEntity({
|
257
|
+
status: "existing",
|
258
|
+
path: rolesPath,
|
259
|
+
entityId: id,
|
260
|
+
values: roleData
|
261
|
+
}).then(() => {
|
262
|
+
return;
|
263
|
+
});
|
264
|
+
}, [rolesPath, dataSourceDelegate]);
|
258
265
|
const deleteUser = React.useCallback(async (user) => {
|
259
|
-
if (!
|
260
|
-
|
261
|
-
if (!firestore$1 || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
266
|
+
if (!dataSourceDelegate) throw Error("useFirestoreUserManagement Firebase not initialised");
|
267
|
+
if (!usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
262
268
|
console.debug("Deleting", user);
|
263
269
|
const { uid } = user;
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
+
const entity = {
|
271
|
+
path: usersPath,
|
272
|
+
id: uid,
|
273
|
+
values: {}
|
274
|
+
};
|
275
|
+
await dataSourceDelegate.deleteEntity({ entity });
|
276
|
+
}, [usersPath, dataSourceDelegate]);
|
277
|
+
const deleteRole = React.useCallback(async (role) => {
|
278
|
+
if (!dataSourceDelegate) throw Error("useFirestoreUserManagement Firebase not initialised");
|
279
|
+
if (!rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
270
280
|
console.debug("Deleting", role);
|
271
281
|
const { id } = role;
|
272
|
-
const
|
273
|
-
|
274
|
-
|
282
|
+
const entity = {
|
283
|
+
path: usersPath,
|
284
|
+
id,
|
285
|
+
values: {}
|
286
|
+
};
|
287
|
+
await dataSourceDelegate.deleteEntity({ entity });
|
288
|
+
}, [rolesPath, dataSourceDelegate]);
|
275
289
|
const collectionPermissions = React.useCallback(({
|
276
|
-
collection
|
290
|
+
collection,
|
277
291
|
user
|
278
292
|
}) => resolveUserRolePermissions({
|
279
|
-
collection
|
293
|
+
collection,
|
280
294
|
user
|
281
295
|
}), []);
|
282
296
|
const defineRolesFor = React.useCallback((user) => {
|
@@ -320,22 +334,22 @@
|
|
320
334
|
authenticator
|
321
335
|
};
|
322
336
|
}
|
323
|
-
const
|
324
|
-
return docs.map((
|
325
|
-
const data =
|
337
|
+
const entitiesToUsers = (docs) => {
|
338
|
+
return docs.map((doc) => {
|
339
|
+
const data = doc.values;
|
326
340
|
const newVar = {
|
327
|
-
uid:
|
341
|
+
uid: doc.id,
|
328
342
|
...data,
|
329
|
-
created_on: data?.created_on
|
330
|
-
updated_on: data?.updated_on
|
343
|
+
created_on: data?.created_on,
|
344
|
+
updated_on: data?.updated_on
|
331
345
|
};
|
332
346
|
return newVar;
|
333
347
|
});
|
334
348
|
};
|
335
|
-
const
|
336
|
-
return
|
337
|
-
id:
|
338
|
-
...
|
349
|
+
const entityToRoles = (entities) => {
|
350
|
+
return entities.map((doc) => ({
|
351
|
+
id: doc.id,
|
352
|
+
...doc.values
|
339
353
|
}));
|
340
354
|
};
|
341
355
|
const UserManagementContext = React.createContext({});
|
@@ -1531,7 +1545,7 @@
|
|
1531
1545
|
exports2.getUserRoles = getUserRoles;
|
1532
1546
|
exports2.hexToRgbaWithOpacity = hexToRgbaWithOpacity;
|
1533
1547
|
exports2.resolveUserRolePermissions = resolveUserRolePermissions;
|
1534
|
-
exports2.
|
1548
|
+
exports2.useBuildUserManagement = useBuildUserManagement;
|
1535
1549
|
exports2.useUserManagement = useUserManagement;
|
1536
1550
|
exports2.useUserManagementPlugin = useUserManagementPlugin;
|
1537
1551
|
exports2.userManagementAdminViews = userManagementAdminViews;
|