mailery 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4691,6 +4691,40 @@ ${input.plainText}`);
4691
4691
  });
4692
4692
  }
4693
4693
  }
4694
+ const offDomain = findOffDomainLinkHosts(input.html, input.fromEmail);
4695
+ if (offDomain.majority && offDomain.hosts.length > 0) {
4696
+ issues.push({
4697
+ rule: "offdomain_links",
4698
+ severity: "warning",
4699
+ message: `Most links point away from the From domain: ${offDomain.hosts.join(", ")}.`,
4700
+ hint: "Link domains that match the sending domain build reputation. Route links through your own domain (or a tracking subdomain of it) where you can."
4701
+ });
4702
+ }
4703
+ const insecure = findInsecureLinkHosts(input.html);
4704
+ if (insecure.length > 0) {
4705
+ issues.push({
4706
+ rule: "insecure_link",
4707
+ severity: "warning",
4708
+ message: `Link uses plain http://: ${insecure.join(", ")}.`,
4709
+ hint: "Mixed-content links get rewritten or warned about by some clients, and http:// correlates with stale spam templates. Use https://."
4710
+ });
4711
+ }
4712
+ if (countImagesMissingAlt(input.html) > 0) {
4713
+ issues.push({
4714
+ rule: "image_missing_alt",
4715
+ severity: "warning",
4716
+ message: "One or more images have no alt text.",
4717
+ hint: "Most clients block images by default on first open. Alt text is what the recipient actually sees, and screen readers need it."
4718
+ });
4719
+ }
4720
+ if (hasImageOnlyLink(input.html)) {
4721
+ issues.push({
4722
+ rule: "image_only_link",
4723
+ severity: "warning",
4724
+ message: "A link wraps an image with no accompanying text.",
4725
+ hint: "With images blocked, an image-only call-to-action is invisible and unclickable. Add a text label inside the link."
4726
+ });
4727
+ }
4694
4728
  const linkCount = countMatches(input.html, /<a\s[^>]*\bhref\s*=/gi);
4695
4729
  if (linkCount > 10) {
4696
4730
  issues.push({
@@ -4745,6 +4779,63 @@ function hasBareUrlInVisibleText(html) {
4745
4779
  const stripped = html.replace(/<a\b[^>]*>.*?<\/a>/gis, " ").replace(/<style\b[^>]*>.*?<\/style>/gis, " ").replace(/<script\b[^>]*>.*?<\/script>/gis, " ").replace(/<head\b[^>]*>.*?<\/head>/gis, " ");
4746
4780
  return /https?:\/\/[^\s<>"']+/i.test(stripped);
4747
4781
  }
4782
+ function findOffDomainLinkHosts(html, fromEmail) {
4783
+ const fromDomain = fromEmail.split("@")[1]?.toLowerCase();
4784
+ if (!fromDomain) return { hosts: [], majority: false };
4785
+ const hosts = /* @__PURE__ */ new Set();
4786
+ let total = 0;
4787
+ let off = 0;
4788
+ for (const href of extractHrefs(html)) {
4789
+ if (href.includes("{{")) continue;
4790
+ const host = hostnameOf(href);
4791
+ if (!host) continue;
4792
+ total++;
4793
+ if (sameSite(host, fromDomain)) continue;
4794
+ off++;
4795
+ hosts.add(host);
4796
+ }
4797
+ return { hosts: Array.from(hosts), majority: total > 0 && off * 2 > total };
4798
+ }
4799
+ function sameSite(a, b) {
4800
+ if (a === b) return true;
4801
+ if (a.endsWith(`.${b}`) || b.endsWith(`.${a}`)) return true;
4802
+ return lastLabels(a) === lastLabels(b);
4803
+ }
4804
+ function lastLabels(host) {
4805
+ return host.split(".").slice(-2).join(".");
4806
+ }
4807
+ function findInsecureLinkHosts(html) {
4808
+ const hits = /* @__PURE__ */ new Set();
4809
+ for (const href of extractHrefs(html)) {
4810
+ if (!/^http:\/\//i.test(href)) continue;
4811
+ const host = hostnameOf(href);
4812
+ if (host) hits.add(host);
4813
+ }
4814
+ return Array.from(hits);
4815
+ }
4816
+ function countImagesMissingAlt(html) {
4817
+ let missing = 0;
4818
+ const re = /<img\b[^>]*>/gi;
4819
+ let m;
4820
+ while (m = re.exec(html)) {
4821
+ const tag = m[0];
4822
+ const alt = /\balt\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(tag);
4823
+ const value = alt ? alt[1] ?? alt[2] ?? alt[3] ?? "" : "";
4824
+ if (value.trim().length === 0) missing++;
4825
+ }
4826
+ return missing;
4827
+ }
4828
+ function hasImageOnlyLink(html) {
4829
+ const re = /<a\b[^>]*>(.*?)<\/a>/gis;
4830
+ let m;
4831
+ while (m = re.exec(html)) {
4832
+ const inner = m[1];
4833
+ if (!/<img\b/i.test(inner)) continue;
4834
+ const text = inner.replace(/<[^>]*>/g, "").replace(/&nbsp;/gi, " ").trim();
4835
+ if (text.length === 0) return true;
4836
+ }
4837
+ return false;
4838
+ }
4748
4839
  function findSpamSignals(text) {
4749
4840
  const out = /* @__PURE__ */ new Set();
4750
4841
  for (const { pattern, phrase } of SPAM_PHRASES) {
@@ -7608,7 +7699,7 @@ var DEDUPE_POLICIES = [
7608
7699
  ];
7609
7700
 
7610
7701
  // src/server/index.ts
7611
- var VERSION = "0.11.0" ;
7702
+ var VERSION = "0.12.0" ;
7612
7703
 
7613
7704
  export { DEDUPE_POLICIES, FLOW_STEP_KINDS, Mailer, MongoContactAdapter, NullProvider, PREDICATE_KINDS, RESERVED_VAR_KEYS, SEGMENT_FILTER_KINDS, SendGridProvider, VERSION, applyTracking, applyWebhookEvent, compileMailyTemplate, compileTemplate, computeDeliveryTime, createAdminRouter, createPublicRouter, defaultFlowStep, defaultPredicate, defaultSegmentFilter, defineVars, derivePlaintext, dispatchSend, ensureIndexes, getCollections, predicateKind, processNewlyFiredEventTriggers, processOneRunStep, renderTemplate, runTick, sha256Hex, signUnsubscribeToken, sweepStrandedFlowRuns, validateSenderDomain, varsJsonSchema, verifyUnsubscribeToken };
7614
7705
  //# sourceMappingURL=index.js.map