princemuel / invoicetracker-api

the backend repo of my invoice mail web application (still under development)

Home Page:https://invoicemailer.onrender.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invoice Mail

This is the backend of my Invoice Mail Web App

Table of contents

Overview

This project was bootstrapped with Express and Apollo Server 4

Available Scripts

In the project directory, you can run:

yarn dev

Runs the app in the development mode with server restarts.
Open http://localhost:4000 to view it in the browser. You will be directed to the Apollo Studio Playground.

The page will refresh when you make edits to the code.
You will also see updates to the GraphQL schema.

yarn start

Runs the app in the development or production mode without server restarts.
Open http://localhost:4000 to view it in the browser.

yarn studio

Opens up Prisma Studio in the browser with a nice GUI interface.
It gives the developer a seamless and interactive experience with Prisma and the Database service used

yarn postinstall

Runs automatically after the project's dependencies have been installed.
It runs the generate script to output correct types, migrations, schema for Prisma and Nexus GraphQl

Deployment

Your app is ready to be deployed! See the section about deployment for more information.

Links

My process

Built with

  • RSA asymmetric encryption
  • TS Node
  • Express - A Fast, unopinionated, minimalist web framework for Node.js
  • Graphql - A server-side runtime for executing queries using a type system you define for your data
  • Apollo Server 4 - An open-source, spec-compliant GraphQL server that's compatible with any GraphQL client, including Apollo Client
  • GraphQL Nexus - A robust, composable, and declarative, code-first schemas for GraphQL in TypeScript/JavaScript
  • Prisma - A Next-generation Node.js and TypeScript ORM
  • MongoDB - A NoSQL Database program
  • Typescript - A strongly typed programming language that builds on JavaScript, giving you better tooling at any scale
  • Immer - A javascript package which helps you interact with your data by simply modifying it while keeping all the benefits of immutable data

What I learned

  • The proper way to work with state removing the need for boilerplate code and protecting it from future accidental modifications
  • How to generate RSA crypto key pairs
function generateCryptoKeyPair(callback: () => void) {
  crypto.generateKeyPair(
    'rsa',
    {
      modulusLength: 4096,
      publicKeyEncoding: {
        type: 'pkcs1',
        format: 'pem',
      },
      privateKeyEncoding: {
        type: 'pkcs1',
        format: 'pem',
        // cipher: 'aes-256-cbc',
        // passphrase: '@Blah,b1@H.B1@w#$',
      },
    },
    (error, publicKey, privateKey) => {
      if (error) console.log(error);
      callback();
    }
  );
}
  • How to get a user's image using the email hash,
function gravatar(email = '', size = 200, defaults = 'retro') {
  const BASE_URL = `https://gravatar.com/avatar`;

  if (!email) return `${BASE_URL}/?s=${size}&d=${defaults}`;

  const hash = createHash(email.trim(), 'md5').toString();
  return `${BASE_URL}/${hash}?s=${size}&d=${defaults}`;
}

function createHash(
  data: crypto.BinaryLike,
  algorithm: string,
  encoding: crypto.BinaryToTextEncoding = 'hex',
  options?: crypto.HashOptions
) {
  return crypto.createHash(algorithm, options).update(data).digest(encoding);
}

Continued development

  • Implementing refresh token rotation and reuse detection

Useful resources

  • Javascript:The Definitive Guide - This book by author David Flanagan helped me improve in my Javascript knowledge. I really liked this book and it will be my companion guide going forward cus' there are still some important concepts I have to master.
  • Get a catch block error message with TypeScript - This is an amazing article which helped me understand how to provide handle errors obtained in the catch block and make them type-safe. I'd recommend it to anyone still learning this concept.

Author

About

the backend repo of my invoice mail web application (still under development)

https://invoicemailer.onrender.com

License:MIT License


Languages

Language:TypeScript 97.7%Language:JavaScript 2.3%