npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dtorn/contact-api-core

v1.0.12

Published

The `API` that handles all contact-related requests from a website that implements it as the backend

Downloads

10

Readme

@dtorn/contact-api-core

The API that handles all contact-related requests from a website that implements it as the backend.


Node.js version: 12.20.0


Setup

npm install @dtorn/contact-api-core --save

Application structure


root
-- config
---- data.json
---- development.js
---- index.js
---- local.js
---- production.js
---- staging.js
-- language
---- el.js // any 'language code' could be here as long as it's added to the index.js's default language
---- index.js
-- public
---- images
-------- favicon.ico
-------- logo.png
.env
.env.development
.env.local
.env.production
.env.staging
index.js

Config

// config/data.json
{
  "users": [
    {
      "id": "671ec03e-edbb-4a3d-8dda-05558e05b0d0"
    }
  ]
}
// config/index.js
require("dotenv").config();
const local = require("./local");
const development = require("./development");
const staging = require("./staging");
const production = require("./production");

let config;

switch (process.env.NODE_ENV) {
  case "local":
    config = local;
    break;
  case "development":
    config = development;
    break;
  case "staging":
    config = staging;
    break;
  case "production":
    config = production;
    break;
  default:
    config = local;
    break;
}

module.exports = config;
// config/local.js
const Local = {
  apiPath: "",
  apiVersion: "",
  protocol: "",
  domain: "",
  url: "",
  website: {
    domain: "",
    url: "",
  },
  email: {
    contact: "",
    administrator: "",
  },
  launchYear: 0,
  preferences: {
    sendMessageEmail: false,
  },
};

module.exports = Local;

Language

// language/index.js
const EL = require("./el");

module.exports = {
  el: EL,
  default: "el",
};
// language/EL.js
module.exports = {
  identity: {
    brandName: "",
    legalName: "",
    address: "",
    postalCode: "",
    country: "",
    email: "",
    phone: "",
  },
  name: "",
  phone: "",
  email: "",
  message: "",
  thankYouTitle: "",
  thankYouForContactingUs: "",
  messageReceived: "",
  cantSeeThisMessage: "",
  viewItInBrowser: "",
  messageSent: "",
  yourContactDetails: "",
  thankYouMessage: "",
  moto: "",
  contactForm: {
    title: "",
    clientSubject: "",
  },
};

index.js

// index.js
require("contact-api-core");

.env

  • Create a new .env file for each development environment. Usually it would be:

    • .env: the current debug environment
    • .env.local: local environment
    • .env.development: development environment (continuous integration)
    • .env.staging: staging environment (release testing)
    • .env.production: production environment
  • local – used for workstation testing, e.g. http://localhost:8000

  • development – used for development testing, e.g. https://dev.{DOMAIN_NAME}

  • staging – used for release testing, e.g. https://sta.{DOMAIN_NAME}

  • production – used for production, e.g. https://{DOMAIN_NAME}

# sample-env file

# NODE_ENV

# ENCRYPTION_KEY

# JWT_TOKEN_KEY
# JWT_TOKEN_EXPIRATION

# DB_USERNAME
# DB_PASSWORD
# DB_DATABASE
# DB_HOST
# DB_DIALECT

# EMAIL_HOST
# EMAIL_USERNAME
# EMAIL_PASSWORD
# Configure .env files
echo .sample-env > .env.local
echo .sample-env > .env.development
echo .sample-env > .env.staging
echo .sample-env > .env.production
echo .env.local > .env

Notes

Tools
Guides

Changelog

14/04/2023 1.0.11
  • Add support to define custom DB_PORT and PORT through environmental variables
09/05/2021 1.0.10
  • Change the request data for the authorization request. Make it simplier by requiring just { id: '...' } instead of { user: { id: '' } }
07/03/2021 1.0.9
  • Fix problematic path in validations hook file
07/03/2021 1.0.8
  • Implement validation hooks in controllers and tested
07/03/2021 1.0.8-beta
  • Implement validation hooks in controllers
22/02/2021 1.0.7
  • Fix class issues regarding property declaration:
    • libs/external-request-verification-handler.js
    • libs/encrypt.js
20/02/2021 1.0.6
  • Unsubscribe only if input email exists in messages
  • Remove await from send email promise. The server must respond right after the record is stored in the database
19/02/2021 1.0.5
  • Fix config/data.json path (from seeder file)
  • Add console.log on sequelize actions
19/02/2021 1.0.4
  • Fix config / language paths
19/02/2021 1.0.3
  • Add morgan as a dependency instead of a dev dependency
19/02/2021 1.0.2
  • Fix tests path issues (config and language)
  • Better handle default config and language index files
19/02/2021 1.0.1
  • Initial npm package publish
  • Structure fixes
  • Remove sensitive data
18/02/2021 1.0.0
  • Restructure the project and make it generic
  • Change email recepient in all environments except production to be the email.administrator