mirror of
https://github.com/rjNemo/devbook_ts
synced 2026-06-06 02:36:39 +00:00
init Firebase
This commit is contained in:
parent
9e30322ffc
commit
7a870ce878
12 changed files with 2862 additions and 0 deletions
5
.firebaserc
Normal file
5
.firebaserc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"projects": {
|
||||
"default": "devprojects-4749c"
|
||||
}
|
||||
}
|
||||
29
firebase.json
Normal file
29
firebase.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"firestore": {
|
||||
"rules": "firestore.rules",
|
||||
"indexes": "firestore.indexes.json"
|
||||
},
|
||||
"functions": {
|
||||
"predeploy": [
|
||||
"npm --prefix \"$RESOURCE_DIR\" run lint",
|
||||
"npm --prefix \"$RESOURCE_DIR\" run build"
|
||||
]
|
||||
},
|
||||
"hosting": {
|
||||
"public": "build",
|
||||
"ignore": [
|
||||
"firebase.json",
|
||||
"**/.*",
|
||||
"**/node_modules/**"
|
||||
],
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "**",
|
||||
"destination": "/index.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"storage": {
|
||||
"rules": "storage.rules"
|
||||
}
|
||||
}
|
||||
117
firestore.indexes.json
Normal file
117
firestore.indexes.json
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"indexes": [
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "category",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "avgRating",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "category",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "numRatings",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "category",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "price",
|
||||
"order": "ASCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "city",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "avgRating",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "city",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "numRatings",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "city",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "price",
|
||||
"order": "ASCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "price",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "avgRating",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"collectionGroup": "restaurants",
|
||||
"queryScope": "COLLECTION",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "price",
|
||||
"order": "ASCENDING"
|
||||
},
|
||||
{
|
||||
"fieldPath": "numRatings",
|
||||
"order": "DESCENDING"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"fieldOverrides": []
|
||||
}
|
||||
75
firestore.rules
Normal file
75
firestore.rules
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
rules_version = '2';
|
||||
service cloud.firestore {
|
||||
match /databases/{database}/documents {
|
||||
// Restaurants:
|
||||
// - Authenticated user can read
|
||||
// - Authenticated user can create/update (for demo)
|
||||
// - Validate updates
|
||||
// - Deletes are not allowed
|
||||
match /restaurants/{restaurantId} {
|
||||
allow read, create: if request.auth != null;
|
||||
allow update: if request.auth != null
|
||||
&& request.resource.data.name == resource.data.name
|
||||
allow delete: if false;
|
||||
|
||||
// Ratings:
|
||||
// - Authenticated user can read
|
||||
// - Authenticated user can create if userId matches
|
||||
// - Deletes and updates are not allowed
|
||||
match /ratings/{ratingId} {
|
||||
allow read: if request.auth != null;
|
||||
allow create: if request.auth != null
|
||||
&& request.resource.data.userId == request.auth.uid;
|
||||
allow update, delete: if false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// MealPlannerUsers:
|
||||
// - Anyone can read
|
||||
// - Authenticated users can create and edit their account
|
||||
// - Deletes are not allowed
|
||||
match /mealPlannerUsers/{userID} {
|
||||
allow read: if true;
|
||||
allow create, update, write: if true;
|
||||
allow delete: if false;
|
||||
|
||||
// Favs:
|
||||
// - Anyone can read
|
||||
// - Authenticated users can create and edit their account
|
||||
// - Deletes are not allowed
|
||||
match /favs/{favID} {
|
||||
allow read, create, update, write: if true;
|
||||
allow delete: if false;
|
||||
}
|
||||
}
|
||||
|
||||
// Messages:
|
||||
// - Anyone can read.
|
||||
// - Authenticated users can add and edit messages.
|
||||
// - Validation: Check name is same as auth token and text length below 300 char or that imageUrl is a URL.
|
||||
// - Deletes are not allowed.
|
||||
match /messages/{messageId} {
|
||||
allow read;
|
||||
allow create, update: if request.auth != null
|
||||
&& request.resource.data.name == request.auth.token.name
|
||||
&& (request.resource.data.text is string
|
||||
&& request.resource.data.text.size() <= 300
|
||||
|| request.resource.data.imageUrl is string
|
||||
&& request.resource.data.imageUrl.matches('https?://.*'));
|
||||
allow delete: if false;
|
||||
}
|
||||
|
||||
// FcmTokens:
|
||||
// - anyone can save its token
|
||||
// - access is forbidden
|
||||
match /fcmTokens/{tokenID} {
|
||||
allow write;
|
||||
allow read: if false;
|
||||
}
|
||||
// Users: DevBook app
|
||||
match /users/{userID} {
|
||||
allow read,write :if true;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
functions/.gitignore
vendored
Normal file
8
functions/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
## Compiled JavaScript files
|
||||
**/*.js
|
||||
**/*.js.map
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
node_modules/
|
||||
2394
functions/package-lock.json
generated
Normal file
2394
functions/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
26
functions/package.json
Normal file
26
functions/package.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "functions",
|
||||
"scripts": {
|
||||
"lint": "tslint --project tsconfig.json",
|
||||
"build": "tsc",
|
||||
"serve": "npm run build && firebase emulators:start --only functions",
|
||||
"shell": "npm run build && firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log"
|
||||
},
|
||||
"engines": {
|
||||
"node": "8"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"firebase-admin": "^8.10.0",
|
||||
"firebase-functions": "^3.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tslint": "^5.12.0",
|
||||
"typescript": "^3.2.2",
|
||||
"firebase-functions-test": "^0.2.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
8
functions/src/index.ts
Normal file
8
functions/src/index.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import * as functions from 'firebase-functions';
|
||||
|
||||
// // Start writing Firebase Functions
|
||||
// // https://firebase.google.com/docs/functions/typescript
|
||||
//
|
||||
// export const helloWorld = functions.https.onRequest((request, response) => {
|
||||
// response.send("Hello from Firebase!");
|
||||
// });
|
||||
15
functions/tsconfig.json
Normal file
15
functions/tsconfig.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"outDir": "lib",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"target": "es2017"
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
115
functions/tslint.json
Normal file
115
functions/tslint.json
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
{
|
||||
"rules": {
|
||||
// -- Strict errors --
|
||||
// These lint rules are likely always a good idea.
|
||||
|
||||
// Force function overloads to be declared together. This ensures readers understand APIs.
|
||||
"adjacent-overload-signatures": true,
|
||||
|
||||
// Do not allow the subtle/obscure comma operator.
|
||||
"ban-comma-operator": true,
|
||||
|
||||
// Do not allow internal modules or namespaces . These are deprecated in favor of ES6 modules.
|
||||
"no-namespace": true,
|
||||
|
||||
// Do not allow parameters to be reassigned. To avoid bugs, developers should instead assign new values to new vars.
|
||||
"no-parameter-reassignment": true,
|
||||
|
||||
// Force the use of ES6-style imports instead of /// <reference path=> imports.
|
||||
"no-reference": true,
|
||||
|
||||
// Do not allow type assertions that do nothing. This is a big warning that the developer may not understand the
|
||||
// code currently being edited (they may be incorrectly handling a different type case that does not exist).
|
||||
"no-unnecessary-type-assertion": true,
|
||||
|
||||
// Disallow nonsensical label usage.
|
||||
"label-position": true,
|
||||
|
||||
// Disallows the (often typo) syntax if (var1 = var2). Replace with if (var2) { var1 = var2 }.
|
||||
"no-conditional-assignment": true,
|
||||
|
||||
// Disallows constructors for primitive types (e.g. new Number('123'), though Number('123') is still allowed).
|
||||
"no-construct": true,
|
||||
|
||||
// Do not allow super() to be called twice in a constructor.
|
||||
"no-duplicate-super": true,
|
||||
|
||||
// Do not allow the same case to appear more than once in a switch block.
|
||||
"no-duplicate-switch-case": true,
|
||||
|
||||
// Do not allow a variable to be declared more than once in the same block. Consider function parameters in this
|
||||
// rule.
|
||||
"no-duplicate-variable": [true, "check-parameters"],
|
||||
|
||||
// Disallows a variable definition in an inner scope from shadowing a variable in an outer scope. Developers should
|
||||
// instead use a separate variable name.
|
||||
"no-shadowed-variable": true,
|
||||
|
||||
// Empty blocks are almost never needed. Allow the one general exception: empty catch blocks.
|
||||
"no-empty": [true, "allow-empty-catch"],
|
||||
|
||||
// Functions must either be handled directly (e.g. with a catch() handler) or returned to another function.
|
||||
// This is a major source of errors in Cloud Functions and the team strongly recommends leaving this rule on.
|
||||
"no-floating-promises": true,
|
||||
|
||||
// Do not allow any imports for modules that are not in package.json. These will almost certainly fail when
|
||||
// deployed.
|
||||
"no-implicit-dependencies": true,
|
||||
|
||||
// The 'this' keyword can only be used inside of classes.
|
||||
"no-invalid-this": true,
|
||||
|
||||
// Do not allow strings to be thrown because they will not include stack traces. Throw Errors instead.
|
||||
"no-string-throw": true,
|
||||
|
||||
// Disallow control flow statements, such as return, continue, break, and throw in finally blocks.
|
||||
"no-unsafe-finally": true,
|
||||
|
||||
// Expressions must always return a value. Avoids common errors like const myValue = functionReturningVoid();
|
||||
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
|
||||
|
||||
// Disallow duplicate imports in the same file.
|
||||
"no-duplicate-imports": true,
|
||||
|
||||
|
||||
// -- Strong Warnings --
|
||||
// These rules should almost never be needed, but may be included due to legacy code.
|
||||
// They are left as a warning to avoid frustration with blocked deploys when the developer
|
||||
// understand the warning and wants to deploy anyway.
|
||||
|
||||
// Warn when an empty interface is defined. These are generally not useful.
|
||||
"no-empty-interface": {"severity": "warning"},
|
||||
|
||||
// Warn when an import will have side effects.
|
||||
"no-import-side-effect": {"severity": "warning"},
|
||||
|
||||
// Warn when variables are defined with var. Var has subtle meaning that can lead to bugs. Strongly prefer const for
|
||||
// most values and let for values that will change.
|
||||
"no-var-keyword": {"severity": "warning"},
|
||||
|
||||
// Prefer === and !== over == and !=. The latter operators support overloads that are often accidental.
|
||||
"triple-equals": {"severity": "warning"},
|
||||
|
||||
// Warn when using deprecated APIs.
|
||||
"deprecation": {"severity": "warning"},
|
||||
|
||||
// -- Light Warnings --
|
||||
// These rules are intended to help developers use better style. Simpler code has fewer bugs. These would be "info"
|
||||
// if TSLint supported such a level.
|
||||
|
||||
// prefer for( ... of ... ) to an index loop when the index is only used to fetch an object from an array.
|
||||
// (Even better: check out utils like .map if transforming an array!)
|
||||
"prefer-for-of": {"severity": "warning"},
|
||||
|
||||
// Warns if function overloads could be unified into a single function with optional or rest parameters.
|
||||
"unified-signatures": {"severity": "warning"},
|
||||
|
||||
// Prefer const for values that will not change. This better documents code.
|
||||
"prefer-const": {"severity": "warning"},
|
||||
|
||||
// Multi-line object literals and function calls should have a trailing comma. This helps avoid merge conflicts.
|
||||
"trailing-comma": {"severity": "warning"}
|
||||
},
|
||||
|
||||
"defaultSeverity": "error"
|
||||
}
|
||||
7
storage.rules
Normal file
7
storage.rules
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
service firebase.storage {
|
||||
match /b/{bucket}/o {
|
||||
match /{allPaths=**} {
|
||||
allow read, write: if request.auth!=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
tslint.json
Normal file
63
tslint.json
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": true,
|
||||
"ban-comma-operator": true,
|
||||
"no-namespace": true,
|
||||
"no-parameter-reassignment": true,
|
||||
"no-reference": true,
|
||||
"no-unnecessary-type-assertion": true,
|
||||
"label-position": true,
|
||||
"no-conditional-assignment": true,
|
||||
"no-construct": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-duplicate-switch-case": true,
|
||||
"no-duplicate-variable": [
|
||||
true,
|
||||
"check-parameters"
|
||||
],
|
||||
"no-shadowed-variable": true,
|
||||
"no-empty": [
|
||||
true,
|
||||
"allow-empty-catch"
|
||||
],
|
||||
"no-floating-promises": true,
|
||||
"no-implicit-dependencies": true,
|
||||
"no-invalid-this": true,
|
||||
"no-string-throw": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-void-expression": [
|
||||
true,
|
||||
"ignore-arrow-function-shorthand"
|
||||
],
|
||||
"no-duplicate-imports": true,
|
||||
// Warn when an empty interface is defined. These are generally not useful.
|
||||
"no-empty-interface": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"no-import-side-effect": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"no-var-keyword": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"triple-equals": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"deprecation": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"prefer-for-of": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"unified-signatures": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"prefer-const": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"trailing-comma": {
|
||||
"severity": "warning"
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "error"
|
||||
}
|
||||
Loading…
Reference in a new issue