@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.
Files changed (2) hide show
  1. package/edgeFirebase.ts +68 -13
  2. package/package.json +1 -1
package/edgeFirebase.ts CHANGED
@@ -728,27 +728,59 @@ export const EdgeFirebase = class {
728
728
  });
729
729
  }
730
730
 
731
- let metaUpdate = {};
732
- if (Object.prototype.hasOwnProperty.call(userRegister, 'meta')) {
733
- metaUpdate = userRegister.meta;
734
- }else{
735
- metaUpdate = user.meta;
736
- }
737
- let stagedUserUpdate: {userId?: string, templateUserId?: string, dynamicDocumentFieldValue?: string, uid: string, meta: unknown, templateMeta?: unknown, requestedOrgId?: unknown} = {userId: response.user.uid, uid: response.user.uid, meta: metaUpdate}
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
- stagedUserUpdate = {templateUserId: response.user.uid, uid: response.user.uid, meta: user.meta, templateMeta: metaUpdate}
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 = {templateUserId: response.user.uid, uid: response.user.uid, dynamicDocumentFieldValue: userRegister.dynamicDocumentFieldValue, meta: user.meta, templateMeta: metaUpdate}
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 = {templateUserId: response.user.uid, uid: response.user.uid, dynamicDocumentFieldValue: userRegister.dynamicDocumentFieldValue, meta: user.meta, templateMeta: metaUpdate, requestedOrgId: userRegister.requestedOrgId.toLowerCase()}
768
+ stagedUserUpdate.requestedOrgId = userRegister.requestedOrgId?.toLowerCase();
745
769
  }
770
+ dottedUpdates = { ...this.flattenObjectPaths(incomingMeta, 'meta') };
746
771
  }
747
- const initRoleHelper = {uid: response.user.uid}
748
- initRoleHelper["edge-assignment-helper"] = {permissionType: "roles"}
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
- await updateDoc(doc(this.db, "staged-users/" + userRegister.registrationCode), stagedUserUpdate)
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("/", "-");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.1.66",
3
+ "version": "2.1.67",
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": {