Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
incorporate campus-enrollment repo
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodino committed Sep 2, 2018
1 parent 645723d commit 39c3845
Show file tree
Hide file tree
Showing 47 changed files with 5,894 additions and 278 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "campus-unb"
}
}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Project dependencies
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
package-lock.json
.cache/
.firebase/

# Build directory
public/
/functions
static/admin/*.bundle.*
.DS_Store
yarn-error.log
*.env.*
*.log*
5 changes: 5 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"database": {"rules": "packages/campus-enrollment-database/rules.json"},
"functions": {"source": "packages/campus-enrollment-functions"},
"hosting": {"public": "packages/campus-enrollment-frontend/build"}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"lint": "wsrun lint --exclude-missing",
"build": "wsrun build --exclude-missing",
"format": "wsrun format --exclude-missing",
"precommit": "wsrun precommit --exclude-missing"
"precommit": "wsrun precommit --exclude-missing",
"test": "wsrun test --exclude-missing",
"deploy": "wsrun build 'campus-enrollment-frontend' && firebase deploy"
},
"private": true,
"workspaces": [
Expand All @@ -15,6 +17,7 @@
"yarn": "^1"
},
"devDependencies": {
"firebase-tools": "^4.2.1",
"husky": "^0.14.3",
"wsrun": "^2.2.1"
}
Expand Down
5 changes: 5 additions & 0 deletions packages/campus-enrollment-database/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "campus-enrollment-database",
"version": "0.0.0-alpha",
"private": true
}
66 changes: 66 additions & 0 deletions packages/campus-enrollment-database/rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"rules": {
"netlify-subdomain": {
".validate": "newData.isString()",
".read": "root.child('tokens/'+auth.uid).isString()"
},
"tasks": {
"$task": {
".read": "root.child('tokens/'+auth.uid).isString() && data.child('createdBy').val() === auth.uid",
".validate": "newData.child('type').isString()",
"status": {
".validate": "newData.val() === 'queue' || newData.val() === 'done' || newData.val() === 'error' || newData.val() === 'skipped'"
},
"createdBy": {".validate": "root.child('tokens/'+newData.val()).isString()"},
"createdAt": {".validate": "newData.isNumber()"},
"updatedAt": {".validate": "newData.isNumber()"}
}
},
"invite": {
".read": "root.child('tokens/'+auth.uid).isString()",
"$sha256": {
".read": "true",
".write": "root.child('tokens/'+auth.uid).isString() && $sha256.length === 64 && $sha256 === $sha256.toLowerCase()",
".validate": "!data.exists() && newData.hasChildren(['email'])",
"email": {
".validate": "newData.isString() && newData.val().contains('@') && newData.val() === newData.val().toLowerCase()"
},
"full_name": {
".validate": "newData.isString()"
},
"$other": {".validate": false}
}
},
"update": {
".read": "root.child('tokens/'+auth.uid).isString()",
"$push": {
".write": "root.child('tokens/'+auth.uid).isString() && newData.child('user_id').isString()",
"user_id": {
".validate": "newData.isString()"
},
"email": {
".validate": "newData.isString() && newData.val().contains('@') && newData.val() === newData.val().toLowerCase()"
},
"full_name": {
".validate": "newData.isString()"
},
"$other": {".validate": false}
}
},
"retire": {
".read": "root.child('tokens/'+auth.uid).isString()",
"$push": {
".write": "root.child('tokens/'+auth.uid).isString()",
".validate": "newData.child('user_id').isString()",
"user_id": {
".validate": "newData.isString()"
}
}
},
"tokens": {
"$uid": {
".validate": "newData.isString() || !newData.exists()"
}
}
}
}
13 changes: 13 additions & 0 deletions packages/campus-enrollment-frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parser": "babel-eslint",
"extends": [
"../../.eslintrc.json",
"plugin:react/recommended"
],
"env": {
"browser": true
},
"rules": {
"react/prop-types": 0
}
}
19 changes: 19 additions & 0 deletions packages/campus-enrollment-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# dependencies
node_modules
package-lock.json

# testing
/coverage

# production
build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

*.log*
.firebase/
27 changes: 27 additions & 0 deletions packages/campus-enrollment-frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "campus-enrollment-frontend",
"version": "0.0.0-alpha",
"homepage": "https://matricula.campus.kunst.cloud/",
"private": true,
"scripts": {
"dev": "react-scripts start",
"lint": "eslint 'src'",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom"
},
"dependencies": {
"firebase": "^5.3.1",
"invariant": "^2.2.4",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-redux": "^5.0.7",
"react-scripts": "1.1.4",
"rebass": "^2.1.0",
"redux": "^4.0.0",
"redux-implicit-oauth2": "^1.2.1",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"reline": "^1.0.0-beta.3",
"styled-components": "^3.4.1"
}
}
Binary file not shown.
47 changes: 47 additions & 0 deletions packages/campus-enrollment-frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<style>
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
</style>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions packages/campus-enrollment-frontend/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
12 changes: 12 additions & 0 deletions packages/campus-enrollment-frontend/src/api/getFirebaseToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import invariant from 'invariant'
import http from './http'

const getFirebaseToken = async token => {
invariant(token, 'getFirebaseToken: input token is missing')
const res = await http.get('token', {auth: {token}, credentials: 'include'})
const {access_token} = res
invariant(access_token, 'getFirebaseToken: output token is missing')
return access_token
}

export default getFirebaseToken
79 changes: 79 additions & 0 deletions packages/campus-enrollment-frontend/src/api/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const API_URL = 'https://us-east1-campus-unb.cloudfunctions.net'

const headersByMethod = {
'HEAD': {},
'GET': {Accept: 'application/json'},
'LINK': {Accept: 'application/json'},
'UNLINK': {Accept: 'application/json'},
'DELETE': {Accept: 'application/json'},
'POST': {Accept: 'application/json', 'Content-Type': 'application/json'},
'PUT': {Accept: 'application/json', 'Content-Type': 'application/json'},
'PATCH': {Accept: 'application/json', 'Content-Type': 'application/json'},
}

const isString = value => typeof value === 'string'
const JSONEncode = body => isString(body) ? body : JSON.stringify(body)

const api = Object.keys(headersByMethod).reduce((api, method) => {
api[method.toLowerCase()] = async (path, {auth, raw, ...options} = {}) => {
if(typeof path !== 'string') throw new Error(`api.${method}: Missing Path`)
const body = JSONEncode(options.body)
const headers = new Headers({
...headersByMethod[method],
...options.headers,
...createAuth(auth),
})
const {href} = new URL(path, API_URL)
const response = await fetch(href, {...options, method, headers, body})
if(raw) return response
let json = {}
try{json = await response.json()}catch(e){/* swallow */}

