Code Monkey home page Code Monkey logo

amplify-back-end's Introduction

amplify-back-end's People

Contributors

jamesmgreene avatar manishapriya94 avatar beexiong avatar dependabot[bot] avatar nawazkhan avatar computate avatar waldnzwrld avatar ankitagrawal98 avatar nawazeverlane avatar andyfeller avatar anishasthana avatar afcollins avatar

Stargazers

 avatar  avatar  avatar  avatar Ramon Preston Lee Henderson avatar Greg Hoelzer avatar  avatar  avatar veekas ashoka avatar Evelyn Luu avatar

Watchers

 avatar Evelyn Luu avatar Rashan avatar  avatar Ernest Serunkuma avatar Param Siddharth avatar

amplify-back-end's Issues

Function: Verify Address

Issues

FrontEnd

Backend

Architecture

QA

Working together

  Frontend Backend Architecture QA/Security
Verify Address based off of boolean check, display one of the screens Format address input from FrontEnd to Lob, return boolean check Make it easier for backend and database to connect testing the data passed to APIs

This function verifies the user's address in order to show their representative list

Screen Shot 2021-05-09 at 10 46 28 PM

If the address is invalidated, the user will be prompted to enter another address

Screen Shot 2021-05-09 at 10 47 20 PM

APIs not working

Receiving this error when trying to access any of API links in the front-end.
Screen Shot 2021-07-27 at 8 37 03 PM

⚙️ 🗂 New Architecture Outline

Takeaways from the BackEnd discussion on #6 : Moving forward with a Heroku Postgres structure

  • Airtable has been set and tables to migrate to Postgres

