@edgedev/firebase 1.7.1 → 1.7.3

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/README.md CHANGED
@@ -132,7 +132,7 @@ exports.updateUser = functions.firestore.document('staged-users/{docId}').onUpda
132
132
  })
133
133
  }
134
134
  else {
135
- if (newData.templateUserId) {
135
+ if (newData.templateUserId !== oldData.templateUserId) {
136
136
  newData.isTemplate = false
137
137
  const templateUserId = newData.templateUserId
138
138
  newData.meta = newData.templateMeta
@@ -180,9 +180,6 @@ exports.updateUser = functions.firestore.document('staged-users/{docId}').onUpda
180
180
  })
181
181
 
182
182
  function setUser(userRef, newData, oldData, stagedDocId) {
183
- // IT's OK If "users" doesn't match exactly matched "staged-users" because this is only preventing
184
- // writing from outside the @edgdev/firebase functions, so discrepancies will be rare since
185
- // the package will prevent before it gets this far.
186
183
  return userRef.get().then((user) => {
187
184
  let userUpdate = { meta: newData.meta, stagedDocId }
188
185
 
package/edgeFirebase.ts CHANGED
@@ -781,7 +781,7 @@ export const EdgeFirebase = class {
781
781
  }
782
782
  }
783
783
 
784
- const onlyMeta = { meta: userMeta.meta, userId: "", uid: this.user.uid, roles:{}, specialPermissions:{}, isTemplate, subCreate };
784
+ const onlyMeta = { meta: userMeta.meta, userId: "", uid: this.user.uid, roles:{}, specialPermissions:{}, isTemplate, subCreate, templateUserId: "" };
785
785
 
786
786
  const docRef = await addDoc(collection(this.db, "staged-users"), onlyMeta );
787
787
  for (const role of roles) {
@@ -1116,6 +1116,44 @@ export const EdgeFirebase = class {
1116
1116
  );
1117
1117
  };
1118
1118
 
1119
+ // TODO: Document this and how the data is stored collectionPath + '/' + docId...
1120
+ // Also stopSnapshot is by collectionPath + '/' + docId
1121
+ public startDocumentSnapshot = async (
1122
+ collectionPath: string,
1123
+ docId: string
1124
+ ): Promise<actionResponse> => {
1125
+ console.log(collectionPath)
1126
+ console.log(docId)
1127
+ const canRead = await this.permissionCheck("read", collectionPath + '/' + docId);
1128
+ this.data[collectionPath + '/' + docId] = {};
1129
+ this.stopSnapshot(collectionPath + '/' + docId);
1130
+ this.unsubscibe[collectionPath + '/' + docId] = null;
1131
+ if (canRead) {
1132
+ const docRef = doc(this.db, collectionPath, docId);
1133
+ const unsubscribe = onSnapshot(docRef, (doc) => {
1134
+ if (doc.exists()) {
1135
+ const item = doc.data();
1136
+ item.docId = doc.id;
1137
+ this.data[collectionPath + '/' + docId] = item;
1138
+ } else {
1139
+ this.data[collectionPath + '/' + docId] = {};
1140
+ }
1141
+ });
1142
+ this.unsubscibe[collectionPath + '/' + docId] = unsubscribe;
1143
+ return this.sendResponse({
1144
+ success: true,
1145
+ message: "",
1146
+ meta: {}
1147
+ });
1148
+ } else {
1149
+ return this.sendResponse({
1150
+ success: false,
1151
+ message: `You do not have permission to read from "${collectionPath}"`,
1152
+ meta: {}
1153
+ });
1154
+ }
1155
+ };
1156
+
1119
1157
  public startSnapshot = async(
1120
1158
  collectionPath: string,
1121
1159
  queryList: FirestoreQuery[] = [],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.7.1",
4
- "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
3
+ "version": "1.7.3",
4
+ "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 plugin for firebase authentication and firestore.",
5
5
  "main": "index.ts",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"