Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fc6da4e9aa | |||
| f7411d3dc4 | |||
| 7be2ec605c |
@@ -32,24 +32,18 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
const productName = formData.get('productName') as string | null;
|
||||
|
||||
if (!name || !email || !message) {
|
||||
logger.warn(
|
||||
{
|
||||
name: !!name,
|
||||
email: !!email,
|
||||
message: !!message,
|
||||
},
|
||||
'Missing required fields in contact form',
|
||||
);
|
||||
logger.warn('Missing required fields in contact form', {
|
||||
name: !!name,
|
||||
email: !!email,
|
||||
message: !!message,
|
||||
});
|
||||
return { success: false, error: 'Missing required fields' };
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{
|
||||
type: productName ? 'product_quote' : 'contact',
|
||||
email,
|
||||
},
|
||||
'Payload CMS saving skipped because it has been removed',
|
||||
);
|
||||
logger.info('Payload CMS saving skipped because it has been removed', {
|
||||
type: productName ? 'product_quote' : 'contact',
|
||||
email,
|
||||
});
|
||||
|
||||
// 1.5. Simple Fail-Safe Backup to Disk
|
||||
// To ensure leads are never lost if email fails or Gotify is down, we append them to a local JSON Lines file.
|
||||
@@ -68,13 +62,13 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
message,
|
||||
};
|
||||
fs.appendFileSync(backupFile, JSON.stringify(leadData) + '\n');
|
||||
logger.info({ backupFile }, 'Successfully saved lead to local backup file');
|
||||
logger.info('Successfully saved lead to local backup file', { backupFile });
|
||||
} catch (backupError) {
|
||||
logger.error({ error: String(backupError) }, 'Failed to write to local leads backup');
|
||||
logger.error('Failed to write to local leads backup', { error: String(backupError) });
|
||||
}
|
||||
|
||||
// 2. Send Emails
|
||||
logger.info({ email, productName }, 'Sending branded emails');
|
||||
logger.info('Sending branded emails', { email, productName });
|
||||
|
||||
const notificationSubject = productName
|
||||
? `Product Inquiry: ${productName}`
|
||||
@@ -94,7 +88,7 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
);
|
||||
|
||||
if (!isTestSubmission) {
|
||||
logger.info({ recipients: env.MAIL_RECIPIENTS }, 'Sending internal notification');
|
||||
logger.info('Sending internal notification', { recipients: env.MAIL_RECIPIENTS });
|
||||
const notificationResult = await sendEmail({
|
||||
replyTo: email,
|
||||
subject: notificationSubject,
|
||||
@@ -102,21 +96,15 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
});
|
||||
|
||||
if (notificationResult.success) {
|
||||
logger.info(
|
||||
{
|
||||
messageId: notificationResult.messageId,
|
||||
},
|
||||
'Notification email sent successfully',
|
||||
);
|
||||
logger.info('Notification email sent successfully', {
|
||||
messageId: notificationResult.messageId,
|
||||
});
|
||||
} else {
|
||||
logger.error(
|
||||
{
|
||||
error: notificationResult.error,
|
||||
subject: notificationSubject,
|
||||
recipients: env.MAIL_RECIPIENTS,
|
||||
},
|
||||
'Notification email DELIVERY FAILED',
|
||||
);
|
||||
logger.error('Notification email DELIVERY FAILED', {
|
||||
error: notificationResult.error,
|
||||
subject: notificationSubject,
|
||||
recipients: env.MAIL_RECIPIENTS,
|
||||
});
|
||||
services.errors.captureException(
|
||||
new Error(`Notification email failed: ${notificationResult.error}`),
|
||||
{
|
||||
@@ -127,7 +115,7 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.info({ email }, 'Skipping notification email for test submission');
|
||||
logger.info('Skipping notification email for test submission', { email });
|
||||
}
|
||||
|
||||
// 2b. Send confirmation to Customer (branded as KLZ Cables)
|
||||
@@ -140,7 +128,7 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
);
|
||||
|
||||
if (!isTestSubmission) {
|
||||
logger.info({ to: email }, 'Sending customer confirmation');
|
||||
logger.info('Sending customer confirmation', { to: email });
|
||||
const confirmationResult = await sendEmail({
|
||||
to: email,
|
||||
subject: confirmationSubject,
|
||||
@@ -148,28 +136,22 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
});
|
||||
|
||||
if (confirmationResult.success) {
|
||||
logger.info(
|
||||
{
|
||||
messageId: confirmationResult.messageId,
|
||||
},
|
||||
'Confirmation email sent successfully',
|
||||
);
|
||||
logger.info('Confirmation email sent successfully', {
|
||||
messageId: confirmationResult.messageId,
|
||||
});
|
||||
} else {
|
||||
logger.error(
|
||||
{
|
||||
error: confirmationResult.error,
|
||||
subject: confirmationSubject,
|
||||
to: email,
|
||||
},
|
||||
'Confirmation email DELIVERY FAILED',
|
||||
);
|
||||
logger.error('Confirmation email DELIVERY FAILED', {
|
||||
error: confirmationResult.error,
|
||||
subject: confirmationSubject,
|
||||
to: email,
|
||||
});
|
||||
services.errors.captureException(
|
||||
new Error(`Confirmation email failed: ${confirmationResult.error}`),
|
||||
{ action: 'sendContactFormAction_confirmation', email },
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.info({ email }, 'Skipping confirmation email for test submission');
|
||||
logger.info('Skipping confirmation email for test submission', { email });
|
||||
}
|
||||
|
||||
// Notify via Gotify (Internal)
|
||||
@@ -187,13 +169,10 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : String(error);
|
||||
logger.error(
|
||||
{
|
||||
error: errorMsg,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
},
|
||||
'Failed to send branded emails',
|
||||
);
|
||||
logger.error('Failed to send branded emails', {
|
||||
error: errorMsg,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
|
||||
services.errors.captureException(error, { action: 'sendContactFormAction', email });
|
||||
|
||||
|
||||
@@ -7,14 +7,36 @@ export function fixMdxDataProps(content: string): string {
|
||||
let endIndex = -1;
|
||||
const startObj = dataIndex + 6; // index of the first '{' in 'data={{'
|
||||
|
||||
let inString = false;
|
||||
let isEscaped = false;
|
||||
|
||||
for (let i = startObj; i < fixedContent.length; i++) {
|
||||
if (fixedContent[i] === '{') {
|
||||
openCount++;
|
||||
} else if (fixedContent[i] === '}') {
|
||||
openCount--;
|
||||
if (openCount === 0) {
|
||||
endIndex = i;
|
||||
break;
|
||||
const char = fixedContent[i];
|
||||
|
||||
if (isEscaped) {
|
||||
isEscaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char === '\\') {
|
||||
isEscaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char === '"') {
|
||||
inString = !inString;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inString) {
|
||||
if (char === '{') {
|
||||
openCount++;
|
||||
} else if (char === '}') {
|
||||
openCount--;
|
||||
if (openCount === 0) {
|
||||
endIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
"prepare": "husky",
|
||||
"preinstall": "npx only-allow pnpm"
|
||||
},
|
||||
"version": "2.3.29",
|
||||
"version": "2.3.31",
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"@parcel/watcher",
|
||||
|
||||
@@ -8,10 +8,15 @@ describe('MDX Data Props Fixer', () => {
|
||||
|
||||
const result = fixMdxDataProps(mdxInput);
|
||||
|
||||
// The expected output should have the entire JSON object enclosed in data="{...}"
|
||||
// and NO trailing characters left over from the regex truncating early.
|
||||
const expected = `<Block type="productTabs" data="{"content":{"root":{"children":[]}},"id":"123"}" />`;
|
||||
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
it('should not prematurely truncate if } appears inside a string literal', () => {
|
||||
const mdxInput = `<Block type="productTabs" data={{"content":{"text":"}>"}}} />`;
|
||||
const result = fixMdxDataProps(mdxInput);
|
||||
const expected = `<Block type="productTabs" data="{"content":{"text":"}>"}}" />`;
|
||||
expect(result).toBe(expected.replace('>', '>'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user