Data Structure Read more here

  • Two types of users: orgs and volunteers (volunteers will come mpv+)
    • Orgs (Starter (only letters), Accelerator (analytics), Grant (completely subsidized)
    • Volunteers (which orgs are they referred from?)

BackEnd functions:

  • Create data tables
  • Establish APIs for: Twilio, Auth0, Lob
  • Passwordless authentication
  • Store new users

Testing

  • Error codes from APIs
  • Login errors
  • Database?

Working on:

Update Amplify Endpoint to Representatives

Creating a new issue to update the Amplify Endpoint.

Per our conversation in the Send Letter Issue, updating api/amplify/{zipcode} to reflect api/representatives/{zipcode}

  • Modify app.js file for routing
  • Change name of Amplify Endpoint to Representatives
  • Update Wiki information to reflect Representatives
  • Update Front-End URL for --> @mahrsbar

Lift meta files (`package.json`, etc.) to project root directory

While onboarding to join this project, it took a several minutes (sadly 😅) to realize that the project wasn't actually missing its package.json file, it was just unexpectedly down 1 level deeper (inside of server/).

My take on the project setup here is that the server directory was probably a direct copy from another location (e.g. a previous repository), so it ended up looking a bit like a monorepo setup (sub-repositories inside of a repository).

My understanding from @manishapriya94 and @BeeXiong is that this repository will continue to be a single repository dedicated to the backend server, so I feel that we should flatten the hierarchy at least for the meta files to achieve a more standard Node.js project layout and avoid confusion for onboarding additional folks in the future. 😊

Rules Layer

Purpose:

Part of User Login Outline
Implementing rules with Auth0 allows the user to maneuver amplify and browse many campaigns before having to login when they've chosen a letter to send.

Screen Shot 2021-04-05 at 2 42 37 PM

When the user clicks 'send letter':

  • A trigger kicks off that checks if the user has been previously authenticated (Via passwordless SMS).
    • If the user hasn't, they'll be sent to an Auth0 landing page
    • Previously authenticated users can continue to send the letter.

Screen Shot 2021-02-04 at 4 41 04 AM

After a successful authentication, the user will be added to our database of User Volunteer where any future letters sent will be added.

We will need to modify the following:

  • require authentication for app.post
  • route to Auth0 page for SMS passwordless

Requiring Authentication

To implement the logic, we reference the below to require Auth0 for specific routes
Screen Shot 2021-04-05 at 2 49 02 PM

  • Change to app.post
  • How do we do this without the frontend button?

Route to Auth0

  • res.redirect to auth0 url:
  • How do we do this without the page being built?

Route to Lob API

If the user is already logged in (use cookie), send the lob api call

Stripe Implementation Overview

Purpose: Users are able to donate to the cost of letter and any additional amount to the advocacy nonprofit directly. Users donating a certain amount over $30 will get a campaign sticker. Full details ProgramEquity/product#3

User Story:

  1. User has authenticated and went through all steps leading up to payment of letter
  2. Pick an amount to donate
  3. Checkout and fill payment information
  4. Successful payment accepted highlights send message button
  5. send button pressed, results in confirmation, congratulated if sticker unlocked as well

@nawazkhan could you fill in subtasks for backend each sprint for this feature?

1. Setting up tables transactions, and checkout items

a. pre-req: database structure being finalized OpenSourceFellows/amplify#32. Heroku
b. transactions as a balance, id matches checkout items
Screen Shot 2021-07-14 at 12 23 32 AM
type refers to:
Screen Shot 2021-07-14 at 12 23 48 AM
c. checkout items table
Screen Shot 2021-07-14 at 12 29 13 AM
d. API set up in Heroku and routed in index file

2. Input from frontend

GET checkout info via unit price and campaign_id
unit price is 3$ (letter), 30$ (sticker), $45 (button)

3. Routed to payment method via Checkout button

Screen Shot 2021-07-14 at 1 21 17 AM

4. Store transaction data into table

Mirroring balancing object

Screen Shot 2021-07-14 at 12 52 12 AM
Questions to explore:

  1. setting up webhook in stripe to create line item
    2.using API to get details of balance object

6. Send message button creates lob object #59

check success_url string to determine if this button is highlighted

7. Restrict send message if payment unsuccessful

Use show and hide method for send message button

8. Show a success page

Heroku Deployment Down

TLDR: Heroku is not deploying to ally.guide for frontend

In Heroku we're seeing the following error:
Screen Shot 2021-06-17 at 12 35 28 PM

At first in package.json main was not in the correct directory, it now is but even though a new build is refreshed with each install

Screen Shot 2021-06-17 at 12 36 33 PM

Let @manishapriya know if you have access issues with Heroku

2. Establishing API endpoints

What we're hoping to establish in March

Heroku environment variables for each
Screen Shot 2021-03-13 at 9 03 12 AM

RESOURCES

AIRTABLE

GOOGLE CIVIC API

LOB API

  • API Docs
  • Information to be consumed
    • template ID

Heroku Back End Deployment - Auth0 .env File

Hi @teakopp - Got an issue with the Auth0 environmental variables when deploying I believe.

Getting this error message from the logs ⬇️

image

Seems to be the same variable for when you had me create the .env file locally and added in...

ISSUER_BASE_URL=https://YOUR_DOMAIN
CLIENT_ID=YOUR_CLIENT_ID
BASE_URL=https://YOUR_APPLICATION_ROOT_URL
SECRET=LONG_RANDOM_VALUE

Would the fix be to add these as Heroku Config Environment Variables? 🤔

Auth0 Callback

Issue: callback needs to have a URL that takes the user back to the campaign page they were on before hitting login, currently it takes the user to home
Screen Shot 2021-08-20 at 12 44 53 PM
does it have to do with specifying the url path?

BACKGRUOND:

  • backend needs to have those postal codes cached to the user_volunteer table
  • frontend checks the token to see if user signed in to see what to display

logged in screen:
Screen Shot 2021-08-20 at 12 51 03 PM

need to log in screen:
Screen Shot 2021-08-20 at 12 51 32 PM

E

Creating the URL to direct users to when checking session authentication prior to sending letter. Referencing Rules Layer #19

  • adding to .env
  • secret variable in heroku

Referencing the Auth0 basic Setup
Screen Shot 2021-04-05 at 3 17 48 PM

We have the following setup in Heroku
to be referenced in further routing of the user
https://git.heroku.com/murmuring-headland-63935.git
Screen Shot 2021-04-05 at 3 28 47 PM

Back-end down

Can't access ally.guide or any of the API links. Receiving the following error.
Screen Shot 2021-07-27 at 8 37 03 PM

🖋🗂 Amplify: Message Feature Outline

Short Description*

Integrating Lob to create mail sending capability for Amplify
https://user-images.githubusercontent.com/9143339/105809192-3cc19a80-5f77-11eb-8bb0-e8c0e8c4e059.mov

Priority 1

Describe the solution you'd like

Priority 2

  • Format everything into letter object(it will triage based off the variables, will we want to default the dates)

Screen Shot 2021-01-18 at 1 48 30 AM

Priority 3

  • Business Logic:
  • Configure Inputs
    • Addresses: user, representative
    • User name from signature
    • Email template ID (which corresponds to the Breathe Act, etc)

Priority 4

Questions to explore

  • Putting a limit per address to throttle spam/cost
  • How to store email addresses

Screen Shot 2020-10-22 at 3 34 24 PM

  • Things to figure out
    • Do we want to show letter tracking
    • Are we storing additional info via PostGres?

Tracking Milestones

Features needed for each milestone (project board linked)

1. MVP: Pilot letter parties with SoapBox, AAAJ, and the Breathe Act (starting mid April 2021)

  • Architecture SetUp
  • Create custom landing for each org
  • Send message to letter function
  • Dashboard for organization

2. MVP+ Campaign Sponsors launched, scale 10 organizations. (August 2021)

  • Cause focused design refresh
  • Campaign Sponsors
  • Refined Dashboard for SetUp

3. Alpha: Public facing site launched, scale 25 organizations. (November 2021)

  • Make project open source
  • Text based functionality

Revise "volunteers" database schema to break down name and address?

Should we revise the volunteers database schema to break down name and physical_address columns into more granular bits? I followed what I saw in the Notion Product Log but now I've noticed that in the current production database (pre-migration), those fields were actually broken down into:

name ➡️ first_name, last_name
physical_address ➡️ street_address (line 1), address_2 (line 2), city, state, zip

I haven't verified but I'm guessing that better aligns with what the Lob API will be expecting us to provide vs. just a large text field like I used? 😅

⚠️ Database migrations must never be revised, so we will need to create a new migration to alter and repopulate these. 👍🏻

🔏 🗂 User Login Flow Outline

Working on

Purpose

  • Opting for a passwordless authentication to reduce user login friction while ensuring security standards are met so only US users are contacting US representatives.
  • This is done using Auth0 which requires a Twilio instantiation for the sms.

Screen Shot 2021-04-07 at 11 01 03 AM

How the user navigates passwordless for Amplify:

Screen Shot 2021-04-05 at 2 42 37 PM

Implementation Broken Down

Setting up Auth0 issue here

Opting for SMS and Embedded Universal login

  • Set up Auth0 App
  • Set up Twilio
  • Configure landing
    image

Setting up Twilio

  • Added to Heroku
  • limited user authentication only from US numbers

Create index page for Auth0 landing

Screen Shot 2021-03-13 at 10 03 25 AM

Routing to sms authentication

Screen Shot 2021-04-07 at 11 48 37 AM

User Rules @teakopp

The user will be prompted to the sms passwordless if they attempt to send the letter and aren't authenticated. This ensures they can not send a letter unless authenticated

Screen Shot 2021-02-04 at 4 15 13 AM

Create auth0.js index file

Screen Shot 2021-04-07 at 1 22 20 PM

Checks user token

Using passport and auth0

Screen Shot 2021-04-07 at 1 30 12 PM

Redirect to authentication for post request

We're dealing with post request instead of get due to the 'send letter button' which is speaking to the Lob API if user is authenticated.
Using the following route customization:
Screen Shot 2021-04-07 at 1 32 32 PM

Appending user data

  • Data table flow : Once authenticated user sends message, populates user_volunteer with the time stamp of letter_version sent from letters_sent table.
  • Justification: storing information outside of authentication will slow down database on Auth0 end
  • Exporting: seems there is an extension, @BeeXiong let me know what the id column should be? (user name or phone?

Screen Shot 2021-03-13 at 10 14 58 AM

- Data tables: user_table, letters_sent, transactions

Testing

  • It seems we can also use actions for CI/CD of the rules with Auth0?\
  • Tests

Custom Landing URL

Use Case:

1. Sending a password protected custom URL (so only users can know based off of nonprofit user list)

Security Reasons:
To maintain the growth of this platform's performance and the integrity of its users, we'll grow through nonprofit based referrals for users (that way they are only responsible for the costs of their user list).

2. The user would then enter from the standpoint of the campaign:
Screen Shot 2021-01-26 at 12 05 52 AM

3. Organization has a login to dashboard for their custom url and metrics

4. Do we want to create member user login now or just cache emails?

Collect Email or Member Login?

  • Part of the UserFlow of Custom URL
  • Do we want to ask them to save email or login?
  • If Login Use Case: Member wants to save their login for easier action?

After sending message: record info in letter_sent

  1. BackEnd creates letters_sent table which has the following pieces of information in database

    • date created
    • delivery date
    • Rep Name
    • campaign template_id
  2. FrontEnd sends information on representative and campaign_id

  3. BackEnd posts the following

    • from Google Civic API:

      • Representative Name
    • From Lob API
      Screen Shot 2021-05-22 at 7 55 19 PM

      • template_id
      • time created
      • delivery date

Continuous Integration/Deployment?

Do we happen to have any sort of subsidy from GitHub that would allow us to use GitHub Actions for continuous integration/deployment (to run our tests on each pull request, for example) without incurring any/much cost?

I'm guilty of being unfamiliar with the GitHub Actions pricing model and just using it a lot internally. 😓

I have a ton of experience with GitHub Actions, so if this is a cost-free or cost-effective option for us, I would love to help setup CI and/or CD (if we can -- and want to -- deploy our changes programmatically, that is) for the project.

Account creation

User flow after #10 : Organizations have their own login

  • Creating orgs after our comms team discusses their campaign
  • Later, they can receive payments from Sponsors

Data Structure

  • Two types of users: orgs and volunteers (volunteers will come mpv+)
  • Including all data points from this form
  • Plan: Base (only sending letters), Assisted (get analytics)

BackEnd functions:

  • Store new user
  • Dashboard
    • (Base) Upload campaign
    • (Base) Upload user emails
    • (Assisted Tier) Conversion Analytics
    • (Base) Lob Invoices

Contribution Guide Update

Wanted to highlligh that part of the issue for getting set up seems to be PGAdmin
image (4)

The fix seems to be if we use the Postgres App to install and might be good to add as an additional step in the guide?

Use of MIT license?

Currently, the package.json lists the project's license as MIT, which is a free and open source license that allows anyone to use, reuse, change, sell (🤔), etc. the contents.

I know the project is currently private, so it's not an urgent issue to attend to, but I'm curious....

  1. Are we are planning to make this repository public in the future, such as an open source license would make more sense?
  2. If not, should we change the license to something more prohibitive? The SPDX license type (the value we put into the package.json file) suggested for proprietary/closed source software is [confusing, IMHO] UNLICENSED.

⚠️ In the short term, I would also recommend we add a "private": true flag into the package.json to prevent accidental publishing to npm for those of us with local-and-active npm credentials. 😅

Calling API 'send message' Button

Priority 4 from Ally-Guide/ally-guide-app#98

Screen Shot 2021-01-30 at 1 45 47 AM

Calling Lob API to create a letter for queuing

  • Cache inputs (user address, name, letter template id, rep address)
  • add button to send letter in amplify page
  • Calling api on saved letter after button click (pass cached inputs)

Screen Shot 2021-01-18 at 2 12 38 AM

  • Error testing

Future Considerations

  • Have user create account?
  • Letter tracking (delivery)
  • Letter cancellation?

Setting up BackEnd

Takeaways from the BackEnd discussion on #6

  • What happens to the current airtable?

  • Storing orgs

💡 Idea: store all addresses in a single database table

Since we are now storing physical/mailing addresses in multiple database tables, we should probably just make a new database table to hold addresses and reference them from the relevant tables (and load them with records via JOIN operations or an ORM).

This would also allow us to validate the addresses more directly for greater data integrity, e.g. require values for at least one line, a city, a state, and a zip code at the database level.

Not an urgent requirement but something that would probably be wise in the long term.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.