Compare commits

...

2 Commits

Author SHA1 Message Date
adueck e09f3b7d14 cleanup 2024-03-02 23:13:11 -05:00
adueck e0ef03a944 add ntfy 2024-03-02 22:46:48 -05:00
4 changed files with 65 additions and 45 deletions

View File

@ -11,6 +11,7 @@ const names = [
"LINGDOCS_ACCOUNT_UPGRADE_PASSWORD",
"STRIPE_SECRET_KEY",
"STRIPE_WEBHOOK_SECRET",
"NTFY_TOPIC",
];
const values = names.map((name) => ({
@ -20,7 +21,10 @@ const values = names.map((name) => ({
const missing = values.filter((v) => !v.value);
if (missing.length) {
console.error("Missing evironment variable(s):", missing.map((m) => m.name).join(", "));
console.error(
"Missing evironment variable(s):",
missing.map((m) => m.name).join(", ")
);
process.exit(1);
}
@ -37,4 +41,5 @@ export default {
upgradePassword: values[9].value,
stripeSecretKey: values[10].value,
stripeWebhookSecret: values[11].value,
ntfyTopic: values[12].value,
};

9
account/src/lib/ntfy.ts Normal file
View File

@ -0,0 +1,9 @@
import fetch from "node-fetch";
import envVars from "./env-vars";
export async function ntfy(message: string) {
fetch(`https://ntfy.sh/${envVars.ntfyTopic}`, {
method: "POST",
body: message,
}).catch(console.error);
}

View File

@ -15,6 +15,7 @@ import { outsideProviders } from "../middleware/setup-passport";
import * as T from "../../../website/src/types/account-types";
import env from "../lib/env-vars";
import Stripe from "stripe";
import { ntfy } from "./ntfy";
const stripe = new Stripe(env.stripeSecretKey, {
apiVersion: "2022-08-01",
@ -163,6 +164,7 @@ export async function createNewUser(
email: input.email || "",
token: email.token,
});
ntfy(`new LingDocs user ${input.name} - ${input.email}`);
const user = await insertLingdocsUser(newUser);
return user;
}

View File

@ -1,6 +1,7 @@
import express, { Response } from "express";
import * as T from "../../../website/src/types/account-types";
import { addFeedback } from "../lib/couch-db";
import { ntfy } from "../lib/ntfy";
// import env from "../lib/env-vars";
// TODO: ADD PROPER ERROR HANDLING THAT WILL RETURN JSON ALWAYS
@ -24,9 +25,12 @@ feedbackRouter.put("/", (req, res, next) => {
addFeedback({
user,
feedback,
}).then(() => {
})
.then(() => {
ntfy(JSON.stringify(feedback));
res.send({ ok: true, message: "feedback received" });
}).catch((e) => {
})
.catch((e) => {
console.error("error receiving feedback");
console.error("feedback missed", feedback);
console.error(e);