@edgedev/firebase 1.9.2 → 1.9.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgedev/firebase",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
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": {
package/src/functions.js CHANGED
@@ -1,4 +1,39 @@
1
1
  // START @edge/firebase functions
2
+
3
+ exports.initFirestore = functions.https.onCall(async (data, context) => {
4
+ // checks to see of the collections 'collection-data' and 'staged-users' exist if not will seed them with data
5
+ const collectionData = await db.collection('collection-data').get()
6
+ const stagedUsers = await db.collection('staged-users').get()
7
+ if (collectionData.empty) {
8
+ // create a document with the id of '-' and one called '-default-':
9
+ const admin = { assign: true, delete: true, read: true, write: true }
10
+ const editor = { assign: false, delete: true, read: true, write: true }
11
+ const writer = { assign: false, delete: false, read: true, write: true }
12
+ const user = { assign: false, delete: false, read: true, write: false }
13
+ await db.collection('collection-data').doc('-').set({ admin, editor, writer, user })
14
+ await db.collection('collection-data').doc('-default-').set({ admin, editor, writer, user })
15
+ }
16
+ if (stagedUsers.empty) {
17
+ const templateUser = {
18
+ docId: 'organization-registration-template',
19
+ isTemplate: true,
20
+ meta: {
21
+ name: 'Organization Registration Template',
22
+ },
23
+ subCreate: {
24
+ documentStructure: {
25
+ name: '',
26
+ },
27
+ dynamicDocumentField: 'name',
28
+ role: 'admin',
29
+ rootPath: 'organizations',
30
+ },
31
+ userId: '',
32
+ }
33
+ await db.collection('staged-users').doc('organization-registration-template').set(templateUser)
34
+ }
35
+ })
36
+
2
37
  exports.removeNonRegisteredUser = functions.https.onCall(async (data, context) => {
3
38
  if (data.uid === context.auth.uid) {
4
39
  const stagedUser = await db.collection('staged-users').doc(data.docId).get()
@@ -93,7 +128,6 @@ exports.updateUser = functions.firestore.document('staged-users/{docId}').onUpda
93
128
  return shouldProcess(eventRef).then((process) => {
94
129
  if (process) {
95
130
  // Note: we can trust on newData.uid because we are checking in rules that it matches the auth.uid
96
- // 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.
97
131
  if (newData.userId) {
98
132
  const userRef = db.collection('users').doc(newData.userId)
99
133
  setUser(userRef, newData, oldData, stagedDocId).then(() => {
@@ -22,12 +22,12 @@ awk '/\/\/ #EDGE FIREBASE RULES START/,/\/\/ #EDGE FIREBASE RULES END/' ./src/fi
22
22
  sed -e '1s/^/\/\/ #EDGE FIREBASE RULES START\n/' -e '$s/$/\n\/\/ #EDGE FIREBASE RULES END/' \
23
23
  >> "$project_root/firestore.rules";
24
24
 
25
- if [ ! -f ./functions/index.js ]; then
26
- mkdir -p ./functions
25
+ if [ ! -f "$project_root/functions/index.js" ]; then
26
+ mkdir -p "$project_root/functions"
27
27
  echo "const functions = require('firebase-functions');" > ./functions/index.js;
28
28
  echo "const admin = require('firebase-admin');" >> ./functions/index.js;
29
29
  echo "admin.initializeApp();" >> ./functions/index.js;
30
- echo "const db = admin.firestore();" >> ./functions/index.js;
30
+ echo "const db = admin.firestore();" >> "$project_root/functions/index.js";
31
31
  fi
32
32
 
33
33
  [ "$(tail -c1 $project_root/functions/index.js)" != "" ] && echo "" >> "$project_root/functions/index.js"