UNPKG

@accounter/server

Version:
36 lines (35 loc) 1.83 kB
/** * Wildcard-aware matching for business-recognition emails * (`suggestion_data.emails`). * * Some suppliers send invoices from a unique address per invoice * (e.g. `qr45uf@cloudflare.com`). To recognize such a business its recognition * emails may store a wildcard pattern like `*@cloudflare.com`, where `*` matches * any (possibly empty) run of characters. Matching is case-insensitive. * * The SQL lookups (`BusinessesProvider.getBusinessByEmail` and * `EmailIngestionControlProvider`'s ingest query) translate `*` to a `LIKE` * wildcard directly in the database; this helper is the source of truth for the * pattern shape (used on write, see the suggestion-data schema) and provides an * equivalent in-process matcher for tests and non-DB call sites. */ /** A wildcard pattern is any recognition entry containing a `*`. */ export declare function isWildcardEmailPattern(value: string): boolean; /** * Validate a wildcard recognition entry. Non-wildcard entries are plain email * addresses and are validated elsewhere (the suggestion-data schema); this only * covers entries that actually contain a `*`. * * Beyond the email shape, the domain must carry at least one concrete label * (2+ characters, no `*`) before the TLD, so an over-broad pattern such as * `*@*.com` — which would route nearly every sender to a single business — is * rejected while a scoped pattern like `*@cloudflare.com` (or `*@*.cloudflare.com`) * is allowed. */ export declare function isValidWildcardEmailPattern(value: string): boolean; /** * Case-insensitively test whether `email` matches a stored recognition * `pattern`. A pattern without `*` must match exactly; each `*` matches any * (possibly empty) run of characters. */ export declare function emailMatchesPattern(pattern: string, email: string): boolean;