Initial MVP test

This commit is contained in:
Elizabeth Cray 2024-10-04 18:41:01 -04:00
commit 28391f5b18
5 changed files with 1577 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/*

19
eslint.config.mjs Normal file
View File

@ -0,0 +1,19 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import stylistic from '@stylistic/eslint-plugin';
export default [
{
languageOptions: {
globals: globals.node
},
plugins: {
'@stylistic': stylistic
},
rules : {
'@stylistic/indent': ['error', 2],
'no-useless-escape' : 'off'
}
},
pluginJs.configs.recommended,
];

37
index.mjs Normal file
View File

@ -0,0 +1,37 @@
export const handler = async (event) => {
let result = "did not send";
if (event.subject == "You have deliveries" || event.subject == "You have a delivery"){
// Trigger home notification
const command = `ssh ${process.env.INTERNAL_HOST} "/usr/bin/tmux neww -d \"/usr/bin/mplayer '${process.env.INTERNAL_FILE}'\""`;
const { Client } = require('ssh2');
const connection = new Client();
connection.on('ready', () => {
connection.exec(command, (error, stream) => {
if (error) {
console.warn(error);
result = JSON.stringify(error);
}
stream.on('close', (code, signal) => {
// COMPLETE
console.info("Trigger completed", code, signal)
}).stderr.on('data', (data) => {
// STDERR
console.warn(data);
});
});
}).connect({
host: process.env.TRIGGER_HOST,
port: 22,
username: process.env.TRIGGER_USERNAME,
privateKey: process.env.TRIGGER_PRIVATEKEY
});
}
const response = {
statusCode: 200,
body: {
result
},
};
return response;
};

1495
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "deliveries",
"version": "1.0.0",
"description": "Trigger notif from matching WorkMail email",
"main": "index.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.corrupt.link:liz/deliveries.git"
},
"author": "Elizabeth Cray",
"license": "Apache-2.0",
"dependencies": {
"@stylistic/eslint-plugin": "^2.8.0",
"ssh2": "^1.16.0"
},
"devDependencies": {
"@eslint/js": "^9.12.0",
"@stylistic/eslint-plugin-js": "^2.8.0",
"eslint": "^9.12.0",
"globals": "^15.10.0"
}
}