if(json.error){
const err = new Error(json.error_message || json.error_code || json.error)
err.code = json.error_code
throw err
}

return Array.isArray(json)
? {items: json, http: response}
: {...json, http: response}
}
return api
}, {})

export default api

const createAuth = ({username, password, token} = {}) => {
const key = 'Authorization'
if(typeof token === 'string') return {[key]: new TokenAuth(token)}
if(typeof username === 'string' && typeof password === 'string'){
return {[key]: new BasicAuth(username, password)}
}
return {}
}

export class BasicAuth {
constructor(username, password){
if(!username) throw new Error('BasicAuth: Missing Username')
if(!password) throw new Error('BasicAuth: Missing Password')
this.username = username
this.password = password
this.toString.bind(this)
}
toString(){
// [TODO]: replace btoa with propper base64, people use emoji etc
return 'Basic ' + btoa(`${this.username}:${this.password}`)
}
}

export class TokenAuth {
constructor(token){
if(!token) throw new Error('TokenAuth: Missing Token')
this.token = token
this.toString.bind(this)
}
toString(){
return 'Bearer ' + this.token
}
}
1 change: 1 addition & 0 deletions packages/campus-enrollment-frontend/src/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default as getFirebaseToken} from './getFirebaseToken'
26 changes: 26 additions & 0 deletions packages/campus-enrollment-frontend/src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import {Provider as RebassProvider} from 'rebass'
import {Provider as ReduxProvider} from 'react-redux'
import {Provider as FirebaseProvider} from './Firebase'
import store from '../store'
import firebase from '../firebase'
import Home from './Home'

/* eslint-disable no-mixed-operators */

export default class App extends React.Component {
/* globals process */
static defaultProps = {isTest: process.env.NODE_ENV === 'test'}
render(){
const {isTest, store: overideStore} = this.props
return (
<ReduxProvider store={isTest && overideStore || store}>
<FirebaseProvider value={firebase}>
<RebassProvider>
<Home/>
</RebassProvider>
</FirebaseProvider>
</ReduxProvider>
)
}
}
11 changes: 11 additions & 0 deletions packages/campus-enrollment-frontend/src/components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env jest */

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
})
Loading

0 comments on commit 39c3845

Please sign in to comment.