@edgedev/firebase 1.4.7 → 1.4.8

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 (2) hide show
  1. package/edgeFirebase.ts +89 -45
  2. package/package.json +1 -1
package/edgeFirebase.ts CHANGED
@@ -148,6 +148,7 @@ interface firebaseConfig {
148
148
  interface actionResponse {
149
149
  success: boolean;
150
150
  message: string;
151
+ meta: object;
151
152
  }
152
153
 
153
154
  interface permissionStatus {
@@ -210,7 +211,7 @@ export const EdgeFirebase = class {
210
211
  }
211
212
  }
212
213
  this.user.specialPermissions = specialPermissions;
213
- await this.listCollectionsCanAssign()
214
+ this.listCollectionsCanAssign()
214
215
  }
215
216
  const metaUnsubscribe = onSnapshot(
216
217
  doc(this.db, "users", this.user.email),
@@ -266,7 +267,6 @@ export const EdgeFirebase = class {
266
267
  this.user.uid = userAuth.uid;
267
268
  this.user.logInError = false;
268
269
  this.user.logInErrorMessage = "";
269
-
270
270
  this.startUserMetaSync();
271
271
  } else {
272
272
  this.user.email = "";
@@ -288,7 +288,8 @@ export const EdgeFirebase = class {
288
288
  if (user.userId) {
289
289
  return this.sendResponse({
290
290
  success: false,
291
- message: "User already registered"
291
+ message: "User already registered",
292
+ meta: {}
292
293
  });
293
294
  } else {
294
295
  createUserWithEmailAndPassword(
@@ -305,14 +306,16 @@ export const EdgeFirebase = class {
305
306
  }
306
307
  return this.sendResponse({
307
308
  success: true,
308
- message: ""
309
+ message: "",
310
+ meta: {}
309
311
  });
310
312
  });
311
313
  }
312
314
  } else {
313
315
  return this.sendResponse({
314
316
  success: false,
315
- message: "User doesn't exist"
317
+ message: "User doesn't exist",
318
+ meta: {}
316
319
  });
317
320
  }
318
321
  };
@@ -322,12 +325,14 @@ export const EdgeFirebase = class {
322
325
  await sendPasswordResetEmail(this.auth, email);
323
326
  return this.sendResponse({
324
327
  success: true,
325
- message: ""
328
+ message: "",
329
+ meta: {}
326
330
  });
327
331
  } catch (error) {
328
332
  return this.sendResponse({
329
333
  success: false,
330
- message: error.message
334
+ message: error.message,
335
+ meta: {}
331
336
  });
332
337
  }
333
338
  };
@@ -341,12 +346,14 @@ export const EdgeFirebase = class {
341
346
  await confirmPasswordReset(this.auth, oobCode, password);
342
347
  return this.sendResponse({
343
348
  success: true,
344
- message: ""
349
+ message: "",
350
+ meta: {}
345
351
  });
346
352
  } catch (error) {
347
353
  return this.sendResponse({
348
354
  success: false,
349
- message: error.message
355
+ message: error.message,
356
+ meta: {}
350
357
  });
351
358
  }
352
359
  };
@@ -365,12 +372,14 @@ export const EdgeFirebase = class {
365
372
  await updatePassword(user, password);
366
373
  return this.sendResponse({
367
374
  success: true,
368
- message: ""
375
+ message: "",
376
+ meta: {}
369
377
  });
370
378
  } catch (error) {
371
379
  return this.sendResponse({
372
380
  success: false,
373
- message: error.message
381
+ message: error.message,
382
+ meta: {}
374
383
  });
375
384
  }
376
385
  };
@@ -383,7 +392,8 @@ export const EdgeFirebase = class {
383
392
  }
384
393
  return this.sendResponse({
385
394
  success: true,
386
- message: ""
395
+ message: "",
396
+ meta: {}
387
397
  });
388
398
  };
389
399
 
@@ -421,12 +431,14 @@ export const EdgeFirebase = class {
421
431
  if (removedFrom.length > 0) {
422
432
  return this.sendResponse({
423
433
  success: true,
424
- message: ""
434
+ message: "",
435
+ meta: {}
425
436
  });
426
437
  } else {
427
438
  return this.sendResponse({
428
439
  success: false,
429
- message: "You do not have permission to remove this user"
440
+ message: "You do not have permission to remove this user",
441
+ meta: {}
430
442
  });
431
443
  }
432
444
  };
@@ -455,12 +467,14 @@ export const EdgeFirebase = class {
455
467
  this.generateUserMeta(userMeta);
456
468
  return this.sendResponse({
457
469
  success: true,
458
- message: ""
470
+ message: "",
471
+ meta: {}
459
472
  });
460
473
  } else {
461
474
  return this.sendResponse({
462
475
  success: false,
463
- message: "User already exists"
476
+ message: "User already exists",
477
+ meta: {}
464
478
  });
465
479
  }
