@firecms/user_management 3.0.0-canary.84 → 3.0.0-canary.86
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} +8 -7
- package/dist/index.es.js +99 -81
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +97 -79
- 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} +115 -97
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-fast-compare"), 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-fast-compare", "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.equal, global.jsxRuntime, global.ui, global.Yup, global.core, global.formex, global.dateFns, global.locales));
|
3
|
+
})(this, function(exports2, React, equal, 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,56 @@
|
|
174
174
|
const [usersError, setUsersError] = React.useState();
|
175
175
|
const loading = rolesLoading || usersLoading;
|
176
176
|
React.useEffect(() => {
|
177
|
-
if (!
|
178
|
-
|
179
|
-
return
|
180
|
-
|
181
|
-
{
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
177
|
+
if (!dataSourceDelegate || !rolesPath) return;
|
178
|
+
if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
|
179
|
+
return dataSourceDelegate.listenCollection?.({
|
180
|
+
path: rolesPath,
|
181
|
+
onUpdate(entities) {
|
182
|
+
setRolesError(void 0);
|
183
|
+
try {
|
184
|
+
const newRoles = entityToRoles(entities);
|
185
|
+
if (!equal(newRoles, roles))
|
186
186
|
setRoles(newRoles);
|
187
|
-
|
188
|
-
console.error("Error loading roles", e);
|
189
|
-
setRolesError(e);
|
190
|
-
}
|
191
|
-
setRolesLoading(false);
|
192
|
-
},
|
193
|
-
error: (e) => {
|
187
|
+
} catch (e) {
|
194
188
|
console.error("Error loading roles", e);
|
195
189
|
setRolesError(e);
|
196
|
-
setRolesLoading(false);
|
197
190
|
}
|
191
|
+
setRolesLoading(false);
|
192
|
+
},
|
193
|
+
onError(e) {
|
194
|
+
console.error("Error loading roles", e);
|
195
|
+
setRolesError(e);
|
196
|
+
setRolesLoading(false);
|
198
197
|
}
|
199
|
-
);
|
200
|
-
}, [
|
198
|
+
});
|
199
|
+
}, [dataSourceDelegate, rolesPath]);
|
201
200
|
React.useEffect(() => {
|
202
|
-
if (!
|
203
|
-
|
204
|
-
return
|
205
|
-
|
206
|
-
{
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
201
|
+
if (!dataSourceDelegate || !usersPath) return;
|
202
|
+
if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
|
203
|
+
return dataSourceDelegate.listenCollection?.({
|
204
|
+
path: usersPath,
|
205
|
+
onUpdate(entities) {
|
206
|
+
setUsersError(void 0);
|
207
|
+
try {
|
208
|
+
const newUsers = entitiesToUsers(entities);
|
209
|
+
if (!equal(newUsers, usersWithRoleIds))
|
211
210
|
setUsersWithRoleIds(newUsers);
|
212
|
-
|
213
|
-
console.error("Error loading users", e);
|
214
|
-
setUsersError(e);
|
215
|
-
}
|
216
|
-
setUsersLoading(false);
|
217
|
-
},
|
218
|
-
error: (e) => {
|
211
|
+
} catch (e) {
|
219
212
|
console.error("Error loading users", e);
|
220
213
|
setUsersError(e);
|
221
|
-
setUsersLoading(false);
|
222
214
|
}
|
215
|
+
setUsersLoading(false);
|
216
|
+
},
|
217
|
+
onError(e) {
|
218
|
+
console.error("Error loading users", e);
|
219
|
+
setUsersError(e);
|
220
|
+
setUsersLoading(false);
|
223
221
|
}
|
224
|
-
);
|
225
|
-
}, [
|
222
|
+
});
|
223
|
+
}, [dataSourceDelegate, usersPath]);
|
226
224
|
const saveUser = React.useCallback(async (user) => {
|
227
|
-
if (!
|
228
|
-
|
229
|
-
if (!firestore$1 || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
225
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
226
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
230
227
|
console.debug("Persisting user", user);
|
231
228
|
const roleIds = user.roles?.map((r) => r.id);
|
232
229
|
const {
|
@@ -238,45 +235,66 @@
|
|
238
235
|
roles: roleIds
|
239
236
|
};
|
240
237
|
if (uid) {
|
241
|
-
return
|
238
|
+
return dataSourceDelegate.saveEntity({
|
239
|
+
status: "existing",
|
240
|
+
path: usersPath,
|
241
|
+
entityId: uid,
|
242
|
+
values: data
|
243
|
+
}).then(() => user);
|
242
244
|
} else {
|
243
|
-
return
|
245
|
+
return dataSourceDelegate.saveEntity({
|
246
|
+
status: "new",
|
247
|
+
path: usersPath,
|
248
|
+
values: data
|
249
|
+
}).then(() => user);
|
244
250
|
}
|
245
|
-
}, [usersPath,
|
251
|
+
}, [usersPath, dataSourceDelegate]);
|
246
252
|
const saveRole = React.useCallback((role) => {
|
247
|
-
if (!
|
248
|
-
|
249
|
-
if (!firestore$1 || !rolesPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
253
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
254
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
250
255
|
console.debug("Persisting role", role);
|
251
256
|
const {
|
252
257
|
id,
|
253
258
|
...roleData
|
254
259
|
} = role;
|
255
|
-
|
256
|
-
|
257
|
-
|
260
|
+
return dataSourceDelegate.saveEntity({
|
261
|
+
status: "existing",
|
262
|
+
path: rolesPath,
|
263
|
+
entityId: id,
|
264
|
+
values: roleData
|
265
|
+
}).then(() => {
|
266
|
+
return;
|
267
|
+
});
|
268
|
+
}, [rolesPath, dataSourceDelegate]);
|
258
269
|
const deleteUser = React.useCallback(async (user) => {
|
259
|
-
if (!
|
260
|
-
|
261
|
-
if (!firestore$1 || !usersPath) throw Error("useFirestoreUserManagement Firestore not initialised");
|
270
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
271
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
262
272
|
console.debug("Deleting", user);
|
263
273
|
const { uid } = user;
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
274
|
+
const entity = {
|
275
|
+
path: usersPath,
|
276
|
+
id: uid,
|
277
|
+
values: {}
|
278
|
+
};
|
279
|
+
await dataSourceDelegate.deleteEntity({ entity });
|
280
|
+
}, [usersPath, dataSourceDelegate]);
|
281
|
+
const deleteRole = React.useCallback(async (role) => {
|
282
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
283
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
270
284
|
console.debug("Deleting", role);
|
271
285
|
const { id } = role;
|
272
|
-
const
|
273
|
-
|
274
|
-
|
286
|
+
const entity = {
|
287
|
+
path: usersPath,
|
288
|
+
id,
|
289
|
+
values: {}
|
290
|
+
};
|
291
|
+
await dataSourceDelegate.deleteEntity({ entity });
|
292
|
+
}, [rolesPath, dataSourceDelegate]);
|
275
293
|
const collectionPermissions = React.useCallback(({
|
276
|
-
collection
|
294
|
+
collection,
|
277
295
|
user
|
278
296
|
}) => resolveUserRolePermissions({
|
279
|
-
collection
|
297
|
+
collection,
|
280
298
|
user
|
281
299
|
}), []);
|
282
300
|
const defineRolesFor = React.useCallback((user) => {
|
@@ -320,22 +338,22 @@
|
|
320
338
|
authenticator
|
321
339
|
};
|
322
340
|
}
|
323
|
-
const
|
324
|
-
return docs.map((
|
325
|
-
const data =
|
341
|
+
const entitiesToUsers = (docs) => {
|
342
|
+
return docs.map((doc) => {
|
343
|
+
const data = doc.values;
|
326
344
|
const newVar = {
|
327
|
-
uid:
|
345
|
+
uid: doc.id,
|
328
346
|
...data,
|
329
|
-
created_on: data?.created_on
|
330
|
-
updated_on: data?.updated_on
|
347
|
+
created_on: data?.created_on,
|
348
|
+
updated_on: data?.updated_on
|
331
349
|
};
|
332
350
|
return newVar;
|
333
351
|
});
|
334
352
|
};
|
335
|
-
const
|
336
|
-
return
|
337
|
-
id:
|
338
|
-
...
|
353
|
+
const entityToRoles = (entities) => {
|
354
|
+
return entities.map((doc) => ({
|
355
|
+
id: doc.id,
|
356
|
+
...doc.values
|
339
357
|
}));
|
340
358
|
};
|
341
359
|
const UserManagementContext = React.createContext({});
|
@@ -1531,7 +1549,7 @@
|
|
1531
1549
|
exports2.getUserRoles = getUserRoles;
|
1532
1550
|
exports2.hexToRgbaWithOpacity = hexToRgbaWithOpacity;
|
1533
1551
|
exports2.resolveUserRolePermissions = resolveUserRolePermissions;
|
1534
|
-
exports2.
|
1552
|
+
exports2.useBuildUserManagement = useBuildUserManagement;
|
1535
1553
|
exports2.useUserManagement = useUserManagement;
|
1536
1554
|
exports2.useUserManagementPlugin = useUserManagementPlugin;
|
1537
1555
|
exports2.userManagementAdminViews = userManagementAdminViews;
|