@edgedev/firebase 2.0.9 → 2.0.11

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 CHANGED
@@ -338,7 +338,7 @@ export const EdgeFirebase = class {
338
338
  this.user.specialPermissions = specialPermissions;
339
339
  }
340
340
  );
341
- this.unsubscibe.userMeta = metaUnsubscribe;
341
+ this.unsubscribe.userMeta = metaUnsubscribe;
342
342
  };
343
343
 
344
344
  private startCollectionPermissionsSync = async (): Promise<void> => {
@@ -397,7 +397,7 @@ export const EdgeFirebase = class {
397
397
  });
398
398
  this.state.collectionPermissions = items;
399
399
  });
400
- this.unsubscibe['collection-data'] = unsubscribe
400
+ this.unsubscribe['collection-data'] = unsubscribe
401
401
  }
402
402
 
403
403
  private ruleHelperReset = async (): Promise<void> => {
@@ -407,7 +407,8 @@ export const EdgeFirebase = class {
407
407
  }
408
408
 
409
409
  private startUserMetaSync = async (docSnap): Promise<void> => {
410
- await this.ruleHelperReset();
410
+ // Took this out because if another client is logged in, it breaks the other client
411
+ // await this.ruleHelperReset();
411
412
  await this.startCollectionPermissionsSync()
412
413
  await this.initUserMetaPermissions(docSnap);
413
414
  this.user.loggedIn = true;
@@ -1171,10 +1172,10 @@ export const EdgeFirebase = class {
1171
1172
  };
1172
1173
 
1173
1174
  public logOut = (): void => {
1174
- for (const key of Object.keys(this.unsubscibe)) {
1175
- if (this.unsubscibe[key] instanceof Function) {
1176
- this.unsubscibe[key]();
1177
- this.unsubscibe[key] = null;
1175
+ for (const key of Object.keys(this.unsubscribe)) {
1176
+ if (this.unsubscribe[key] instanceof Function) {
1177
+ this.unsubscribe[key]();
1178
+ this.unsubscribe[key] = null;
1178
1179
  this.data[key] = {};
1179
1180
  }
1180
1181
  }
@@ -1229,7 +1230,7 @@ export const EdgeFirebase = class {
1229
1230
  // Simple Store Items (add matching key per firebase collection)
1230
1231
  public data: CollectionDataObject = reactive({});
1231
1232
 
1232
- public unsubscibe: CollectionUnsubscribeObject = reactive({});
1233
+ public unsubscribe: CollectionUnsubscribeObject = reactive({});
1233
1234
 
1234
1235
  public user: UserDataObject = reactive({
1235
1236
  uid: null,
@@ -1502,7 +1503,7 @@ export const EdgeFirebase = class {
1502
1503
  const canRead = await this.permissionCheck("read", collectionPath + '/' + docId);
1503
1504
  this.data[collectionPath + '/' + docId] = {};
1504
1505
  this.stopSnapshot(collectionPath + '/' + docId);
1505
- this.unsubscibe[collectionPath + '/' + docId] = null;
1506
+ this.unsubscribe[collectionPath + '/' + docId] = null;
1506
1507
  if (canRead) {
1507
1508
  const docRef = doc(this.db, collectionPath, docId);
1508
1509
 
@@ -1544,7 +1545,7 @@ export const EdgeFirebase = class {
1544
1545
  meta: {}
1545
1546
  }));
1546
1547
  });
1547
- this.unsubscibe[collectionPath + '/' + docId] = unsubscribe;
1548
+ this.unsubscribe[collectionPath + '/' + docId] = unsubscribe;
1548
1549
  });
1549
1550
  } else {
1550
1551
  return this.sendResponse({
@@ -1565,10 +1566,9 @@ export const EdgeFirebase = class {
1565
1566
  const canRead = await this.permissionCheck("read", collectionPath);
1566
1567
  this.data[collectionPath] = {};
1567
1568
  this.stopSnapshot(collectionPath);
1568
- this.unsubscibe[collectionPath] = null;
1569
+ this.unsubscribe[collectionPath] = null;
1569
1570
  if (canRead) {
1570
1571
  const q = this.getQuery(collectionPath, queryList, orderList, max);
1571
-
1572
1572
  return new Promise<actionResponse>((resolve, reject) => {
1573
1573
  let firstRun = true;
1574
1574
  const unsubscribe = onSnapshot(q, (querySnapshot) => {
@@ -1579,7 +1579,6 @@ export const EdgeFirebase = class {
1579
1579
  items[doc.id] = item;
1580
1580
  });
1581
1581
  this.data[collectionPath] = items;
1582
- this.unsubscibe[collectionPath] = unsubscribe;
1583
1582
 
1584
1583
  // Only resolve or reject the Promise on first run of onSnapshot
1585
1584
  if(firstRun) {
@@ -1607,6 +1606,7 @@ export const EdgeFirebase = class {
1607
1606
  meta: {}
1608
1607
  }));
1609
1608
  });
1609
+ this.unsubscribe[collectionPath] = unsubscribe;
1610
1610
  });
1611
1611
  } else {
1612
1612
  return this.sendResponse({
@@ -1639,7 +1639,7 @@ export const EdgeFirebase = class {
1639
1639
  collectionPath.replaceAll('/', '-')
1640
1640
  )
1641
1641
  )
1642
- const unsubscibe = await onSnapshot(q, (querySnapshot) => {
1642
+ const unsubscribe = await onSnapshot(q, (querySnapshot) => {
1643
1643
  const items = {};
1644
1644
  querySnapshot.forEach((doc) => {
1645
1645
  const user = doc.data();
@@ -1679,7 +1679,7 @@ export const EdgeFirebase = class {
1679
1679
  });
1680
1680
  this.state.users = items;
1681
1681
  });
1682
- this.unsubscibe["staged-users"] = unsubscibe;
1682
+ this.unsubscribe["staged-users"] = unsubscribe;
1683
1683
  } else {
1684
1684
  const q = query(
1685
1685
  collection(this.db, "public-users"),
@@ -1689,7 +1689,7 @@ export const EdgeFirebase = class {
1689
1689
  collectionPath.replaceAll('/', '-')
1690
1690
  )
1691
1691
  )
1692
- const unsubscibe = await onSnapshot(q, (querySnapshot) => {
1692
+ const unsubscribe = await onSnapshot(q, (querySnapshot) => {
1693
1693
  const items = {};
1694
1694
  querySnapshot.forEach((doc) => {
1695
1695
  const user = doc.data();
@@ -1703,7 +1703,7 @@ export const EdgeFirebase = class {
1703
1703
  });
1704
1704
  this.state.users = items;
1705
1705
  });
1706
- this.unsubscibe["staged-users"] = unsubscibe;
1706
+ this.unsubscribe["staged-users"] = unsubscribe;
1707
1707
  }
1708
1708
  }
1709
1709
  };
@@ -2090,9 +2090,9 @@ export const EdgeFirebase = class {
2090
2090
  };
2091
2091
 
2092
2092
  public stopSnapshot = (collectionPath: string): void => {
2093
- if (this.unsubscibe[collectionPath] instanceof Function) {
2094
- this.unsubscibe[collectionPath]();
2095
- this.unsubscibe[collectionPath] = null;
2093
+ if (this.unsubscribe[collectionPath] instanceof Function) {
2094
+ this.unsubscribe[collectionPath]();
2095
+ this.unsubscribe[collectionPath] = null;
2096
2096
  }
2097
2097
  };
2098
2098
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
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": {
@@ -0,0 +1,10 @@
1
+ VITE_FIREBASE_API_KEY=
2
+ VITE_FIREBASE_AUTH_DOMAIN=
3
+ VITE_FIREBASE_PROJECT_ID=
4
+ VITE_FIREBASE_STORAGE_BUCKET=
5
+ VITE_FIREBASE_MESSAGING_SENDER_ID=
6
+ VITE_FIREBASE_APP_ID=
7
+ VITE_FIREBASE_MEASUREMENT_ID=
8
+ VITE_FIREBASE_EMULATOR_AUTH=9099
9
+ VITE_FIREBASE_EMULATOR_FIRESTORE=8080
10
+ VITE_FIREBASE_EMULATOR_FUNCTIONS=5001
@@ -0,0 +1,10 @@
1
+ VITE_FIREBASE_API_KEY=
2
+ VITE_FIREBASE_AUTH_DOMAIN=
3
+ VITE_FIREBASE_PROJECT_ID=
4
+ VITE_FIREBASE_STORAGE_BUCKET=
5
+ VITE_FIREBASE_MESSAGING_SENDER_ID=
6
+ VITE_FIREBASE_APP_ID=
7
+ VITE_FIREBASE_MEASUREMENT_ID=
8
+ VITE_FIREBASE_EMULATOR_AUTH=
9
+ VITE_FIREBASE_EMULATOR_FIRESTORE=
10
+ VITE_FIREBASE_EMULATOR_FUNCTIONS=
@@ -21,23 +21,23 @@ exports.topicQueue = onSchedule({ schedule: 'every 1 minutes', timeoutSeconds: 1
21
21
  if (!docSnapshot.exists) {
22
22
  throw new Error('Document does not exist!')
23
23
  }
24
- const emailData = docSnapshot.data()
25
- const emailTimestamp = emailData.timestamp ? emailData.timestamp.toMillis() : 0
26
- const delayTimestamp = emailData.minuteDelay ? emailTimestamp + emailData.minuteDelay * 60 * 1000 : 0
24
+ const docData = docSnapshot.data()
25
+ const emailTimestamp = docData.timestamp ? docData.timestamp.toMillis() : 0
26
+ const delayTimestamp = docData.minuteDelay ? emailTimestamp + docData.minuteDelay * 60 * 1000 : 0
27
27
  const currentTimestamp = Date.now()
28
28
  // Check if current time is beyond the timestamp + minuteDelay, or if timestamp or minuteDelay is not set
29
- if (emailTimestamp > currentTimestamp || currentTimestamp >= delayTimestamp || !emailData.timestamp || !emailData.minuteDelay) {
29
+ if (emailTimestamp > currentTimestamp || currentTimestamp >= delayTimestamp || !docData.timestamp || !docData.minuteDelay) {
30
30
  // Check if topic and payload exist and are not empty
31
- if (emailData.topic && emailData.payload && emailData.topic.trim() !== '' && emailData.payload.trim() !== '') {
31
+ if (docData.topic && docData.payload && typeof docData.payload === 'object' && docData.topic.trim() !== '') {
32
32
  try {
33
- await pubsub.topic(emailData.topic).publishMessage({ data: Buffer.from(JSON.stringify(emailData.payload)) })
33
+ await pubsub.topic(docData.topic).publishMessage({ data: Buffer.from(JSON.stringify(docData.payload)) })
34
34
  // Delete the document after successfully publishing the message
35
35
  transaction.delete(doc.ref)
36
36
  }
37
37
  catch (error) {
38
- console.error(`Error publishing message to topic ${emailData.topic}:`, error)
38
+ console.error(`Error publishing message to topic ${docData.topic}:`, error)
39
39
  // Increment retry count and set new delay
40
- const retryCount = emailData.retry ? emailData.retry + 1 : 1
40
+ const retryCount = docData.retry ? docData.retry + 1 : 1
41
41
  if (retryCount <= 3) {
42
42
  const minuteDelay = retryCount === 1 ? 1 : retryCount === 2 ? 10 : 30
43
43
  transaction.update(doc.ref, { retry: retryCount, minuteDelay })
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "functions",
3
+ "description": "Cloud Functions for Firebase",
4
+ "scripts": {
5
+ "serve": "firebase emulators:start --only functions",
6
+ "shell": "firebase functions:shell",
7
+ "start": "npm run shell",
8
+ "deploy": "firebase deploy --only functions",
9
+ "logs": "firebase functions:log"
10
+ },
11
+ "engines": {
12
+ "node": "16"
13
+ },
14
+ "main": "index.js",
15
+ "dependencies": {
16
+ "@google-cloud/pubsub": "^4.0.6",
17
+ "dotenv": "^16.3.1",
18
+ "firebase-admin": "^10.0.2",
19
+ "firebase-functions": "^4.5.0",
20
+ "twilio": "^4.18.0"
21
+ },
22
+ "devDependencies": {
23
+ "firebase-functions-test": "^0.2.0"
24
+ },
25
+ "private": true
26
+ }
@@ -30,12 +30,27 @@ fi
30
30
  cp ./src/edgeFirebase.js "$project_root/functions/edgeFirebase.js"
31
31
  cp ./src/config.js "$project_root/functions/config.js"
32
32
 
33
- if [ ! -f "$project_root/.env.dev" ]; then
34
- cp ./src/.env.dev "$project_root/.env.dev"
33
+ if [ ! -f "$project_root/functions/.env.dev" ]; then
34
+ cp ./src/.env.dev "$project_root/functions/.env.dev"
35
35
  fi
36
36
 
37
- if [ ! -f "$project_root/.env.prod" ]; then
38
- cp ./src/.env.prod "$project_root/.env.prod"
37
+ if [ ! -f "$project_root/functions/.env.prod" ]; then
38
+ cp ./src/.env.prod "$project_root/functions/.env.prod"
39
+ fi
40
+
41
+ if [ ! -f "$project_root/.env.development" ]; then
42
+ cp ./src/.env.dev "$project_root/.env.development"
43
+ fi
44
+
45
+ if [ ! -f "$project_root/.env.production" ]; then
46
+ cp ./src/.env.prod "$project_root/functions/.env.production"
47
+ fi
48
+
49
+ if [ ! -f "$project_root/functions/package.json" ]; then
50
+ cp ./src/package.json "$project_root/functions/package.json"
51
+ cd "$project_root/functions"
52
+ npm install --no-audit --silent
53
+ cd "$project_root"
39
54
  fi
40
55
 
41
56
  [ "$(tail -c1 $project_root/functions/index.js)" != "" ] && echo "" >> "$project_root/functions/index.js"