@edgedev/firebase 1.7.0 → 1.7.2

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
@@ -9,7 +9,7 @@ A Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication
9
9
  **[Firestore Basic Document Interactions](#firestore-Basic-document-interactions)**
10
10
  **[Firestore Snapshot Listeners](#firestore-snapshot-listeners)**
11
11
  **[Firestore Static Collection Data](#firestore-static-collection-data)**
12
- **[Await and response](#await-and-responses)**
12
+ **[Await and response](#responses)**
13
13
  **[Firestore Rules](#firestore-rules)**
14
14
 
15
15
  # Installation
@@ -125,6 +125,7 @@ exports.updateUser = functions.firestore.document('staged-users/{docId}').onUpda
125
125
  return shouldProcess(eventRef).then((process) => {
126
126
  if (process) {
127
127
  // Note: we can trust on newData.uid because we are checking in rules that it matches the auth.uid
128
+ // TODO: user might be invited to join another org with reg code.. if used when logged will combine new staged-user doc into first stage-user doc and sync to users.
128
129
  if (newData.userId) {
129
130
  const userRef = db.collection('users').doc(newData.userId)
130
131
  setUser(userRef, newData, oldData, stagedDocId).then(() => {
@@ -132,7 +133,7 @@ exports.updateUser = functions.firestore.document('staged-users/{docId}').onUpda
132
133
  })
133
134
  }
134
135
  else {
135
- if (newData.templateUserId) {
136
+ if (newData.templateUserId !== oldData.templateUserId) {
136
137
  newData.isTemplate = false
137
138
  const templateUserId = newData.templateUserId
138
139
  newData.meta = newData.templateMeta
@@ -748,6 +749,7 @@ Most functions will return a response that can be used.
748
749
 
749
750
  ```javascript
750
751
  const response = edgeFirebase.startSnapshot("things");
752
+ const response = await edgeFirebase.storeDoc("myItems", {name: "John Doe"});
751
753
  ```
752
754
 
753
755
  reponse:
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.0",
4
- "description": "Vue 3 / Nuxt 3 Plugin or Nuxt 3 global composable for firebase authentication and firestore.",
3
+ "version": "1.7.2",
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"