466
480
  } else {
@@ -470,7 +484,8 @@ export const EdgeFirebase = class {
470
484
  "Cannot assign role or special permission for collection path(s): " +
471
485
  canAssignRole.badCollectionPaths
472
486
  .concat(canAssignSpecialPermissions.badCollectionPaths)
473
- .join(", ")
487
+ .join(", "),
488
+ meta: {}
474
489
  });
475
490
  }
476
491
  };
@@ -916,12 +931,14 @@ export const EdgeFirebase = class {
916
931
  }
917
932
  return sendResponse({
918
933
  success: true,
919
- message: ""
934
+ message: "",
935
+ meta: {}
920
936
  });
921
937
  } else {
922
938
  return sendResponse({
923
939
  success: false,
924
- message: `You do not have permission to read from "${collectionPath}"`
940
+ message: `You do not have permission to read from "${collectionPath}"`,
941
+ meta: {}
925
942
  });
926
943
  }
927
944
  };
@@ -991,12 +1008,14 @@ export const EdgeFirebase = class {
991
1008
  this.unsubscibe[collectionPath] = unsubscribe;
992
1009
  return this.sendResponse({
993
1010
  success: true,
994
- message: ""
1011
+ message: "",
1012
+ meta: {}
995
1013
  });
996
1014
  } else {
997
1015
  return this.sendResponse({
998
1016
  success: false,
999
- message: `You do not have permission to read from "${collectionPath}"`
1017
+ message: `You do not have permission to read from "${collectionPath}"`,
1018
+ meta: {}
1000
1019
  });
1001
1020
  }
1002
1021
  };
@@ -1125,13 +1144,15 @@ export const EdgeFirebase = class {
1125
1144
  });
1126
1145
  return this.sendResponse({
1127
1146
  success: true,
1128
- message: ""
1147
+ message: "",
1148
+ meta: {}
1129
1149
  });
1130
1150
  } else {
1131
1151
  return this.sendResponse({
1132
1152
  success: false,
1133
1153
  message:
1134
- "Cannot remove permissions for collection path: " + collectionPath
1154
+ "Cannot remove permissions for collection path: " + collectionPath,
1155
+ meta: {}
1135
1156
  });
1136
1157
  }
1137
1158
  };
@@ -1148,13 +1169,15 @@ export const EdgeFirebase = class {
1148
1169
  });
1149
1170
  return this.sendResponse({
1150
1171
  success: true,
1151
- message: ""
1172
+ message: "",
1173
+ meta: {}
1152
1174
  });
1153
1175
  } else {
1154
1176
  return this.sendResponse({
1155
1177
  success: false,
1156
1178
  message:
1157
- "Cannot remove permissions for collection path: " + collectionPath
1179
+ "Cannot remove permissions for collection path: " + collectionPath,
1180
+ meta: {}
1158
1181
  });
1159
1182
  }
1160
1183
  };
@@ -1177,19 +1200,22 @@ export const EdgeFirebase = class {
1177
1200
  updateDoc(doc(this.db, "users/" + email), permissionItem);
1178
1201
  return this.sendResponse({
1179
1202
  success: true,
1180
- message: ""
1203
+ message: "",
1204
+ meta: {}
1181
1205
  });
1182
1206
  } else {
1183
1207
  return this.sendResponse({
1184
1208
  success: false,
1185
- message: collectionPath + " is not a valid collection path"
1209
+ message: collectionPath + " is not a valid collection path",
1210
+ meta: {}
1186
1211
  });
1187
1212
  }
1188
1213
  } else {
1189
1214
  return this.sendResponse({
1190
1215
  success: false,
1191
1216
  message:
1192
- "Cannot assign permissions for collection path: " + collectionPath
1217
+ "Cannot assign permissions for collection path: " + collectionPath,
1218
+ meta: {}
1193
1219
  });
1194
1220
  }
1195
1221
  };
@@ -1215,25 +1241,29 @@ export const EdgeFirebase = class {
1215
1241
  updateDoc(doc(this.db, "users/" + email), roleItem);
1216
1242
  return this.sendResponse({
1217
1243
  success: true,
1218
- message: ""
1244
+ message: "",
1245
+ meta: {}
1219
1246
  });
1220
1247
  } else {
1221
1248
  return this.sendResponse({
1222
1249
  success: false,
1223
- message: collectionPath + " is not a valid collection path"
1250
+ message: collectionPath + " is not a valid collection path",
1251
+ meta: {}
1224
1252
  });
1225
1253
  }
1226
1254
  } else {
1227
1255
  return this.sendResponse({
1228
1256
  success: false,
1229
- message: "Role must be either 'admin' or 'user'"
1257
+ message: "Role must be either 'admin' or 'user'",
1258
+ meta: {}
1230
1259
  });
1231
1260
  }
