refactor phase 4 hardening helpers and redacted logging
This commit is contained in:
@@ -25,11 +25,19 @@
|
||||
* description: Failed
|
||||
*/
|
||||
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { consoleLogger, redactSensitive } from "../../../actions/core/logger";
|
||||
import { isNonEmptyString, sanitizeString } from "../../../actions/core/guards";
|
||||
import { getPreferredLanguage } from "../../../actions/services/accountService";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var data = req.body;
|
||||
const emailAddress = sanitizeString(data?.emailAddress);
|
||||
|
||||
if (!isNonEmptyString(emailAddress)) {
|
||||
return res.status(400).json({ error: "emailAddress is required" });
|
||||
}
|
||||
|
||||
data.emailAddress = emailAddress;
|
||||
|
||||
if (data?.reference === "PEDW-NEW-CASEREF") {
|
||||
try {
|
||||
@@ -50,7 +58,10 @@ export default async function ApiProxy(req, res) {
|
||||
const notifyClient = new NotifyClient(process.env.NOTIFY_API_KEY);
|
||||
//const emailReplyToId = process.env.EMAIL_REPLY_TO_ID;
|
||||
|
||||
console.log("///////////////\n Sending email \ns//////////////", data);
|
||||
console.log(
|
||||
"///////////////\n Sending email \ns//////////////",
|
||||
redactSensitive(data)
|
||||
);
|
||||
|
||||
notifyClient
|
||||
.sendEmail(data.templateId, data.emailAddress, {
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { isNonEmptyString, sanitizeString } from "../../../actions/core/guards";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { getCaseBlob } from "../../../actions/azurestorage";
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
@@ -66,6 +68,17 @@ const hashAPIPath = (queryPath) => {
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var createTaskBody = req.body;
|
||||
|
||||
const contactEmail = sanitizeString(createTaskBody?.contactEmail);
|
||||
const contactSubject = sanitizeString(createTaskBody?.contactSubject);
|
||||
const contactBody = sanitizeString(createTaskBody?.contactbody);
|
||||
|
||||
if (!isNonEmptyString(contactEmail) || !isNonEmptyString(contactSubject)) {
|
||||
return res.status(400).json({
|
||||
error: "contactEmail and contactSubject are required"
|
||||
});
|
||||
}
|
||||
|
||||
var queryUrl = "tasks";
|
||||
var token = await getToken();
|
||||
|
||||
@@ -87,8 +100,8 @@ export default async function ApiProxy(req, res) {
|
||||
let teamId = teamMap[contactValue];
|
||||
|
||||
const payload = {
|
||||
"subject": `Contact Us Enquiry - ${createTaskBody.contactSubject}`,
|
||||
"description": `From: ${createTaskBody.contactEmail}\n\n${createTaskBody.contactbody}`,
|
||||
"subject": `Contact Us Enquiry - ${contactSubject}`,
|
||||
"description": `From: ${contactEmail}\n\n${contactBody}`,
|
||||
"scheduledstart": new Date().toISOString(),
|
||||
"scheduledend": new Date(
|
||||
new Date().getTime() + 60 * 60000 * 24
|
||||
@@ -118,10 +131,7 @@ export default async function ApiProxy(req, res) {
|
||||
const { data } = await axios(config);
|
||||
return res.status(200).json(data);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"CRM Task Creation Error:",
|
||||
error.response?.data || error
|
||||
);
|
||||
consoleLogger(error);
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "Failed to create CRM task", details: error });
|
||||
|
||||
@@ -19,7 +19,12 @@ import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import {
|
||||
escapeODataString,
|
||||
isNonEmptyString,
|
||||
sanitizeString
|
||||
} from "../../../actions/core/guards";
|
||||
import { consoleLogger, redactSensitive } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
@@ -38,15 +43,19 @@ const hashAPIPath = (queryPath) => {
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var emailAddress = req.query.emailAddress;
|
||||
var emailAddress = sanitizeString(req.query.emailAddress);
|
||||
var token = await getToken();
|
||||
|
||||
if (!isNonEmptyString(emailAddress)) {
|
||||
return res.status(400).json({ error: "emailAddress is required" });
|
||||
}
|
||||
|
||||
var queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
emailAddress +
|
||||
escapeODataString(emailAddress) +
|
||||
"'&$count=true&$select=pinswg_preferredlanguage,contactid";
|
||||
|
||||
console.log(queryUrl);
|
||||
console.log(redactSensitive(queryUrl));
|
||||
// var queryUrl = "contacts/?$count=true&$select=emailaddress1, contactid";
|
||||
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
|
||||
Reference in New Issue
Block a user