@edgedev/firebase 2.1.68 → 2.1.70

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/edgeFirebase.ts CHANGED
@@ -914,11 +914,11 @@ export const EdgeFirebase = class {
914
914
  if (!stagedDocId) {
915
915
  stagedDocId = this.user.stagedDocId;
916
916
  }
917
+ const updates: Record<string, unknown> = { uid: this.user.uid };
917
918
  for (const [key, value] of Object.entries(meta)) {
918
- await updateDoc(doc(this.db, "staged-users/" + stagedDocId), {
919
- ["meta." + key]: value, uid: this.user.uid
920
- });
919
+ updates[`meta.${key}`] = value;
921
920
  }
921
+ await updateDoc(doc(this.db, "staged-users/" + stagedDocId), updates);
922
922
  return this.sendResponse({
923
923
  success: true,
924
924
  message: "line 664",
@@ -2403,4 +2403,4 @@ export const EdgeFirebase = class {
2403
2403
  });
2404
2404
  }
2405
2405
  }
2406
- };
2406
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.1.68",
3
+ "version": "2.1.70",
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": {
@@ -2,7 +2,7 @@ const AWS = require('aws-sdk')
2
2
  const FormData = require('form-data')
3
3
  const fetch = require('node-fetch')
4
4
 
5
- const { onCall, HttpsError, logger, getFirestore, functions, admin, twilio, db, onSchedule, onDocumentUpdated, pubsub, Storage, permissionCheck, onObjectFinalized, onObjectDeleted, onDocumentDeleted } = require('./config.js')
5
+ const { onCall, HttpsError, logger, getFirestore, functions, admin, twilio, db, onSchedule, onDocumentUpdated, onDocumentWritten, pubsub, Storage, permissionCheck, onObjectFinalized, onObjectDeleted, onDocumentDeleted } = require('./config.js')
6
6
  const authToken = process.env.TWILIO_AUTH_TOKEN
7
7
  const accountSid = process.env.TWILIO_SID
8
8
  const systemNumber = process.env.TWILIO_SYSTEM_NUMBER
@@ -302,6 +302,35 @@ exports.topicQueue = onSchedule({ schedule: 'every 1 minutes', timeoutSeconds: 1
302
302
  }
303
303
  })
304
304
 
305
+ exports.userSyncMetaToOrg = onDocumentWritten({ document: 'staged-users/{stagedId}', timeoutSeconds: 180 }, async (event) => {
306
+ console.log('userSyncMetaToOrg triggered')
307
+ const change = event.data
308
+ const afterExists = change.after.exists
309
+ const beforeData = change.before.data() || {}
310
+ const afterData = afterExists ? change.after.data() : null
311
+
312
+ const beforeUniqueOrgs = beforeData.roles ? [...new Set(Object.values(beforeData.roles).map(role => role.collectionPath.split('-')[1]))] : []
313
+ const afterUniqueOrgs = (afterData && afterData.roles) ? [...new Set(Object.values(afterData.roles).map(role => role.collectionPath.split('-')[1]))] : []
314
+ if (!afterExists) {
315
+ for (const orgId of beforeUniqueOrgs) {
316
+ // delete user from org
317
+ const orgRef = db.collection('organizations').doc(orgId).collection('users').doc(change.before.id)
318
+ await orgRef.delete()
319
+ }
320
+ }
321
+ const orgsRemoved = beforeUniqueOrgs.filter(orgId => !afterUniqueOrgs.includes(orgId))
322
+ for (const orgId of orgsRemoved) {
323
+ // delete user from org
324
+ const orgRef = db.collection('organizations').doc(orgId).collection('users').doc(change.before.id)
325
+ await orgRef.delete()
326
+ }
327
+ for (const orgId of afterUniqueOrgs) {
328
+ // add user to org
329
+ const orgRef = db.collection('organizations').doc(orgId).collection('users').doc(change.before.id)
330
+ await orgRef.set({ ...afterData.meta, userId: afterData.userId, stagedDocId: change.before.id })
331
+ }
332
+ })
333
+
305
334
  exports.sendVerificationCode = onCall(async (request) => {
306
335
  const data = request.data
307
336
  let code = (Math.floor(Math.random() * 1000000) + 1000000).toString().substring(1)