@edgedev/firebase 2.1.67 → 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 +14 -6
- package/package.json +1 -1
- package/src/edgeFirebase.js +30 -1
package/edgeFirebase.ts
CHANGED
|
@@ -125,6 +125,7 @@ interface newUser {
|
|
|
125
125
|
specialPermissions: specialPermission[];
|
|
126
126
|
meta: object;
|
|
127
127
|
isTemplate?: boolean;
|
|
128
|
+
customRegCode?: string;
|
|
128
129
|
subCreate?: {
|
|
129
130
|
rootPath: string, // This must be a collection path (odd number of segments) since a document will be created and assigned to ther user here.
|
|
130
131
|
role: string,
|
|
@@ -913,11 +914,11 @@ export const EdgeFirebase = class {
|
|
|
913
914
|
if (!stagedDocId) {
|
|
914
915
|
stagedDocId = this.user.stagedDocId;
|
|
915
916
|
}
|
|
917
|
+
const updates: Record<string, unknown> = { uid: this.user.uid };
|
|
916
918
|
for (const [key, value] of Object.entries(meta)) {
|
|
917
|
-
|
|
918
|
-
["meta." + key]: value, uid: this.user.uid
|
|
919
|
-
});
|
|
919
|
+
updates[`meta.${key}`] = value;
|
|
920
920
|
}
|
|
921
|
+
await updateDoc(doc(this.db, "staged-users/" + stagedDocId), updates);
|
|
921
922
|
return this.sendResponse({
|
|
922
923
|
success: true,
|
|
923
924
|
message: "line 664",
|
|
@@ -1205,8 +1206,10 @@ export const EdgeFirebase = class {
|
|
|
1205
1206
|
private generateUserMeta = async (userMeta: newUser): Promise<actionResponse> => {
|
|
1206
1207
|
const roles: role[] = userMeta.roles || [];
|
|
1207
1208
|
const specialPermissions: specialPermission[] = userMeta.specialPermissions || [];
|
|
1209
|
+
const docId = userMeta?.customRegCode || "";
|
|
1208
1210
|
delete userMeta.roles;
|
|
1209
1211
|
delete userMeta.specialPermissions;
|
|
1212
|
+
delete userMeta.customRegCode;
|
|
1210
1213
|
|
|
1211
1214
|
let isTemplate = false
|
|
1212
1215
|
if (Object.prototype.hasOwnProperty.call(userMeta, "isTemplate") && userMeta.isTemplate) {
|
|
@@ -1235,8 +1238,13 @@ export const EdgeFirebase = class {
|
|
|
1235
1238
|
}
|
|
1236
1239
|
|
|
1237
1240
|
const onlyMeta = { meta: userMeta.meta, userId: "", uid: this.user.uid, roles:{}, specialPermissions:{}, isTemplate, subCreate, templateUserId: "" };
|
|
1238
|
-
|
|
1239
|
-
|
|
1241
|
+
let docRef;
|
|
1242
|
+
if (!docId) {
|
|
1243
|
+
docRef = await addDoc(collection(this.db, "staged-users"), onlyMeta );
|
|
1244
|
+
} else {
|
|
1245
|
+
docRef = doc(this.db, "staged-users", docId);
|
|
1246
|
+
await setDoc(docRef, onlyMeta);
|
|
1247
|
+
}
|
|
1240
1248
|
for (const role of roles) {
|
|
1241
1249
|
await this.storeUserRoles(docRef.id, role.collectionPath, role.role);
|
|
1242
1250
|
}
|
|
@@ -2395,4 +2403,4 @@ export const EdgeFirebase = class {
|
|
|
2395
2403
|
});
|
|
2396
2404
|
}
|
|
2397
2405
|
}
|
|
2398
|
-
};
|
|
2406
|
+
};
|
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)
|