@edgedev/firebase 2.1.77 → 2.1.79

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 +50 -0
  2. package/package.json +1 -1
package/edgeFirebase.ts CHANGED
@@ -923,9 +923,51 @@ export const EdgeFirebase = class {
923
923
  if (!stagedDocId) {
924
924
  stagedDocId = this.user.stagedDocId;
925
925
  }
926
+ const stagedUsers = this.state.users as Record<string, any>;
927
+ const existingMeta =
928
+ stagedDocId && stagedUsers[stagedDocId] && typeof stagedUsers[stagedDocId].meta === "object"
929
+ ? stagedUsers[stagedDocId].meta as Record<string, unknown>
930
+ : null;
931
+
932
+ const valuesEqual = (a: any, b: any): boolean => {
933
+ if (Object.is(a, b)) return true;
934
+ if (a === null || b === null) return false;
935
+ if (typeof a !== "object" || typeof b !== "object") return false;
936
+ const aIsArray = Array.isArray(a);
937
+ const bIsArray = Array.isArray(b);
938
+ if (aIsArray !== bIsArray) return false;
939
+ if (aIsArray) {
940
+ if (a.length !== b.length) return false;
941
+ for (let i = 0; i < a.length; i++) {
942
+ if (!valuesEqual(a[i], b[i])) return false;
943
+ }
944
+ return true;
945
+ }
946
+ const aKeys = Object.keys(a);
947
+ const bKeys = Object.keys(b);
948
+ if (aKeys.length !== bKeys.length) return false;
949
+ for (const key of aKeys) {
950
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
951
+ if (!valuesEqual(a[key], b[key])) return false;
952
+ }
953
+ return true;
954
+ };
955
+
926
956
  const updates: Record<string, unknown> = { uid: this.user.uid };
957
+ let changedKeys = 0;
927
958
  for (const [key, value] of Object.entries(meta)) {
959
+ if (existingMeta && valuesEqual(existingMeta[key], value)) {
960
+ continue;
961
+ }
928
962
  updates[`meta.${key}`] = value;
963
+ changedKeys++;
964
+ }
965
+ if (changedKeys === 0) {
966
+ return this.sendResponse({
967
+ success: true,
968
+ message: "line 664",
969
+ meta: {}
970
+ });
929
971
  }
930
972
  await updateDoc(doc(this.db, "staged-users/" + stagedDocId), updates);
931
973
  return this.sendResponse({
@@ -2135,6 +2177,14 @@ export const EdgeFirebase = class {
2135
2177
  cloneItem.doc_created_at = currentTime;
2136
2178
  }
2137
2179
  if (Object.prototype.hasOwnProperty.call(cloneItem, "docId")) {
2180
+ const canWriteCollection = await this.permissionCheck("write", collectionPath);
2181
+ if (!canWriteCollection) {
2182
+ return this.sendResponse({
2183
+ success: false,
2184
+ message: `You do not have permission to write to "${collectionPath}"`,
2185
+ meta: {}
2186
+ });
2187
+ }
2138
2188
  const canWrite = await this.permissionCheck("write", collectionPath + "/" + cloneItem.docId);
2139
2189
  if (!canWrite) {
2140
2190
  return this.sendResponse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.1.77",
3
+ "version": "2.1.79",
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": {