@edgedev/firebase 2.1.66 → 2.1.67
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 +68 -13
- package/package.json +1 -1
package/edgeFirebase.ts
CHANGED
|
@@ -728,27 +728,59 @@ export const EdgeFirebase = class {
|
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
731
|
+
// Build Firestore dotted-path updates so meta merges instead of replacing
|
|
732
|
+
const incomingMeta =
|
|
733
|
+
(Object.prototype.hasOwnProperty.call(userRegister, 'meta') &&
|
|
734
|
+
userRegister.meta && typeof userRegister.meta === 'object')
|
|
735
|
+
? (userRegister.meta as any)
|
|
736
|
+
: {};
|
|
737
|
+
|
|
738
|
+
// Identity fields written at top level
|
|
739
|
+
let stagedUserUpdate: {
|
|
740
|
+
userId?: string;
|
|
741
|
+
templateUserId?: string;
|
|
742
|
+
dynamicDocumentFieldValue?: string;
|
|
743
|
+
uid: string;
|
|
744
|
+
requestedOrgId?: string;
|
|
745
|
+
} = {
|
|
746
|
+
userId: response.user.uid,
|
|
747
|
+
uid: response.user.uid
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
let dottedUpdates: Record<string, any> = {};
|
|
751
|
+
|
|
738
752
|
if (user.isTemplate) {
|
|
739
|
-
|
|
753
|
+
// Template flow: keep template `meta` intact; write user fields as templateMeta.*
|
|
754
|
+
stagedUserUpdate = { templateUserId: response.user.uid, uid: response.user.uid };
|
|
755
|
+
|
|
740
756
|
if (Object.prototype.hasOwnProperty.call(userRegister, 'dynamicDocumentFieldValue')) {
|
|
741
|
-
stagedUserUpdate =
|
|
757
|
+
stagedUserUpdate.dynamicDocumentFieldValue = userRegister.dynamicDocumentFieldValue;
|
|
758
|
+
}
|
|
759
|
+
if (Object.prototype.hasOwnProperty.call(userRegister, 'requestedOrgId')) {
|
|
760
|
+
stagedUserUpdate.requestedOrgId = userRegister.requestedOrgId?.toLowerCase();
|
|
742
761
|
}
|
|
762
|
+
|
|
763
|
+
// Only write templateMeta.* dotted paths (do not touch meta)
|
|
764
|
+
dottedUpdates = { ...this.flattenObjectPaths(incomingMeta, 'templateMeta') };
|
|
765
|
+
} else {
|
|
766
|
+
// Non-template: merge user meta into existing meta using dotted paths
|
|
743
767
|
if (Object.prototype.hasOwnProperty.call(userRegister, 'requestedOrgId')) {
|
|
744
|
-
stagedUserUpdate =
|
|
768
|
+
stagedUserUpdate.requestedOrgId = userRegister.requestedOrgId?.toLowerCase();
|
|
745
769
|
}
|
|
770
|
+
dottedUpdates = { ...this.flattenObjectPaths(incomingMeta, 'meta') };
|
|
746
771
|
}
|
|
747
|
-
|
|
748
|
-
initRoleHelper
|
|
772
|
+
|
|
773
|
+
const initRoleHelper: any = { uid: response.user.uid };
|
|
774
|
+
initRoleHelper["edge-assignment-helper"] = { permissionType: "roles" };
|
|
749
775
|
this.user.loggingIn = true;
|
|
750
776
|
await setDoc(doc(this.db, "rule-helpers", response.user.uid), initRoleHelper);
|
|
751
|
-
|
|
777
|
+
|
|
778
|
+
// Firestore merges only the specified dotted fields inside meta/templateMeta.
|
|
779
|
+
await updateDoc(
|
|
780
|
+
doc(this.db, "staged-users/" + userRegister.registrationCode),
|
|
781
|
+
{ ...stagedUserUpdate, ...dottedUpdates }
|
|
782
|
+
);
|
|
783
|
+
|
|
752
784
|
this.logAnalyticsEvent("sign_up", { uid: response.user.uid});
|
|
753
785
|
return this.sendResponse({
|
|
754
786
|
success: true,
|
|
@@ -1023,6 +1055,29 @@ export const EdgeFirebase = class {
|
|
|
1023
1055
|
return response;
|
|
1024
1056
|
};
|
|
1025
1057
|
|
|
1058
|
+
private flattenObjectPaths = (obj: any, base: string): Record<string, any> => {
|
|
1059
|
+
const out: Record<string, any> = {};
|
|
1060
|
+
const walk = (cur: any, prefix: string) => {
|
|
1061
|
+
if (cur === null || cur === undefined) {
|
|
1062
|
+
out[prefix] = cur;
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (typeof cur !== 'object' || Array.isArray(cur)) {
|
|
1066
|
+
out[prefix] = cur;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
for (const [k, v] of Object.entries(cur)) {
|
|
1070
|
+
walk(v, `${prefix}.${k}`);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
if (obj && typeof obj === 'object') {
|
|
1074
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
1075
|
+
walk(v, `${base}.${k}`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return out;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1026
1081
|
private setRuleHelper = async(collectionPath: string, action): Promise<void> => {
|
|
1027
1082
|
const collection = collectionPath.replaceAll("-", "/").split("/");
|
|
1028
1083
|
let ruleKey = collectionPath.replaceAll("/", "-");
|