feat: Add headless template type

This commit is contained in:
Dries Augustyns
2026-04-02 12:43:27 +02:00
parent 284838279d
commit fb5aa8796a
16 changed files with 334 additions and 121 deletions
+1
View File
@@ -2,3 +2,4 @@ export * from './schemas/index.js';
export * from './operators.js';
export * from './template.js';
export * from './i18n/index.js';
export * from './unsubscribe.js';
+26
View File
@@ -0,0 +1,26 @@
/**
* Detects whether an email body contains an unsubscribe signal.
*
* Used to warn authors of HEADLESS emails that no unsubscribe mechanism
* was found — Plunk cannot verify the link works, but can check for common patterns.
*
* Returns true if any of the following are present:
* - Plunk template variables: {{unsubscribeUrl}} or {{manageUrl}}
* - An <a> tag whose href contains unsubscribe-related keywords
* - An <a> tag whose visible text contains unsubscribe-related keywords
*/
export function detectUnsubscribeSignal(body: string): boolean {
if (!body) return false;
// Plunk's own managed unsubscribe variables
if (/\{\{(?:unsubscribeUrl|manageUrl)\}\}/.test(body)) return true;
// href containing unsubscribe keywords
if (/href=["'][^"']*(?:unsubscribe|opt[_-]?out|remove)[^"']*["']/i.test(body)) return true;
// Anchor text containing unsubscribe keywords
if (/<a\b[^>]*>(?:[^<]*(?:unsubscribe|opt[_-]?\s*out|manage\s+preferences|email\s+preferences|remove\s+me)[^<]*)<\/a>/i.test(body))
return true;
return false;
}