Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Latest commit

 

History

History
238 lines (172 loc) · 7.61 KB

DEVELOPERS.adoc

File metadata and controls

238 lines (172 loc) · 7.61 KB

Developers

This document presents information relevant to people who want to contribute code. Please read first CONTRIBUTING document for general guidelines.

Environment Setup

This project is made using Node JS. A Dockerfile is provided with the required environment. But a traditional environment installation can be used too.

Dependencies

Code Editors

You can use any editor that supports .editorconfig files.

Recommendations:

Organization

This codebase tries to follow Domain Driven Design practices and SOLID principles.

The main domains are:

  • parsers: Parse email’s content with specific regex rules.

  • actions: Refers to some action to take after parsing emails (Ex: Save to Spreadsheet).

Directory: plugins

This directory contains the different actions and parsers. These are the important domains:

  • country: Directory that holds different entities specific to a country. This is because the same entity (Ex: "Netflix") could have different email formats depending on the country of the customer. Country names should be in lowercase and in USA english. No spaces (use dash to separate words).

  • any: Directory refers to actions and parsers that could be applied to any country/entity. actions will be applied on every email found.

  • entity: Directory that contains actions and parsers specific to the entity. An entity could be any organization. Example banks, subscription services and other money related emails. actions will only be applied to emails related to this entity.

Example Structure

$ tree -L 6 plugins
plugins
├── any
│   ├── actions
│   │   ├── index.js
│   │   └── spreadsheet
│   │       ├── Constants.js
│   │       ├── SpreadSheetAction.js
│   │       └── index.js
│   ├── index.js
│   └── parsers
│       └── index.js
├── chile # country
│   ├── currencies
│   │   ├── CLP.js
│   │   └── index.js
│   ├── entities
│   │   ├── bancoestado # entity
│   │   │   ├── README.adoc
│   │   │   ├── actions
│   │   │   │   └── index.js
│   │   │   ├── index.js
│   │   │   ├── parsers
│   │   │   │   ├── BancoEstadoPurchaseNotificationParser.js
│   │   │   │   ├── BaseBancoEstadoParser.js
│   │   │   │   └── index.js
│   │   │   └── test
│   │   │       └── BancoEstadoPurchaseNotificationParser.test.js
│   │   └── index.js
│   └── index.js
└── index.js

Directory: lib

This directory contains the core functionality and base classes. It should not be needed to modify this if you want to build a custom version. Only savvy developers should modify files here.

Example Structure

$ tree -L 4 lib
lib
├── Config.js
├── Constants.js
├── Email.js
├── actions
│   ├── BaseAction.js
│   ├── README.adoc
│   └── index.js
├── currencies
│   ├── BaseCurrency.js
│   └── index.js
├── parsers
│   ├── BaseParser.js
│   ├── Formatters.js
│   ├── README.adoc
│   ├── Types.js
│   ├── Validators.js
│   └── index.js
└── test
    └── makeEmail.js

Makefile

The Makefile is used for command standarization.

make install

Will install all dependencies.

make release

Will build and create the files inside dist/.

make lint

Will make linting process.

Actions

Contains all the available actions for emails. Actions can be run for each email found (any directory) or specifically for each entity (country/entity/actions directory). It’s recommended to select only the ones you will actually use. To have a more slim script. These actions will be executed in left to right order.

import SpreadSheetAction from "./SpreadSheetAction";
export default [SpreadSheetAction];

Available Actions

  • SpreadSheetAction.js: Save data to a specific Google Spreadsheet.

  • HttpAction: Call an http endpoint with the parsed data.

Parsers

This directory contains all the available parsers for emails. It’s recommended to select only the ones you will actually use. To have a more slim script.

import BancoEstado from "./BancoEstado";

export default [BancoEstado];

Labels

Each parser will have a designated label that you must configure first in your Gmail account (using a filter) This is the way to determine which parser will be used to extract the data.

It’s recommended to use a parent label named biyete to organize better your emails and labels related to biyete.

gmail

Label Format

A label must follow the format {type}:{countrycode}-{entity}:{context} (without spaces).

Example expense:cl-bancoestado:purchase-notifications

  • type: expense

  • entity: bancoestado

  • context: purchase-notifications

Note: {context} must be plural.

Available Types

  • expense: money out.

  • deposit: money in.

  • alert: some payment or another money related action will be done in the future.

  • other: misc.

Return

The parser should return an object with the following properties.

{
  amount: 0, // The amount inside the email content.
  context: '', // Normally the store, the person, or similar info to give context to the transaction.
  account: '', // Associated card number, user account or any other info from wich the transaction took place.
  date: {
    formatter: {}, // DayJS object or similar date formatter
    raw: '' // Raw date string
  },
  name: this.name, // Parser Name.
  type: this.type, // Parser type expense, deposit, alert, other.
  label: this.label, // Parser label.
  entity: this.entity, // Which bank or entity processed the email.
  currency: this.currency, // Currency associated with the ammount.
  meta: {}, // Any other info not fit in the previous properties.
  comment: '', // Additional comment.
  createdAt: createdAt || new Date(), // When this was processed.
  version: this.version,
  parsed: false // tells if the parse was successful
}

Creating a Parser

The first thing you need is the base text of the email. Is recommended to obtain a text representation of the email. You could use "Show Original" option to open a text only representation. Using that you could create a regular expression to parse the data. Is recommended to use https://regex101.com/ for testing your regex.

gmail2

Available Parsers