@edgedev/firebase 2.0.24 → 2.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 plugin for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -261,7 +261,7 @@ const permissionCheck = async (userId, action, collectionPath) => {
261
261
  const roles = userData.roles || []
262
262
 
263
263
  // Check each role for permission
264
- for (let role of roles) {
264
+ for (const role of roles) {
265
265
  if (role.collectionPath === collectionPath) {
266
266
  // Fetch collection data
267
267
  const collectionDoc = await db.collection('collection-data').doc(collectionPath).get()
@@ -284,18 +284,29 @@ exports.deleteSelf = onCall(async (request) => {
284
284
  const userDoc = await db.collection('staged-users').doc(request.auth.uid).get()
285
285
  const userData = userDoc.data()
286
286
  const userCollectionPaths = userData.collectionPaths || []
287
-
288
- for (let path of userCollectionPaths) {
287
+
288
+ for (const path of userCollectionPaths) {
289
289
  const usersWithSamePath = await db.collection('staged-users').where('collectionPaths', 'array-contains', path).get()
290
-
290
+
291
291
  // If no other users have the same collection path, delete the path and all documents and collections under it
292
292
  if (usersWithSamePath.size <= 1) {
293
- const docsToDelete = await db.collection(path).get()
294
- const batch = db.batch()
295
- docsToDelete.docs.forEach((doc) => {
296
- batch.delete(doc.ref)
297
- })
298
- await batch.commit()
293
+ const adjustedPath = path.replace(/-/g, '/')
294
+ const docRef = db.doc(adjustedPath)
295
+ const doc = await docRef.get()
296
+
297
+ if (doc.exists) {
298
+ // If the path is a document, delete it directly
299
+ await docRef.delete()
300
+ }
301
+ else {
302
+ // If the path is a collection, delete all documents under it
303
+ const docsToDelete = await db.collection(adjustedPath).get()
304
+ const batch = db.batch()
305
+ docsToDelete.docs.forEach((doc) => {
306
+ batch.delete(doc.ref)
307
+ })
308
+ await batch.commit()
309
+ }
299
310
  }
300
311
  }
301
312
 
@@ -408,7 +419,6 @@ exports.updateUser = onDocumentUpdated({ document: 'staged-users/{docId}', timeo
408
419
  })
409
420
 
410
421
  async function setUser(userRef, newData, oldData, stagedDocId) {
411
-
412
422
  const user = await userRef.get()
413
423
  let userUpdate = { meta: newData.meta, stagedDocId }
414
424
 
@@ -251,7 +251,9 @@ service cloud.firestore {
251
251
  !(permissionCheck == "write" &&
252
252
  (
253
253
  ("stripeCustomerId" in request.resource.data && (!("stripeCustomerId" in resource.data) || resource.data.stripeCustomerId != request.resource.data.stripeCustomerId)) ||
254
- ("stripeSubscription" in request.resource.data && (!("stripeSubscription" in resource.data) || resource.data.stripeSubscription != request.resource.data.stripeSubscription))
254
+ ("stripeSubscription" in request.resource.data && (!("stripeSubscription" in resource.data) || resource.data.stripeSubscription != request.resource.data.stripeSubscription)) ||
255
+ ("stripeProductId" in request.resource.data && (!("stripeProductId" in resource.data) || resource.data.stripeProductId != request.resource.data.stripeProductId)) ||
256
+ ("stripePriceId" in request.resource.data && (!("stripePriceId" in resource.data) || resource.data.stripePriceId != request.resource.data.stripePriceId)) ||
255
257
  )
256
258
  ) &&
257
259
  request.auth != null &&