Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simplert

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplert - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

bin/generate-gmail-creds.js

33

bin/generate-config.js
#!/usr/bin/env node
const path = require("path");
const DEFAULT_CONFIG_NAME = "simplert.cfg.json"
const DEFAULT_CONFIG_NAME = "simplert.json";
let config_name = DEFAULT_CONFIG_NAME;
const fs = require('fs');
const readline = require('readline').createInterface({
const fs = require("fs");
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout
})
});
readline.question(`Name your config file (${DEFAULT_CONFIG_NAME}) `, (filename) => {
if(filename) config_name = filename;
readline.question(
`Name your config file (${DEFAULT_CONFIG_NAME}) `,
filename => {
if (filename) config_name = filename;
fs.copyFile(path.resolve(__dirname + "/..") + `/${DEFAULT_CONFIG_NAME}`, config_name, fs.constants.COPYFILE_EXCL, (err) => {
if (err) throw err;
console.log(`${config_name} was successfully generated`);
});
fs.copyFile(
path.resolve(__dirname + "/..") + `/${DEFAULT_CONFIG_NAME}`,
config_name,
fs.constants.COPYFILE_EXCL,
err => {
if (err) throw err;
console.log(`${config_name} was successfully generated`);
}
);
readline.close()
})
readline.close();
}
);
const path = require("path");
const Discord = require("discord.js");
const discord_client = new Discord.Client();
const { google } = require("googleapis");
let user_config = {};
let discordLoggedIn = false;
let gmailAuth = "";

