New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dtorn/contact-api-core

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dtorn/contact-api-core

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

  • 1.0.12
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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
  • REST API response structure
  • Sequelize ORM
  • NodeMailer mailing service
  • HeidiSQL program for testing the different database configuration environments
  • Check headers handling
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

FAQs

Package last updated on 14 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc