@edgedev/firebase 1.4.1 → 1.4.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/README.md CHANGED
@@ -242,23 +242,23 @@ edgeFirebase.removeUser("user@edgemarketingdesign.com");
242
242
 
243
243
  ### List Users
244
244
 
245
- This will list all users that are members of collections that the user running the function has assign access for, it will list them grouped by collections.
245
+ This will list all users that are members of collections that the user running the function has assign access for, it will be a listed index by email/user id.
246
246
 
247
247
  ```javascript
248
248
  const users = await edgeFirebase.listUsers();
249
249
  ```
250
250
 
251
251
  ```typescript
252
- interface usersByCollection {
253
- [collectionPath: string]: [user];
252
+ interface usersByEmail {
253
+ [email: string]: [user];
254
254
  }
255
255
  ```
256
256
 
257
257
  ```typescript
258
258
  interface user {
259
259
  email: string;
260
- role: "admin" | "user" | null;
261
- specialPermission: permissions | null;
260
+ roles: {[collectionPath: string ]: "admin" | "user"}
261
+ specialPermissions: {[collectionPath: string]: permissions};
262
262
  userId: string;
263
263
  docId: string;
264
264
  uid: string;
package/edgeFirebase.ts CHANGED
@@ -103,16 +103,16 @@ interface newUser {
103
103
 
104
104
  interface user {
105
105
  email: string;
106
- role: "admin" | "user" | null;
107
- specialPermission: permissions | null;
106
+ roles: {[collectionPath: string ]: "admin" | "user"}
107
+ specialPermissions: {[collectionPath: string]: permissions};
108
108
  userId: string;
109
109
  docId: string;
110
110
  uid: string;
111
111
  last_updated: Date;
112
112
  }
113
113
 
114
- interface usersByCollection {
115
- [collectionPath: string]: [user];
114
+ interface usersByEmail {
115
+ [email: string]: [user];
116
116
  }
117
117
  interface userMeta extends newUser {
118
118
  docId: string;
@@ -988,6 +988,7 @@ export const EdgeFirebase = class {
988
988
  }
989
989
  };
990
990
 
991
+ // TODO: change this function to be synced dynamically on the user object
991
992
  public listCollectionsCanAssign = async (): Promise<string[]> => {
992
993
  let collectionPaths = [];
993
994
  for (const role of this.user.roles) {
@@ -1035,11 +1036,18 @@ export const EdgeFirebase = class {
1035
1036
  return collectionPathList;
1036
1037
  };
1037
1038
 
1038
- public listUsers = async (): Promise<usersByCollection> => {
1039
+ // TODO: finish making this query by collectionPath if passed.. in furture will be used to get users by collectionPath
1040
+ // because having one giant list of users is not scalable
1041
+ public listUsers = async (collectionPath = ''): Promise<usersByEmail> => {
1039
1042
  const userList = {};
1043
+ if (collectionPath) {
1044
+ const canAssign = await this.permissionCheck("assign", collectionPath);
1045
+ if (!canAssign) {
1046
+ return {}
1047
+ }
1048
+ }
1040
1049
  const collectionPathList = await this.listCollectionsCanAssign();
1041
1050
  for (const collectionPath of collectionPathList) {
1042
- userList[collectionPath] = [];
1043
1051
  const roleUsers = await getDocs(
1044
1052
  query(
1045
1053
  collection(this.db, "users"),
@@ -1052,16 +1060,20 @@ export const EdgeFirebase = class {
1052
1060
  );
1053
1061
  roleUsers.forEach((doc) => {
1054
1062
  const user = doc.data();
1055
- userList[collectionPath].push({
1056
- docId: user.docId,
1057
- email: user.email,
1058
- role: user.roles[collectionPath].role,
1059
- specialPermission: null,
1060
- meta: user.meta,
1061
- last_updated: user.last_updated,
1062
- userId: user.userId,
1063
- uid: user.uid
1064
- });
1063
+ if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
1064
+ userList[user.email] = {
1065
+ docId: user.docId,
1066
+ email: user.email,
1067
+ roles: {[collectionPath]: user.roles[collectionPath].role },
1068
+ specialPermissions: {},
1069
+ meta: user.meta,
1070
+ last_updated: user.last_updated,
1071
+ userId: user.userId,
1072
+ uid: user.uid
1073
+ }
1074
+ } else {
1075
+ userList[user.email].roles[collectionPath] = user.roles[collectionPath].role
1076
+ }
1065
1077
  });
1066
1078
  const specialPermissionsUsers = await getDocs(
1067
1079
  query(
@@ -1075,17 +1087,20 @@ export const EdgeFirebase = class {
1075
1087
  );
1076
1088
  specialPermissionsUsers.forEach((doc) => {
1077
1089
  const user = doc.data();
1078
- userList[collectionPath].push({
1079
- docId: user.docId,
1080
- email: user.email,
1081
- role: null,
1082
- specialPermission:
1083
- user.specialPermissions[collectionPath].permissions,
1084
- meta: user.meta,
1085
- last_updated: user.last_updated,
1086
- userId: user.userId,
1087
- uid: user.uid
1088
- });
1090
+ if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
1091
+ userList[user.email] = {
1092
+ docId: user.docId,
1093
+ email: user.email,
1094
+ role: {},
1095
+ specialPermissions: {[collectionPath]: user.specialPermissions[collectionPath].permissions},
1096
+ meta: user.meta,
1097
+ last_updated: user.last_updated,
1098
+ userId: user.userId,
1099
+ uid: user.uid
1100
+ }
1101
+ } else {
1102
+ userList[user.email].specialPermissions[collectionPath] = user.specialPermissions[collectionPath].permissions
1103
+ }
1089
1104
  });
1090
1105
  }
1091
1106
  return userList;
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
6
9
  "author": "Seth Fischer",
7
10
  "keywords": [
8
11
  "firebase authentication",
@@ -32,8 +35,5 @@
32
35
  "peerDependencies": {
33
36
  "firebase": "^9.12.1",
34
37
  "vue": "^3.0.0"
35
- },
36
- "scripts": {
37
- "test": "echo \"Error: no test specified\" && exit 1"
38
38
  }
39
- }
39
+ }