@@ -11,3 +13,3 @@ exports.configure = function(file) {

user_config = require(path.resolve(`${__dirname}/../../${file}`));
template_config = require(__dirname + "/simplert.cfg.json");
template_config = require(__dirname + "/simplert.json");

@@ -19,6 +21,23 @@ user_keys = getAllKeys(user_config);

throw "Your simplert config file is not up to date, use the generate command to get the most up to date version";
if (user_config.email.gmail.enabled) {
const {
client_secret,
client_id,
redirect_uris
} = user_config.email.gmail.credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id,
client_secret,
redirect_uris[0]
);
oAuth2Client.setCredentials(user_config.email.gmail.token);
gmailAuth = oAuth2Client;
}
} catch (e) {
if (e.code === "MODULE_NOT_FOUND") {
throw new Error(
"Could not file specified. Make sure file path is correct."
`Could not file specified. Make sure file path is correct. ${path.resolve(
__dirname + "/../../" + file
)}`
);

@@ -70,2 +89,62 @@ } else {

exports.email = function(
body,
send_to = user_config.email.gmail.send_to,
subject = user_config.email.gmail.subject,
send_from = user_config.email.gmail.send_from
) {
return new Promise(async (resolve, reject) => {
let error;
if (!user_config.email.gmail.enabled)
error =
"Gmail alert is not enabled. You need to enable it in your simplert config file";
else if (!body)
error =
".email() requires at least 1 argument. Pass it a message to send in the email body";
else if (!send_to)
error =
"You need to specify a receipient email either in your simplert config file or passed into .email()";
else if (!subject)
error =
"You need to specify an email subject either in your simplert config file or passed into .email()";
else if (!send_from)
error =
"You need to specify a sender email either in your simplert config file or passed into .email()";
if (error) reject(new Error(error));
const gmail = google.gmail({ version: "v1", auth: gmailAuth });
const utf8Subject = `=?utf-8?B?${Buffer.from(subject).toString(
"base64"
)}?=`;
const messageParts = [
`From: ${send_from}`,
`To: ${send_to}`,
"Content-Type: text/html; charset=utf-8",
"MIME-Version: 1.0",
`Subject: ${utf8Subject}`,
"",
`${body}`
];
const message = messageParts.join("\n");
const encodedMessage = Buffer.from(message)
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
const email = await gmail.users.messages.send({
userId: "me",
requestBody: {
raw: encodedMessage
}
});
resolve(email);
});
};
function getAllKeys(data) {

@@ -72,0 +151,0 @@ const parent_keys = Object.keys(data);

{
"name": "simplert",
"version": "0.1.7",
"version": "0.2.0",
"description": "Simple way to send alerts via Slack, Email, Discord, SMS, etc.",

@@ -8,9 +8,34 @@ "main": "index.js",

"bin": {
"generate-config": "./bin/generate-config.js"
"generate-config": "./bin/generate-config.js",
"generate-gmail": "./bin/generate-gmail-creds.js"
},
"author": "Nicholas Dangles",
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/ndangles/simplert.git"
},
"keywords": [
"simple alerts",
"simple events",
"simplert",
"alerts",
"events",
"discord alerts",
"gmail alerts",
"gmail",
"send alert",
"easy alerts",
"send email",
"discord"
],
"bugs": {
"url": "https://github.com/ndangles/simplert/issues"
},
"readme": "README.md",
"homepage": "https://github.com/ndangles/simplert#readme",
"dependencies": {
"discord.js": "^11.5.1"
"discord.js": "^11.5.1",
"googleapis": "^45.0.0"
}
}
# Simplert
Simple way to send alerts via Slack, Email, Discord, SMS, etc. Simplert is currently geared towards personal and smaller apps where you just want a simple way to alert on some event like when a new user signs up. I would advise against using this in any critical production apps as of now.
Simple way to send alerts via Slack, Email, Discord, SMS, etc. Simplert is currently geared towards personal and smaller apps where you just want a simple way to alert on some event like when a new user signs up. The idea is that you can just drop your simplert config file in any of your projects and quickly starting alerting on events. I would advise against using this in any critical production apps as of now.

@@ -14,43 +14,67 @@ ## Getting Started

"send_to": ""
},
"email": {
"gmail": {
"enabled": false,
"send_to": "",
"send_from": "",
"subject": "",
"token": {},
"credentials": {}
}
}
}
***enabled*** - whether you want this type of alerting enabled or not
***token*** - the token of your discord bot
***send_to*** - the name of the discord channel you want to send your alerts too. Make sure your bot has permission on the server to send messages
***enabled*** - whether you want this type of alerting enabled or not
***discord:token*** - the token of your discord bot
***discord:send_to*** - the name of the discord channel you want to send your alerts too. Make sure your bot has permission on the server to send messages
***email:gmail:send_to*** - the default receipient email you want to send to, otherwise passed into the email function
***email:gmail:send_from*** - The default email you want to send from. You may have a Gsuite account with multiple aliases that you can specifiy here which one you want to send from. Otherwise passed into the email function
***email:gmail:subject*** - A default email subject for every alert, otherwise passed into the email function
***email:gmail:token*** - Used for authorization, can be generated with `npx simplert generate-gmail` assuming you have your `email:gmail:credentials` populated correctly.
***email:gmail:credentials*** - Credentials provided by Google when setting up your project in the [Google Cloud Console](https://console.cloud.google.com/) usually downloaded as `gmail-credentials.json`. Set this key as the contents of that file.
## Usage
*Note: Make sure you have setup your configuration file*
*Note: Make sure you have setup your configuration file*
### Web Server
const express = require("express")
const app = express();
---
#### **simplert.discord(message,[send_to])**
Send a message to a discord channel.
`send_to` can be optional if it is specified in the configuration file under`discord:send_to` as the default, otherwise it needs to be passed in as the second argument
const simplert = require("simplert");
simplert.configure("simplert.cfg.json")
app.get("/test", async (req, res) => {
simplert.discord("server test")
res.send("alert sent")
})
simplert.configure("simplert.json");
app.listen(8849, "127.0.0.1", (req, res) => {
console.log("listening at localhost:8849")
})
simplert.discord("some event"); //assuming discord:send_to is set in config file
simplert.discord("some other event", "general"); // send to a different channel
---
#### **simplert.email(body,[send_to, subject, send_from])**
Send an email message
`send_to, subject, send_from` can be optional if defaults are set under `email:gmail:*` in the configuration file. Otherwise, they need to be passed as arguments to the function.
const simplert = require("simplert");
simplert.configure("simplert.json");
simplert.email("some event"); //assuming discord:send_to is set in config file
simplert.email("some other event", "email@example.com"); // send to a specific email
simplert.email("another event", "email@example.com", "Some Email Subject"); // set an email subject
simplert.email("and another event", "email@example.com", "Some Email Subject", "alias@example.com"); // set a send from alias if you use Gsuite
### Script
const simplert = require("simplert");
simplert.configure("simplert.cfg.json")
## Scripts
#### **generate-config**
`npx simplert generate-config`
Generates a simplert configuration file. By default, all alert will be set to disabled, you will need to manually configure the necessary values in this file before using simplert.
#### **generate-gmail**
`npx simplert generate-gmail`
This will generate an auth token and automatically populate the `email:gmail:token` value in your configuration file. This assumes that you have `email:gmail:credentials` set in your configuration file which should be set to the content in your `gmail-credentials.json` file that was download from Google Cloud Console when setting up a project.
async function run() {
await simplert.discord("some event")
await simplert.discord("some other event")
}
run();
## Supported Alerts
- #### [Discord](https://discordapp.com/)
*Email, Slack, SMS coming eventually*
#### [Discord](https://discordapp.com/)
#### [Gmail](https://mail.google.com)
*Slack and SMS coming eventually*

@@ -60,1 +84,2 @@ ## Bugs and Improvements

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