' + - // Append button for sign out. - ' ' + - // Append button for deletion. - ' ' + - '
' + - '' + - // Append button for sign out. - ' ' + - // Append button for deletion. - ' ' + - '
' + - '' + escape(post.body) + '
'; - }); - return emailHtml; -} - -// Start the server. -startListeners(); -startWeeklyTopPostEmailer(); diff --git a/database/package.json b/database/package.json deleted file mode 100644 index c6890982..00000000 --- a/database/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "firebase-database-quickstart", - "version": "1.0.0", - "description": "Firebase Node.js Database Quickstart Sample", - "main": "index.js", - "author": "nivco@google.com", - "license": "Apache License Version 2.0", - "dependencies": { - "escape-html": "^1.0.3", - "firebase-admin": "^4.0.3", - "node-schedule": "^1.1.0", - "nodemailer": "^2.4.1", - "promise": "^7.1.1" - } -} diff --git a/firestore-emulator/browser-quickstart/.gitignore b/firestore-emulator/browser-quickstart/.gitignore deleted file mode 100644 index c2658d7d..00000000 --- a/firestore-emulator/browser-quickstart/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/firestore-emulator/browser-quickstart/README.md b/firestore-emulator/browser-quickstart/README.md deleted file mode 100644 index 25b90194..00000000 --- a/firestore-emulator/browser-quickstart/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Connecting a web app to the Firestore emulator - -Cloud Firestore relies heavily on bi-directional streams. Most clients (such as -Android, iOS, and Node.js) connect via gRPC. Browser clients unfortunately -cannot use gRPC bidi streams (see https://github.com/grpc/grpc-web), so Cloud -Firestore also supports the -[WebChannel protocol](https://google.github.io/closure-library/api/goog.net.WebChannel.html). - -We are in the process of adding WebChannel support to the Firestore emulator. -It's a little rough at the moment, so please -[file an issue](https://github.com/firebase/firebase-tools/issues) if you run -into any bugs. - -## Setup - -Download the Firestore emulator -``` -curl -LO https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.7.0.jar -``` - -Start the Firestore emulator with WebChannel support enabled -``` -java -jar cloud-firestore-emulator-v1.7.0.jar --webchannel-port=50051 --rules=firestore.rules -``` - -Start the Firebase hosting emulator -``` -firebase serve -``` - -## Interacting with the page - -Once you've run `firebase serve`, you can visit `http://localhost:5000` in your -browser and you should see a _very_ barebones chat app powered by the local -Firestore emulator. - -## Running automated tests - -Run the test -``` -npm test -``` - -This will create a "headless" instance of Google Chrome, visit the page, -interact with a few UI elements, and assert that they have the correct -behavior. diff --git a/firestore-emulator/browser-quickstart/firebase.json b/firestore-emulator/browser-quickstart/firebase.json deleted file mode 100644 index 00f5def2..00000000 --- a/firestore-emulator/browser-quickstart/firebase.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "firestore": { - "rules": "firestore.rules", - "indexes": "firestore.indexes.json" - }, - "emulators": { - "firestore": {} - }, - "hosting": { - "public": "public", - "ignore": [ - "firebase.json", - "**/.*", - "**/node_modules/**" - ], - "rewrites": [ - { - "source": "**", - "destination": "/index.html" - } - ] - } -} diff --git a/firestore-emulator/browser-quickstart/firestore.indexes.json b/firestore-emulator/browser-quickstart/firestore.indexes.json deleted file mode 100644 index 0e3f2d6b..00000000 --- a/firestore-emulator/browser-quickstart/firestore.indexes.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "indexes": [] -} diff --git a/firestore-emulator/browser-quickstart/firestore.rules b/firestore-emulator/browser-quickstart/firestore.rules deleted file mode 100644 index cef3c1a1..00000000 --- a/firestore-emulator/browser-quickstart/firestore.rules +++ /dev/null @@ -1,7 +0,0 @@ -service cloud.firestore { - match /databases/{database}/documents { - match /{doc=**} { - allow read, write; - } - } -} diff --git a/firestore-emulator/browser-quickstart/package.json b/firestore-emulator/browser-quickstart/package.json deleted file mode 100644 index c1311633..00000000 --- a/firestore-emulator/browser-quickstart/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scripts": { - "test": "mocha --exit" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^6.2.0", - "puppeteer": "^1.19.0" - } -} diff --git a/firestore-emulator/browser-quickstart/public/index.html b/firestore-emulator/browser-quickstart/public/index.html deleted file mode 100644 index cf4de788..00000000 --- a/firestore-emulator/browser-quickstart/public/index.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - diff --git a/firestore-emulator/browser-quickstart/test/test.js b/firestore-emulator/browser-quickstart/test/test.js deleted file mode 100644 index 08a903e9..00000000 --- a/firestore-emulator/browser-quickstart/test/test.js +++ /dev/null @@ -1,23 +0,0 @@ -const puppeteer = require('puppeteer'); -const expect = require("chai").expect; - -it('works', async () => { - const browser = await puppeteer.launch(); - const page = await browser.newPage(); - await page.goto('http://localhost:5000'); - - const { before, after } = await page.evaluate(async () => { - const chat = document.getElementById("history"); - const before = chat.innerText; - document.getElementById("input").innerText = "Hello, World!"; - document.getElementById("submit").click(); - await new Promise(r => setTimeout(r, 100)); - const after = chat.innerText; - return { before, after }; - }); - - expect(before).to.be.eql(""); - expect(after).to.be.eql("Hello, World!"); - - await browser.close(); -}); diff --git a/firestore-emulator/javascript-quickstart/.eslintrc b/firestore-emulator/javascript-quickstart/.eslintrc deleted file mode 100644 index 703ba3c9..00000000 --- a/firestore-emulator/javascript-quickstart/.eslintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "google", - "parserOptions": { - "ecmaVersion": 2017, - "sourceType": "module" - }, - "rules": { - "max-len": [1, 100, 4] - } -} diff --git a/firestore-emulator/javascript-quickstart/README.md b/firestore-emulator/javascript-quickstart/README.md deleted file mode 100644 index 8fcae642..00000000 --- a/firestore-emulator/javascript-quickstart/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Cloud Firestore emulator quickstart - -Let's try writing some simple tests for our security rules. - -## Setup - -### Start in the right directory - -To use this, some people may clone the entire quickstart-nodejs directory. -When starting the quickstart, cd to the specific quickstart related to your -project (i.e. `cd firestore-emulator/javascript-quickstart`). - -### Install Node dependencies - -Run `npm install` from this directory, and make sure that you have a recent -version of the [Firebase CLI tool](https://github.com/firebase/firebase-tools) -installed (you'll need `firebase --version` to be at least `6.3.0`). - -### Running the emulator - -Setup the Firestore emulator -``` -firebase setup:emulators:firestore -``` -Add your project to the emulator (use `firebase init` if no project setup) -``` -firebase use --add your-project-name -``` -If another app's using the 8080 port, update the firebase.json file to -look like this -``` -{ - "firestore": { - "rules": "firestore.rules" - }, - "emulators": { - "firestore": { - "port": "PORT" - } - } -} -``` -Start the firestore emulator (and leave it running during the tests) -``` -firebase emulators:start --only firestore -``` - -## Running the tests - -To run the tests, open a new terminal (in your specific quickstart directory, not '/quickstart-nodejs') and execute -``` -npm test -``` -which runs all the tests in the `tests/` directory. - -``` - ✓ require users to log in before creating a profile (71ms) - ✓ should enforce the createdAt date in user profiles (79ms) - ✓ should only let users create their own profile (57ms) - ✓ should let anyone read any profile (40ms) - ✓ should let anyone create a room (44ms) - ✓ should force people to name themselves as room owner when creating a room (48ms) - ✓ should not let one user steal a room from another user (119ms) - - - 7 passing (607ms) -``` diff --git a/firestore-emulator/javascript-quickstart/firebase.json b/firestore-emulator/javascript-quickstart/firebase.json deleted file mode 100644 index 0b4f056b..00000000 --- a/firestore-emulator/javascript-quickstart/firebase.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "firestore": { - "rules": "firestore.rules" - }, - "emulators": { - "firestore": { - "port": 8080 - } - } -} diff --git a/firestore-emulator/javascript-quickstart/firestore.rules b/firestore-emulator/javascript-quickstart/firestore.rules deleted file mode 100644 index 7f77702d..00000000 --- a/firestore-emulator/javascript-quickstart/firestore.rules +++ /dev/null @@ -1,15 +0,0 @@ -service cloud.firestore { - match /databases/{database}/documents { - match /users/{userId} { - allow read; - allow create: if request.auth.uid == userId && request.resource.data.createdAt == request.time; - } - match /rooms/{roomId} { - allow read; - // If you create a room, you must set yourself as the owner. - allow create: if request.resource.data.owner == request.auth.uid; - // Only the room owner is allowed to modify it. - allow update: if resource.data.owner == request.auth.uid; - } - } -} diff --git a/firestore-emulator/javascript-quickstart/package.json b/firestore-emulator/javascript-quickstart/package.json deleted file mode 100644 index 9e71b33f..00000000 --- a/firestore-emulator/javascript-quickstart/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "cloud-firestore-emulator-javascript-quickstart", - "version": "1.0.2", - "description": "Cloud Firestore emulator testing", - "scripts": { - "format": "prettier --write **/*.js", - "test": "mocha --timeout=10000" - }, - "devDependencies": { - "@firebase/testing": "0.10.0", - "filesystem": "1.0.1", - "mocha": "5.2.0", - "prettier": "1.15.2" - } -} diff --git a/firestore-emulator/javascript-quickstart/test/test.js b/firestore-emulator/javascript-quickstart/test/test.js deleted file mode 100644 index 9c143380..00000000 --- a/firestore-emulator/javascript-quickstart/test/test.js +++ /dev/null @@ -1,138 +0,0 @@ -const firebase = require("@firebase/testing"); -const fs = require("fs"); - -/* - * ============ - * Setup - * ============ - */ -const projectId = "firestore-emulator-example"; -const firebasePort = require("../firebase.json").emulators.firestore.port; -const port = firebasePort /** Exists? */ ? firebasePort : 8080; -const coverageUrl = `http://localhost:${port}/emulator/v1/projects/${projectId}:ruleCoverage.html`; - -const rules = fs.readFileSync("firestore.rules", "utf8"); - -/** - * Creates a new app with authentication data matching the input. - * - * @param {object} auth the object to use for authentication (typically {uid: some-uid}) - * @return {object} the app. - */ -function authedApp(auth) { - return firebase.initializeTestApp({ projectId, auth }).firestore(); -} - -/* - * ============ - * Test Cases - * ============ - */ -beforeEach(async () => { - // Clear the database between tests - await firebase.clearFirestoreData({ projectId }); -}); - -before(async () => { - await firebase.loadFirestoreRules({ projectId, rules }); -}); - -after(async () => { - await Promise.all(firebase.apps().map(app => app.delete())); - console.log(`View rule coverage information at ${coverageUrl}\n`); -}); - -describe("My app", () => { - it("require users to log in before creating a profile", async () => { - const db = authedApp(null); - const profile = db.collection("users").doc("alice"); - await firebase.assertFails(profile.set({ birthday: "January 1" })); - }); - - it("should enforce the createdAt date in user profiles", async () => { - const db = authedApp({ uid: "alice" }); - const profile = db.collection("users").doc("alice"); - await firebase.assertFails(profile.set({ birthday: "January 1" })); - await firebase.assertSucceeds( - profile.set({ - birthday: "January 1", - createdAt: firebase.firestore.FieldValue.serverTimestamp() - }) - ); - }); - - it("should only let users create their own profile", async () => { - const db = authedApp({ uid: "alice" }); - await firebase.assertSucceeds( - db - .collection("users") - .doc("alice") - .set({ - birthday: "January 1", - createdAt: firebase.firestore.FieldValue.serverTimestamp() - }) - ); - await firebase.assertFails( - db - .collection("users") - .doc("bob") - .set({ - birthday: "January 1", - createdAt: firebase.firestore.FieldValue.serverTimestamp() - }) - ); - }); - - it("should let anyone read any profile", async () => { - const db = authedApp(null); - const profile = db.collection("users").doc("alice"); - await firebase.assertSucceeds(profile.get()); - }); - - it("should let anyone create a room", async () => { - const db = authedApp({ uid: "alice" }); - const room = db.collection("rooms").doc("firebase"); - await firebase.assertSucceeds( - room.set({ - owner: "alice", - topic: "All Things Firebase" - }) - ); - }); - - it("should force people to name themselves as room owner when creating a room", async () => { - const db = authedApp({ uid: "alice" }); - const room = db.collection("rooms").doc("firebase"); - await firebase.assertFails( - room.set({ - owner: "scott", - topic: "Firebase Rocks!" - }) - ); - }); - - it("should not let one user steal a room from another user", async () => { - const alice = authedApp({ uid: "alice" }); - const bob = authedApp({ uid: "bob" }); - - await firebase.assertSucceeds( - bob - .collection("rooms") - .doc("snow") - .set({ - owner: "bob", - topic: "All Things Snowboarding" - }) - ); - - await firebase.assertFails( - alice - .collection("rooms") - .doc("snow") - .set({ - owner: "alice", - topic: "skiing > snowboarding" - }) - ); - }); -}); diff --git a/firestore-emulator/typescript-quickstart/.eslintrc b/firestore-emulator/typescript-quickstart/.eslintrc deleted file mode 100644 index 98c68efa..00000000 --- a/firestore-emulator/typescript-quickstart/.eslintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "google", - "parser": "typescript-eslint-parser", - "parserOptions": { - "sourceType": "module" - }, - "rules": { - "max-len": [1, 100, 4] - } -} diff --git a/firestore-emulator/typescript-quickstart/.gitignore b/firestore-emulator/typescript-quickstart/.gitignore deleted file mode 100644 index 4e57eef8..00000000 --- a/firestore-emulator/typescript-quickstart/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.js -*.js.map diff --git a/firestore-emulator/typescript-quickstart/.npmignore b/firestore-emulator/typescript-quickstart/.npmignore deleted file mode 100644 index f0e06b3b..00000000 --- a/firestore-emulator/typescript-quickstart/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -*.ts -!*.d.ts diff --git a/firestore-emulator/typescript-quickstart/README.md b/firestore-emulator/typescript-quickstart/README.md deleted file mode 100644 index 5422c96a..00000000 --- a/firestore-emulator/typescript-quickstart/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Cloud Firestore emulator quickstart - -Let's try writing some simple tests for our security rules. - -## Setup - -### Install Node dependencies - -Run `npm install` from this directory, and make sure that you have a recent -version of the [Firebase CLI tool](https://github.com/firebase/firebase-tools) -installed (you'll need `firebase --version` to be at least `6.10.0`). - -### Running the emulator - -Setup the Firestore emulator -``` -firebase setup:emulators:firestore -``` -Start the firestore emulator (and leave it running during the tests) -``` -firebase emulators:start --only firestore -``` - -## Running the tests - -To run the tests, execute -``` -npm test -``` -which runs all the tests in the `tests/` directory. - -``` - ✓ require users to log in before creating a profile (71ms) - ✓ should enforce the createdAt date in user profiles (79ms) - ✓ should only let users create their own profile (57ms) - ✓ should let anyone read any profile (40ms) - ✓ should let anyone create a room (44ms) - ✓ should force people to name themselves as room owner when creating a room (48ms) - ✓ should not let one user steal a room from another user (119ms) - - - 7 passing (607ms) -``` diff --git a/firestore-emulator/typescript-quickstart/firebase.json b/firestore-emulator/typescript-quickstart/firebase.json deleted file mode 100644 index 0207c3fc..00000000 --- a/firestore-emulator/typescript-quickstart/firebase.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "firestore": { - "rules": "firestore.rules" - } -} diff --git a/firestore-emulator/typescript-quickstart/firestore.rules b/firestore-emulator/typescript-quickstart/firestore.rules deleted file mode 100644 index 7f77702d..00000000 --- a/firestore-emulator/typescript-quickstart/firestore.rules +++ /dev/null @@ -1,15 +0,0 @@ -service cloud.firestore { - match /databases/{database}/documents { - match /users/{userId} { - allow read; - allow create: if request.auth.uid == userId && request.resource.data.createdAt == request.time; - } - match /rooms/{roomId} { - allow read; - // If you create a room, you must set yourself as the owner. - allow create: if request.resource.data.owner == request.auth.uid; - // Only the room owner is allowed to modify it. - allow update: if resource.data.owner == request.auth.uid; - } - } -} diff --git a/firestore-emulator/typescript-quickstart/package.json b/firestore-emulator/typescript-quickstart/package.json deleted file mode 100644 index 164022bb..00000000 --- a/firestore-emulator/typescript-quickstart/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "cloud-firestore-emulator-typescript-quickstart", - "version": "1.0.2", - "description": "Cloud Firestore emulator testing, with TypeScript", - "scripts": { - "format": "prettier --write **/*.ts", - "pretest": "tsc", - "test": "mocha --timeout=10000" - }, - "devDependencies": { - "@firebase/testing": "0.10.0", - "@types/mocha": "5.2.5", - "filesystem": "1.0.1", - "mocha": "5.2.0", - "mocha-typescript": "1.1.17", - "prettier": "1.15.2", - "source-map-support": "0.5.9", - "ts-node": "7.0.1", - "typescript": "3.1.3" - } -} diff --git a/firestore-emulator/typescript-quickstart/test/mocha.opts b/firestore-emulator/typescript-quickstart/test/mocha.opts deleted file mode 100644 index bb4e3905..00000000 --- a/firestore-emulator/typescript-quickstart/test/mocha.opts +++ /dev/null @@ -1,3 +0,0 @@ ---ui mocha-typescript ---require source-map-support/register ---recursive test diff --git a/firestore-emulator/typescript-quickstart/test/test.ts b/firestore-emulator/typescript-quickstart/test/test.ts deleted file mode 100644 index 214d64ce..00000000 --- a/firestore-emulator/typescript-quickstart/test/test.ts +++ /dev/null @@ -1,147 +0,0 @@ -///