@edgedev/firebase 2.1.68 → 2.1.71
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 +11 -6
- package/package.json +1 -1
- package/src/edgeFirebase.js +30 -1
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
|
-
|
|
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",
|
|
@@ -1389,8 +1389,13 @@ export const EdgeFirebase = class {
|
|
|
1389
1389
|
const canRead = await this.permissionCheck("read", collectionPath);
|
|
1390
1390
|
if (canRead) {
|
|
1391
1391
|
const q = this.getQuery(collectionPath, queryList, orderList, max, last);
|
|
1392
|
-
|
|
1393
|
-
|
|
1392
|
+
let docs;
|
|
1393
|
+
try {
|
|
1394
|
+
docs = await getDocs(q);
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
console.log('error getting documents')
|
|
1397
|
+
console.error('Error getting documents:', error);
|
|
1398
|
+
}
|
|
1394
1399
|
|
|
1395
1400
|
nextLast = docs.docs[docs.docs.length - 1];
|
|
1396
1401
|
docs.forEach((doc) => {
|
|
@@ -2403,4 +2408,4 @@ export const EdgeFirebase = class {
|
|
|
2403
2408
|
});
|
|
2404
2409
|
}
|
|
2405
2410
|
}
|
|
2406
|
-
};
|
|
2411
|
+
};
|
package/package.json
CHANGED
package/src/edgeFirebase.js
CHANGED
|
@@ -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)
|