Mail relay: development hosts are known by pattern, with no env - built in: *.dev.netscale.pl

The launch rule called a site non-public only when IAPL_NOINDEX was set (or the project named its hosts).
The owner's development sites set nothing, so production's database copied onto a development address
counted as a launch and would have mailed real people.

- iapl({ developmentHosts }): host patterns of development addresses. Default DEFAULT_DEVELOPMENT_HOSTS =
  ['*.dev.netscale.pl'], Intecion's own development domain; a project replaces the list or empties it.
  mail.relay.developmentHosts overrides it for the mail service.
- a site whose host matches is non-public exactly as with IAPL_NOINDEX=1; either signal is enough
- siteNonPublicSignal, matchDevelopmentHost, isDevelopmentHost, pluginDevelopmentHosts exported
- panel state: nonPublicBy, nonPublicPattern; doctor: mail-non-public (info) names the signal
- every case of the launch table runs with no env on the built-in pattern
- docs, AGENT.md, skills, changelog draft

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 10:26:12 +01:00
co-authored by Claude Fable 5.2
parent 634908eb57
commit 14abf369da
26 changed files with 319 additions and 80 deletions
+20 -12
View File
@@ -2,13 +2,14 @@ import type { BasePayload } from 'payload'
import { randomBytes } from 'node:crypto'
import type { ResolvedRelayOptions } from './options.js'
import type { RelayOptions, ResolvedRelayOptions } from './options.js'
import { PLUGIN_VERSION } from '../../../version.js'
import { isSiteNoindex } from '../../seo/siteNoindex.js'
import { matchDevelopmentHost } from '../../shared/developmentHosts.js'
import { type RelayAnswer, type RelayRefusal, relayRequest } from './client.js'
import { RELAY_CONFIRM_PATH, RELAY_DEFAULTS, RELAY_PRODUCT, type RelayStatusCode, relayStatusFor } from './constants.js'
import { isPublicHost, pluginMailOptions, relayHost } from './options.js'
import { isPublicHost, pluginDevelopmentHosts, pluginMailOptions, relayHost } from './options.js'
import * as store from './store.js'
import { otherRelayHosts, type RelaySiteState, type RelayStored, releaseNonce, sha256Hex } from './store.js'
@@ -95,17 +96,24 @@ async function otherHostsNow(payload: BasePayload, host: string, fresh: boolean)
const bare = (host: string) => host.trim().toLowerCase().replace(/^www\./, '')
/** Why a site counts as non-public: its host matches a development pattern, or `IAPL_NOINDEX` is set. */
export type NonPublicSignal = { by: 'development-host'; pattern: string } | { by: 'noindex' }
/**
* Is this site a non-public copy — a development, preview or staging address? `IAPL_NOINDEX=1` (the switch
* such a site already has), or a host that matches `mail.relay.developmentHosts`.
* Which signal makes this site a non-public copy — a development, preview or staging address — or null for a
* public site. Either is enough: its host matches a development pattern (`mail.relay.developmentHosts`, else
* `iapl({ developmentHosts })`, else the built-in list — no environment variable needed), or `IAPL_NOINDEX=1`.
* The host is named first: it is the signal a site has without anybody setting anything.
*/
export function siteIsNonPublic(payload: BasePayload, options: Pick<ResolvedRelayOptions, 'developmentHosts' | 'host'>): boolean {
if (isSiteNoindex()) {return true}
const host = relayHost(payload, options)
return (options.developmentHosts ?? []).some((pattern) => {
const source = pattern.trim().toLowerCase().split('*').map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*')
return Boolean(source) && new RegExp(`^${source}$`).test(host)
})
export function siteNonPublicSignal(payload: BasePayload, options: Pick<RelayOptions, 'developmentHosts' | 'host'>): NonPublicSignal | null {
const pattern = matchDevelopmentHost(relayHost(payload, options), options.developmentHosts ?? pluginDevelopmentHosts(payload))
if (pattern) {return { by: 'development-host', pattern }}
return isSiteNoindex() ? { by: 'noindex' } : null
}
/** Is this site a non-public copy (`siteNonPublicSignal` as a yes or no)? */
export function siteIsNonPublic(payload: BasePayload, options: Pick<RelayOptions, 'developmentHosts' | 'host'>): boolean {
return siteNonPublicSignal(payload, options) !== null
}
/**
@@ -135,7 +143,7 @@ export async function otherHostsInTheWay(
}
const otherHostMessage = (host: string, foreign: string[]) =>
`This database holds the mail-service connection of another site (${foreign.join(', ')}), and this site ("${host}") is a non-public copy (IAPL_NOINDEX, or a development host) or set to wait: it does not connect or send by itself. Press "Connect again" in Site integrations → E-mail sending if it should send e-mails (mail.relay.otherHosts).`
`This database holds the mail-service connection of another site (${foreign.join(', ')}), and this site ("${host}") is a non-public copy (a development host, or IAPL_NOINDEX) or set to wait: it does not connect or send by itself. Press "Connect again" in Site integrations → E-mail sending if it should send e-mails (mail.relay.otherHosts).`
async function enrolOnce(payload: BasePayload, options: ResolvedRelayOptions, force: boolean, deadline?: number): Promise<EnrolResult> {
const stored = await readSiteStore(payload, options)