1232
1261
  } else {
1233
1262
  return this.sendResponse({
1234
1263
  success: false,
1235
1264
  message:
1236
- "Cannot assign permissions for collection path: " + collectionPath
1265
+ "Cannot assign permissions for collection path: " + collectionPath,
1266
+ meta: {}
1237
1267
  });
1238
1268
  }
1239
1269
  };
@@ -1246,12 +1276,14 @@ export const EdgeFirebase = class {
1246
1276
  await deleteDoc(doc(this.db, "collection-data", collectionPath.replaceAll("/", "-")));
1247
1277
  return this.sendResponse({
1248
1278
  success: true,
1249
- message: ""
1279
+ message: "",
1280
+ meta: {}
1250
1281
  });
1251
1282
  } else {
1252
1283
  return this.sendResponse({
1253
1284
  success: false,
1254
- message: "Cannot remove permissions for collection path: " + collectionPath
1285
+ message: "Cannot remove permissions for collection path: " + collectionPath,
1286
+ meta: {}
1255
1287
  });
1256
1288
  }
1257
1289
  };
@@ -1262,7 +1294,7 @@ export const EdgeFirebase = class {
1262
1294
  permissions: permissions
1263
1295
  ): Promise<actionResponse> => {
1264
1296
  const canAssign = await this.permissionCheck("assign", collectionPath);
1265
-
1297
+ // TODO: check if collectionPath starts with "users" and deny if so
1266
1298
  if (canAssign) {
1267
1299
  if (role === "admin" || role === "user") {
1268
1300
  const currentTime = new Date().getTime();
@@ -1290,19 +1322,22 @@ export const EdgeFirebase = class {
1290
1322
 
1291
1323
  return this.sendResponse({
1292
1324
  success: true,
1293
- message: ""
1325
+ message: "",
1326
+ meta: {}
1294
1327
  });
1295
1328
  } else {
1296
1329
  return this.sendResponse({
1297
1330
  success: false,
1298
- message: "Role must be either 'admin' or 'user'"
1331
+ message: "Role must be either 'admin' or 'user'",
1332
+ meta: {}
1299
1333
  });
1300
1334
  }
1301
1335
  } else {
1302
1336
  return this.sendResponse({
1303
1337
  success: false,
1304
1338
  message:
1305
- "Cannot assign permissions for collection path: " + collectionPath
1339
+ "Cannot assign permissions for collection path: " + collectionPath,
1340
+ meta: {}
1306
1341
  });
1307
1342
  }
1308
1343
  };
@@ -1317,7 +1352,8 @@ export const EdgeFirebase = class {
1317
1352
  if (!canWrite) {
1318
1353
  return this.sendResponse({
1319
1354
  success: false,
1320
- message: `You do not have permission to write to "${collectionPath}"`
1355
+ message: `You do not have permission to write to "${collectionPath}"`,
1356
+ meta: {}
1321
1357
  });
1322
1358
  } else {
1323
1359
  if (generatePermissions) {
@@ -1340,6 +1376,11 @@ export const EdgeFirebase = class {
1340
1376
  }
1341
1377
  }
1342
1378
  setDoc(doc(this.db, collectionPath, docId), cloneItem);
1379
+ return this.sendResponse({
1380
+ success: true,
1381
+ message: "",
1382
+ meta: {docId}
1383
+ });
1343
1384
  } else {
1344
1385
  const docRef = await addDoc(
1345
1386
  collection(this.db, collectionPath),
@@ -1356,11 +1397,12 @@ export const EdgeFirebase = class {
1356
1397
  { ...cloneItem, docId: docRef.id },
1357
1398
  generatePermissions
1358
1399
  );
1400
+ return this.sendResponse({
1401
+ success: true,
1402
+ message: "",
1403
+ meta: {docId: docRef.id}
1404
+ });
1359
1405
  }
1360
- return this.sendResponse({
1361
- success: true,
1362
- message: ""
1363
- });
1364
1406
  }
1365
1407
  };
1366
1408
 
@@ -1381,12 +1423,14 @@ export const EdgeFirebase = class {
1381
1423
  deleteDoc(doc(this.db, collectionPath, docId));
1382
1424
  return this.sendResponse({
1383
1425
  success: true,
1384
- message: ""
1426
+ message: "",
1427
+ meta: {}
1385
1428
  });
1386
1429
  } else {
1387
1430
  return this.sendResponse({
1388
1431
  success: false,
1389
- message: `You do not have permission to delete from "${collectionPath}"`
1432
+ message: `You do not have permission to delete from "${collectionPath}"`,
1433
+ meta: {}
1390
1434
  });
1391
1435
  }
1392
1436
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {