@edgedev/firebase 2.1.65 → 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 +83 -16
- 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;
|
|
742
758
|
}
|
|
743
759
|
if (Object.prototype.hasOwnProperty.call(userRegister, 'requestedOrgId')) {
|
|
744
|
-
stagedUserUpdate =
|
|
760
|
+
stagedUserUpdate.requestedOrgId = userRegister.requestedOrgId?.toLowerCase();
|
|
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
|
|
767
|
+
if (Object.prototype.hasOwnProperty.call(userRegister, 'requestedOrgId')) {
|
|
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,
|
|
@@ -853,13 +885,11 @@ export const EdgeFirebase = class {
|
|
|
853
885
|
|
|
854
886
|
|
|
855
887
|
|
|
856
|
-
public setUserMeta = async (meta: Meta, userId = ''): Promise<actionResponse> => {
|
|
857
|
-
let stagedDocId = this.user.stagedDocId;
|
|
888
|
+
public setUserMeta = async (meta: Meta, userId = '', stagedDocId = ''): Promise<actionResponse> => {
|
|
858
889
|
if (userId) {
|
|
859
890
|
const users = Object.values(this.state.users) as User[];
|
|
860
891
|
const user = users.find((u) => u.userId === userId);
|
|
861
892
|
if (user) {
|
|
862
|
-
console.log(user)
|
|
863
893
|
stagedDocId = user.docId;
|
|
864
894
|
} else {
|
|
865
895
|
return this.sendResponse({
|
|
@@ -869,6 +899,20 @@ export const EdgeFirebase = class {
|
|
|
869
899
|
});
|
|
870
900
|
}
|
|
871
901
|
}
|
|
902
|
+
if (!userId && stagedDocId) {
|
|
903
|
+
const users = Object.values(this.state.users) as User[];
|
|
904
|
+
const user = users.find((u) => u.docId === stagedDocId);
|
|
905
|
+
if (!user) {
|
|
906
|
+
return this.sendResponse({
|
|
907
|
+
success: false,
|
|
908
|
+
message: "You don't have access to change this user.",
|
|
909
|
+
meta: {}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (!stagedDocId) {
|
|
914
|
+
stagedDocId = this.user.stagedDocId;
|
|
915
|
+
}
|
|
872
916
|
for (const [key, value] of Object.entries(meta)) {
|
|
873
917
|
await updateDoc(doc(this.db, "staged-users/" + stagedDocId), {
|
|
874
918
|
["meta." + key]: value, uid: this.user.uid
|
|
@@ -1011,6 +1055,29 @@ export const EdgeFirebase = class {
|
|
|
1011
1055
|
return response;
|
|
1012
1056
|
};
|
|
1013
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
|
+
|
|
1014
1081
|
private setRuleHelper = async(collectionPath: string, action): Promise<void> => {
|
|
1015
1082
|
const collection = collectionPath.replaceAll("-", "/").split("/");
|
|
1016
1083
|
let ruleKey = collectionPath.replaceAll("/", "-");
|