@sharadox/form-web-library 0.7.1-development.26 → 0.8.0-development.38

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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  What changed in each version of `@sharadox/form-web-library`, newest first.
4
4
 
5
+ ## 0.8.0
6
+
7
+ - **Breaking:** the contact form sends one email, to both the visitor and the company (`to`), so they share one conversation: replies go to the company (`Reply-To`), so replying the visitor reaches it, and replying to all the company reaches the visitor, never the sending address. The automatic reply and its `acknowledgement` option are gone.
8
+ - Its subject is "Contact · Name (Organization) · <conversation identifier>", a UUID version 7 (`identifier`), in the language the visitor used the form in ("Contacto · …").
9
+ - It thanks the visitor by name, says the company will answer within a working day and that replying adds to the conversation, lists every detail (name, organization, email, phone, the site's fields, the needs one per line, the message keeping its lines, the conversation identifier), and signs off "Best regards, <Company>." The form page, language, time and IP are no longer shown (the visitor sees the email too).
10
+ - Built-in English and Portuguese words (`CONTACT_LABELS`), `labels` by language, choices and fields named in each language. **Breaking:** `ContactLabels` has new words; `site`, `languageNames`, `now`, `formPage` and `LANGUAGE_NAMES` are gone.
11
+ - It comes from the company by name (or `senderName`), no longer "<company> Web Application".
12
+ - The email uses email-web-library's one layout, the same in every mail app; `darkLogo` is the white logo for dark themes.
13
+
5
14
  ## 0.6.1
6
15
 
7
16
  Llms.txt summary names the phone field
package/README.md CHANGED
@@ -43,34 +43,25 @@ pnpm add @sharadox/form-web-library
43
43
  ```ts
44
44
  // the site's library
45
45
  export const sendContact = createContactAction({
46
- to: "contact@example.com",
47
- company: "Example", // from "Example Web Application", subject "Example Web Application · Contact · Ana (Café)"
48
- site: "example.com",
46
+ to: "contact@example.com", // the email goes here and to the visitor; replies come here
47
+ company: "Example", // from "Example", signed "Best regards, Example."
49
48
  choices: { website: "Website", logo: "Logo", other: "Others" },
50
49
  logo: async () => ({ content: await readFile(LOGO), contentType: "image/png", filename: "logo.png" }),
51
- design: EXAMPLE_EMAIL, // the brand's EmailDesign (email-web-library): colors, type, rules, header, signature
52
- acknowledgement: {
53
- en: {
54
- subject: "Example · We received your message",
55
- eyebrow: "Message received",
56
- heading: (name) => `Thank you, ${name}.`,
57
- paragraphs: ["We'll get back to you shortly."],
58
- messageLabel: "Your message",
59
- button: { label: "Visit example.com", href: "https://example.com" }, // optional
60
- },
61
- },
50
+ darkLogo: async () => ({ content: await readFile(LOGO_DARK), contentType: "image/png", filename: "logo-dark.png" }), // white, for dark themes
51
+ design: EXAMPLE_EMAIL, // the company's EmailDesign (email-web-library): name, logo size, wordmark, signature
62
52
  });
63
53
  ```
64
54
 
65
- Every email has the same layout: the company's logo and name on its colors at the top, then the visitor's name
66
- (and company), every detail they gave, their message, and at the bottom the page the form was sent from, the
67
- language, the time and the IP address. Replying answers the visitor. With `acknowledgement`, a visitor who left an
68
- email also gets an automatic reply in their language, with their message, and replying to it reaches the company.
69
- The emails are laid out by email-web-library's `emailLayout` in the brand's `design` (its `EmailDesign`), which a site also uses for any other email it sends.
70
-
71
- ```ts
72
-
73
- ```
55
+ The form sends one email, to both the visitor and the company, so they share one conversation. It comes from the
56
+ company by name, from the sending address (`EMAIL_SENDER_ADDRESS`), with replies set to go to the company: replying,
57
+ the visitor reaches the company, and replying to all, the company reaches the visitor (the sending address never
58
+ appears). The subject is "Contact · Ana (Café) · <conversation identifier>", a UUID version 7. The email thanks the
59
+ visitor by name, says the company will answer within a working day and that replying adds to the conversation, lists
60
+ every detail they gave (name, organization, email, phone, the site's fields, their needs one per line, their message
61
+ keeping its lines) and the conversation's identifier, and signs off with the company's name, all in the language the
62
+ visitor used the form in (English and Portuguese built in, `labels` for more). A visitor who left only a phone isn't
63
+ sent anything; the company still is. The email is laid out by email-web-library's `emailLayout`, which a site also
64
+ uses for any other email it sends.
74
65
 
75
66
  ```ts
76
67
  // the application's server action
@@ -92,17 +83,17 @@ The email server comes from `EMAIL_SERVER_*` and `EMAIL_SENDER_ADDRESS`.
92
83
 
93
84
  ## API
94
85
 
95
- | Import | Export |
96
- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97
- | `…/contact-problem` | `contactProblems({ name, email, phone })`: what a form's contact details still lack |
98
- | `…/choice-request` | `requestChoices(event, choices)`, `useChoiceRequests(event, onRequest)`: a button elsewhere asks the form to tick choices |
99
- | `…/bot-field` | `<BotFields />`: the honeypot and fill-time fields `isLikelyBot` reads |
100
- | `…/contact-action` | `createContactAction(options)` → `(form, ip) => Promise<ContactState>`; `ENGLISH_LABELS`, `PLAIN_THEME`, `LANGUAGE_NAMES`, `formPage(value, site)`; `ContactState`, `ContactActionOptions`, `ContactLabels`, `ContactAcknowledgement` and `EmailLogo` in `…/contact-action/type` |
101
- | `…/parse-contact` | `parseContact(form, { choices?, choiceField?, reach?, requireMessage?, minimumMessageLength?, requireChoice?, fields?, now? })` → `bot`, `invalid` or `valid` |
102
- | `…/contact-check` | `isEmail(text)`, `isPhone(text)`: the rules the action uses, safe in the browser for checks before sending |
103
- | `…/bot-check` | `isLikelyBot(form, { honeypotField?, startedAtField?, minimumFillTime?, now? })` |
104
- | `…/rate-limit` | `createRateLimiter({ window, maximum })` → `(key, now?) => boolean` (kept in memory, per server instance) |
105
- | `…/field` | `readField(form, name, maximumLength)` |
86
+ | Import | Export |
87
+ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
88
+ | `…/contact-problem` | `contactProblems({ name, email, phone })`: what a form's contact details still lack |
89
+ | `…/choice-request` | `requestChoices(event, choices)`, `useChoiceRequests(event, onRequest)`: a button elsewhere asks the form to tick choices |
90
+ | `…/bot-field` | `<BotFields />`: the honeypot and fill-time fields `isLikelyBot` reads |
91
+ | `…/contact-action` | `createContactAction(options)` → `(form, ip) => Promise<ContactState>`; `ENGLISH_LABELS`, `PORTUGUESE_LABELS`, `CONTACT_LABELS`, `plainDesign(company)`, `textIn(text, locale)`; `ContactState`, `ContactActionOptions`, `ContactLabels`, `ContactText` and `EmailLogo` in `…/contact-action/type` |
92
+ | `…/parse-contact` | `parseContact(form, { choices?, choiceField?, reach?, requireMessage?, minimumMessageLength?, requireChoice?, fields?, now? })` → `bot`, `invalid` or `valid` |
93
+ | `…/contact-check` | `isEmail(text)`, `isPhone(text)`: the rules the action uses, safe in the browser for checks before sending |
94
+ | `…/bot-check` | `isLikelyBot(form, { honeypotField?, startedAtField?, minimumFillTime?, now? })` |
95
+ | `…/rate-limit` | `createRateLimiter({ window, maximum })` → `(key, now?) => boolean` (kept in memory, per server instance) |
96
+ | `…/field` | `readField(form, name, maximumLength)` |
106
97
 
107
98
  ## Develop
108
99
 
@@ -1,30 +1,31 @@
1
1
  import type { EmailDesign } from "@sharadox/email-web-library";
2
- import type { ContactActionOptions, ContactLabels, ContactState } from "@sharadox/form-web-library/contact-action/type";
3
- /** The email's words when the site gives none. */
2
+ import type { ContactActionOptions, ContactLabels, ContactState, ContactText } from "@sharadox/form-web-library/contact-action/type";
3
+ /** The email's words in English. */
4
4
  export declare const ENGLISH_LABELS: ContactLabels;
5
- /** Black on white, plainly, when the site gives no design of its own. */
5
+ /** The email's words in Portuguese. */
6
+ export declare const PORTUGUESE_LABELS: ContactLabels;
7
+ /** The built-in words, by language. */
8
+ export declare const CONTACT_LABELS: Readonly<Record<string, ContactLabels>>;
9
+ /** Words in the given language: the text itself, its translation, the English one, or the first there is. */
10
+ export declare function textIn(text: ContactText, locale: string): string;
11
+ /** The logo (when the site gives one) and the company's name beside it, when the site gives no design of its own. */
6
12
  export declare const plainDesign: (company: string) => EmailDesign;
7
- /** Common languages' names, when the site gives none. */
8
- export declare const LANGUAGE_NAMES: Readonly<Record<string, string>>;
9
- /**
10
- * The page the form was sent from, when it is a web address on the site's domain (or a subdomain of it); anything
11
- * else is left out, so a forged field can't put a link of someone else's in the inbox.
12
- */
13
- export declare function formPage(value: ReturnType<FormData["get"]>, site: string): string | undefined;
14
13
  /**
15
14
  * Builds the work of a contact form's server action: checks for bots (they get a fake success), validates, limits
16
- * each address and everyone together per day (`dailyMaximum`, so a flood can't run up the email bill), then emails
17
- * the company in its own design (`design`): its logo at the top, every detail the visitor gave, their message, a
18
- * button to answer them, and the page, language, time and IP at the bottom. It comes from "<company> Web Application" with the subject
19
- * "<company> Web Application · Contact · Name (Company)", and replying answers the visitor. When the visitor left an
20
- * email and the site gives an `acknowledgement`, they get an automatic reply in their language with their message,
21
- * which the company can be reached by replying to. Sites can accept a phone instead of an email (`reach`), make the
22
- * message optional, add fields and write the email in their own language (`labels`).
15
+ * each address and everyone together per day (`dailyMaximum`, so a flood can't run up the email bill), then sends one
16
+ * email to both the visitor and the company (`to`), so they share one conversation: replying, the visitor reaches the
17
+ * company; replying to all, the company reaches the visitor (the sending address is never in the way: replies go to
18
+ * `to`). It thanks the visitor by name, says what happens next, lists every detail they gave (their needs one per
19
+ * line, their message keeping its lines) and the conversation's identifier (a UUID version 7), and signs off with the
20
+ * company's name, all in the language the visitor used the form in. It comes from the company by name, with the
21
+ * subject "Contact · Name (Organization) · <identifier>" ("Contacto · …" in Portuguese). A visitor who left only a
22
+ * phone isn't sent anything; the company still is. Sites can accept a phone instead of an email (`reach`), make the
23
+ * message optional, add fields and give the email's words in more languages (`labels`).
23
24
  *
24
25
  * @example
25
- * const sendContact = createContactAction({ to: "contact@sharadox.com", company: "Sharadox", site: "sharadox.com" });
26
+ * const sendContact = createContactAction({ to: "contact@sharadox.com", company: "Sharadox" });
26
27
  * // in a "use server" file:
27
28
  * export async function sendContactAction(_: ContactState, form: FormData) { return sendContact(form, ip); }
28
29
  */
29
- export declare function createContactAction({ to, company, senderAddress, logo, design: givenDesign, languageNames, acknowledgement, choices, site, reach, requireMessage, minimumMessageLength, requireChoice, fields, labels: givenLabels, rateLimit, dailyMaximum, readConfiguration, createSender, reportError, now, }: ContactActionOptions): (form: FormData, ip: string) => Promise<ContactState>;
30
+ export declare function createContactAction({ to, company, senderName, senderAddress, logo, darkLogo, design: givenDesign, choices, reach, requireMessage, minimumMessageLength, requireChoice, fields, labels: givenLabels, rateLimit, dailyMaximum, readConfiguration, createSender, reportError, identifier, }: ContactActionOptions): (form: FormData, ip: string) => Promise<ContactState>;
30
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-action/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,6BAA6B,CAAC;AAKtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAIxH,kDAAkD;AAClD,eAAO,MAAM,cAAc,EAAE,aAa5B,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,KAAG,WA2B5C,CAAC;AAEH,yDAAyD;AACzD,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS7F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,EAAE,EACF,OAAO,EACP,aAAa,EACb,IAAI,EACJ,MAAM,EAAE,WAAW,EACnB,aAA8B,EAC9B,eAAe,EACf,OAAY,EACZ,IAAI,EACJ,KAAe,EACf,cAAqB,EACrB,oBAAwB,EACxB,aAAqB,EACrB,MAAW,EACX,MAAM,EAAE,WAAgB,EACxB,SAAkD,EAClD,YAAiB,EACjB,iBAAgD,EAChD,YAAgC,EAChC,WAA+D,EAC/D,GAAsB,GACvB,EAAE,oBAAoB,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CA2I9E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-action/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,6BAA6B,CAAC;AAKtF,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,WAAW,EACZ,MAAM,gDAAgD,CAAC;AAIxD,oCAAoC;AACpC,eAAO,MAAM,cAAc,EAAE,aAe5B,CAAC;AAEF,uCAAuC;AACvC,eAAO,MAAM,iBAAiB,EAAE,aAe/B,CAAC;AAEF,uCAAuC;AACvC,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAiD,CAAC;AAErH,6GAA6G;AAC7G,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED,qHAAqH;AACrH,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,KAAG,WAI5C,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,EAAE,EACF,OAAO,EACP,UAAoB,EACpB,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,MAAM,EAAE,WAAW,EACnB,OAAY,EACZ,KAAe,EACf,cAAqB,EACrB,oBAAwB,EACxB,aAAqB,EACrB,MAAW,EACX,MAAM,EAAE,WAAgB,EACxB,SAAkD,EAClD,YAAiB,EACjB,iBAAgD,EAChD,YAAgC,EAChC,WAA+D,EAC/D,UAAiC,GAClC,EAAE,oBAAoB,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CA8F9E"}
@@ -1,98 +1,77 @@
1
1
  import { createEmailSender, EmailError, emailLayout, readEmailServerConfiguration } from "@sharadox/email-web-library";
2
- import { separate } from "@sharadox/web-library/text/separate";
3
- import { SEPARATOR } from "@sharadox/web-library/text/separator";
2
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
3
+ import { separated } from "@sharadox/web-library/text/separated";
4
4
  import { createRateLimiter } from "@sharadox/form-web-library/rate-limit";
5
5
  import { parseContact } from "@sharadox/form-web-library/parse-contact";
6
6
  const oneLine = (text) => text.replace(/[\r\n]+/g, " ");
7
- /** The email's words when the site gives none. */
7
+ /** The email's words in English. */
8
8
  export const ENGLISH_LABELS = {
9
+ contact: "Contact",
10
+ thanks: "Thank you",
11
+ paragraphs: [
12
+ "Your message has reached us and we will get back to you as soon as possible, usually within a working day.",
13
+ "Feel free to reply to this email, in case you would like to add anything else to the conversation.",
14
+ ],
9
15
  name: "Name",
16
+ organization: "Organization",
10
17
  email: "Email",
11
18
  phone: "Phone",
12
- company: "Company",
13
19
  needs: "Needs",
14
- language: "Language",
15
- contact: "Contact",
16
20
  message: "Message",
17
- page: "Form",
18
- sent: "Sent",
19
- reply: "Reply to",
20
- call: "Call",
21
+ conversation: "Conversation identifier",
22
+ closing: "Best regards,",
23
+ };
24
+ /** The email's words in Portuguese. */
25
+ export const PORTUGUESE_LABELS = {
26
+ contact: "Contacto",
27
+ thanks: "Obrigado",
28
+ paragraphs: [
29
+ "A sua mensagem chegou até nós e responderemos o mais brevemente possível, normalmente dentro de um dia útil.",
30
+ "Caso queira acrescentar algo à conversa, basta responder a este email.",
31
+ ],
32
+ name: "Nome",
33
+ organization: "Organização",
34
+ email: "Email",
35
+ phone: "Telefone",
36
+ needs: "Necessidades",
37
+ message: "Mensagem",
38
+ conversation: "Identificador da conversa",
39
+ closing: "Cumprimentos,",
21
40
  };
22
- /** Black on white, plainly, when the site gives no design of its own. */
41
+ /** The built-in words, by language. */
42
+ export const CONTACT_LABELS = { en: ENGLISH_LABELS, pt: PORTUGUESE_LABELS };
43
+ /** Words in the given language: the text itself, its translation, the English one, or the first there is. */
44
+ export function textIn(text, locale) {
45
+ if (typeof text === "string")
46
+ return text;
47
+ return text[locale] ?? text.en ?? Object.values(text)[0];
48
+ }
49
+ /** The logo (when the site gives one) and the company's name beside it, when the site gives no design of its own. */
23
50
  export const plainDesign = (company) => ({
24
51
  name: company,
25
52
  logo: { width: 44, height: 44 },
26
53
  wordmark: true,
27
- align: "left",
28
- colors: {
29
- page: "#f4f4f5",
30
- card: "#ffffff",
31
- edge: "#e4e4e7",
32
- text: "#09090b",
33
- muted: "#3f3f46",
34
- quiet: "#71717a",
35
- rule: "#ececec",
36
- accent: "#09090b",
37
- box: "#f6f6f7",
38
- onAccent: "#ffffff",
39
- },
40
- fonts: {
41
- heading: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
42
- body: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
43
- label: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
44
- },
45
- heading: { size: 24, weight: 600, letterSpacing: "-0.02em", lineHeight: 1.3 },
46
- label: { size: 11, letterSpacing: "0.12em" },
47
- rule: "solid",
48
- radius: 16,
49
- button: { radius: 999, uppercase: false, letterSpacing: "0" },
50
54
  });
51
- /** Common languages' names, when the site gives none. */
52
- export const LANGUAGE_NAMES = {
53
- en: "English",
54
- pt: "Português",
55
- es: "Español",
56
- fr: "Français",
57
- de: "Deutsch",
58
- it: "Italiano",
59
- };
60
- /**
61
- * The page the form was sent from, when it is a web address on the site's domain (or a subdomain of it); anything
62
- * else is left out, so a forged field can't put a link of someone else's in the inbox.
63
- */
64
- export function formPage(value, site) {
65
- if (typeof value !== "string" || value.length > 500)
66
- return undefined;
67
- try {
68
- const url = new URL(value);
69
- const host = url.hostname;
70
- return url.protocol === "https:" && (host === site || host.endsWith(`.${site}`)) ? url.href : undefined;
71
- }
72
- catch {
73
- return undefined;
74
- }
75
- }
76
55
  /**
77
56
  * Builds the work of a contact form's server action: checks for bots (they get a fake success), validates, limits
78
- * each address and everyone together per day (`dailyMaximum`, so a flood can't run up the email bill), then emails
79
- * the company in its own design (`design`): its logo at the top, every detail the visitor gave, their message, a
80
- * button to answer them, and the page, language, time and IP at the bottom. It comes from "<company> Web Application" with the subject
81
- * "<company> Web Application · Contact · Name (Company)", and replying answers the visitor. When the visitor left an
82
- * email and the site gives an `acknowledgement`, they get an automatic reply in their language with their message,
83
- * which the company can be reached by replying to. Sites can accept a phone instead of an email (`reach`), make the
84
- * message optional, add fields and write the email in their own language (`labels`).
57
+ * each address and everyone together per day (`dailyMaximum`, so a flood can't run up the email bill), then sends one
58
+ * email to both the visitor and the company (`to`), so they share one conversation: replying, the visitor reaches the
59
+ * company; replying to all, the company reaches the visitor (the sending address is never in the way: replies go to
60
+ * `to`). It thanks the visitor by name, says what happens next, lists every detail they gave (their needs one per
61
+ * line, their message keeping its lines) and the conversation's identifier (a UUID version 7), and signs off with the
62
+ * company's name, all in the language the visitor used the form in. It comes from the company by name, with the
63
+ * subject "Contact · Name (Organization) · <identifier>" ("Contacto · …" in Portuguese). A visitor who left only a
64
+ * phone isn't sent anything; the company still is. Sites can accept a phone instead of an email (`reach`), make the
65
+ * message optional, add fields and give the email's words in more languages (`labels`).
85
66
  *
86
67
  * @example
87
- * const sendContact = createContactAction({ to: "contact@sharadox.com", company: "Sharadox", site: "sharadox.com" });
68
+ * const sendContact = createContactAction({ to: "contact@sharadox.com", company: "Sharadox" });
88
69
  * // in a "use server" file:
89
70
  * export async function sendContactAction(_: ContactState, form: FormData) { return sendContact(form, ip); }
90
71
  */
91
- export function createContactAction({ to, company, senderAddress, logo, design: givenDesign, languageNames = LANGUAGE_NAMES, acknowledgement, choices = {}, site, reach = "email", requireMessage = true, minimumMessageLength = 1, requireChoice = false, fields = {}, labels: givenLabels = {}, rateLimit = { window: 60 * 60 * 1000, maximum: 5 }, dailyMaximum = 50, readConfiguration = readEmailServerConfiguration, createSender = createEmailSender, reportError = (message, error) => console.error(message, error), now = () => new Date(), }) {
72
+ export function createContactAction({ to, company, senderName = company, senderAddress, logo, darkLogo, design: givenDesign, choices = {}, reach = "email", requireMessage = true, minimumMessageLength = 1, requireChoice = false, fields = {}, labels: givenLabels = {}, rateLimit = { window: 60 * 60 * 1000, maximum: 5 }, dailyMaximum = 50, readConfiguration = readEmailServerConfiguration, createSender = createEmailSender, reportError = (message, error) => console.error(message, error), identifier = () => uuidVersion7(), }) {
92
73
  const allow = createRateLimiter(rateLimit);
93
74
  const allowToday = createRateLimiter({ window: 24 * 60 * 60 * 1000, maximum: dailyMaximum });
94
- const labels = { ...ENGLISH_LABELS, ...givenLabels };
95
- const senderName = `${company} Web Application`;
96
75
  const design = givenDesign ?? plainDesign(company);
97
76
  return async (form, ip) => {
98
77
  const parsed = parseContact(form, {
@@ -111,111 +90,69 @@ export function createContactAction({ to, company, senderAddress, logo, design:
111
90
  if (!allow(ip) || !allowToday("everyone"))
112
91
  return { status: "rate-limited" };
113
92
  const message = parsed.value;
114
- const page = formPage(form.get("page"), site);
115
- const language = languageNames[message.locale] ?? message.locale;
116
- const sent = `${now().toISOString().slice(0, 16).replace("T", " ")} UTC`;
117
- const named = message.choices.map((choice) => choices[choice]);
93
+ // The email is in the language the visitor used the form in.
94
+ const locale = message.locale;
95
+ const labels = { ...(CONTACT_LABELS[locale] ?? ENGLISH_LABELS), ...givenLabels[locale] };
96
+ const conversation = identifier();
97
+ const needs = message.choices.map((choice) => textIn(choices[choice], locale));
118
98
  const who = message.company ? `${message.name} (${message.company})` : message.name;
119
- const firstName = message.name.split(/\s+/)[0];
120
- // The one thing to do: answer by email, or call when only a phone was left.
121
- const answer = message.email
122
- ? { label: `${labels.reply} ${firstName}`, href: `mailto:${message.email}` }
123
- : { label: `${labels.call} ${firstName}`, href: `tel:${message.phone.replace(/[^\d+]/g, "")}` };
99
+ const heading = `${labels.thanks}, ${message.name}.`;
124
100
  const rows = [
125
101
  { label: labels.name, value: message.name },
102
+ ...(message.company ? [{ label: labels.organization, value: message.company }] : []),
126
103
  ...(message.email ? [{ label: labels.email, value: message.email, href: `mailto:${message.email}` }] : []),
127
104
  ...(message.phone
128
105
  ? [{ label: labels.phone, value: message.phone, href: `tel:${message.phone.replace(/[^\d+]/g, "")}` }]
129
106
  : []),
130
- ...(message.company ? [{ label: labels.company, value: message.company }] : []),
131
107
  ...Object.entries(fields)
132
108
  .filter(([field]) => message.fields[field])
133
- .map(([field, label]) => ({ label, value: message.fields[field] })),
134
- ...(named.length ? [{ label: labels.needs, value: named.join(", ") }] : []),
135
- ];
136
- const footer = [
137
- ...(page ? [{ label: labels.page, value: page, href: page }] : [{ label: labels.page, value: site }]),
138
- { label: labels.language, value: language },
139
- { label: labels.sent, value: sent },
140
- { label: "IP", value: ip },
109
+ .map(([field, label]) => ({ label: textIn(label, locale), value: message.fields[field] })),
110
+ ...(needs.length ? [{ label: labels.needs, value: needs }] : []),
111
+ ...(message.message ? [{ label: labels.message, value: message.message, keepLines: true }] : []),
112
+ { label: labels.conversation, value: conversation },
141
113
  ];
142
114
  const text = [
143
- ...rows.map((row) => `${row.label}: ${row.value}`),
144
- ...(message.message ? ["", `${labels.message}:`, message.message] : []),
115
+ heading,
116
+ "",
117
+ ...labels.paragraphs,
118
+ "",
119
+ ...rows.map((row) => typeof row.value === "string"
120
+ ? `${row.label}:${row.keepLines ? "\n" : " "}${row.value}`
121
+ : [`${row.label}:`, ...row.value.map((item) => `- ${item}`)].join("\n")),
145
122
  "",
146
- ...footer.map((row) => `${row.label}: ${row.value}`),
123
+ labels.closing,
124
+ `${company}.`,
147
125
  ].join("\n");
148
126
  try {
149
127
  const image = logo ? await logo() : undefined;
150
- const inlineImages = image ? [{ id: "logo", ...image }] : [];
128
+ const darkImage = image && darkLogo ? await darkLogo() : undefined;
129
+ const inlineImages = [
130
+ ...(image ? [{ id: "logo", ...image }] : []),
131
+ ...(darkImage ? [{ id: "logo-dark", ...darkImage }] : []),
132
+ ];
151
133
  const configuration = readConfiguration();
152
- const sender = createSender(configuration);
153
- const from = {
154
- name: senderName,
155
- address: senderAddress || process.env.EMAIL_SENDER_ADDRESS || configuration.username,
156
- };
157
- await sender.send({
158
- from,
159
- to,
160
- // Replying to the email answers the visitor at the address they typed.
161
- ...(message.email ? { replyTo: { name: oneLine(message.name), address: message.email } } : {}),
162
- subject: oneLine(separate(SEPARATOR, senderName, labels.contact, who)).slice(0, 300),
134
+ await createSender(configuration).send({
135
+ from: {
136
+ name: senderName,
137
+ address: senderAddress || process.env.EMAIL_SENDER_ADDRESS || configuration.username,
138
+ },
139
+ // One email to both: the visitor (when they left an email) and the company, in one conversation.
140
+ to: [...(message.email ? [{ name: oneLine(message.name), address: message.email }] : []), to],
141
+ // Replies go to the company, never to the sending address; replying to all, the company reaches the visitor.
142
+ replyTo: to,
143
+ subject: oneLine(separated(labels.contact, who, conversation)).slice(0, 300),
163
144
  text,
164
145
  html: emailLayout({
165
- language: "en",
166
- preview: separate(SEPARATOR, who, named.join(", ")),
146
+ language: locale,
147
+ preview: labels.paragraphs[0] ?? heading,
167
148
  eyebrow: labels.contact,
168
- heading: who,
149
+ heading,
150
+ paragraphs: labels.paragraphs,
169
151
  rows,
170
- ...(message.message ? { quote: { label: labels.message, text: message.message } } : {}),
171
- button: answer,
172
- footer,
173
- }, design, Boolean(image)),
152
+ closing: labels.closing,
153
+ }, design, { light: Boolean(image), dark: Boolean(darkImage) }),
174
154
  inlineImages,
175
155
  });
176
- // The automatic reply: never stops the message itself from counting as sent.
177
- const reply = acknowledgement?.[message.locale] ?? Object.values(acknowledgement ?? {})[0];
178
- if (reply && message.email) {
179
- try {
180
- await sender.send({
181
- from,
182
- to: { name: oneLine(message.name), address: message.email },
183
- replyTo: to,
184
- subject: oneLine(reply.subject).slice(0, 300),
185
- text: [
186
- reply.heading(message.name),
187
- "",
188
- ...reply.paragraphs,
189
- ...(message.message ? ["", `${reply.messageLabel}:`, message.message] : []),
190
- ].join("\n"),
191
- html: emailLayout({
192
- language: message.locale,
193
- preview: reply.paragraphs[0] ?? reply.subject,
194
- eyebrow: reply.eyebrow,
195
- heading: reply.heading(message.name),
196
- paragraphs: reply.paragraphs,
197
- ...(message.message ? { quote: { label: reply.messageLabel, text: message.message } } : {}),
198
- ...(reply.button ? { button: reply.button } : {}),
199
- // The company's own signature says where it is; without one, a line to its site does.
200
- ...(design.signature?.length
201
- ? {}
202
- : {
203
- footer: [
204
- {
205
- label: company,
206
- value: page ? new URL(page).origin.replace("https://", "") : site,
207
- href: page ? new URL(page).origin : `https://${site}`,
208
- },
209
- ],
210
- }),
211
- }, design, Boolean(image)),
212
- inlineImages,
213
- });
214
- }
215
- catch (error) {
216
- reportError("contact: the automatic reply failed", error);
217
- }
218
- }
219
156
  return { status: "sent" };
220
157
  }
221
158
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-action/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAEvH,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAGxE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAEhE,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,UAAU;IACjB,IAAI,EAA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7B,IAAI;oBACJ,OAAO,EAAE,MAAM,CAAC,OAAO;iBACxB,EACD,MAAM,EACN,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,CACpD;gBACD,YAAY;aACb,CAAC,CAAC;YACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;gBAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YAClG,WAAW,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -4,44 +4,26 @@ import type { ContactReach } from "@sharadox/form-web-library/parse-contact/type
4
4
  export interface ContactState {
5
5
  status: "idle" | "sent" | "invalid" | "rate-limited" | "failed";
6
6
  }
7
- /** The words the email uses around the visitor's answers, so the inbox can read it in its own language. */
7
+ /** Words the email shows in one language, or in each language by code (`{ en: "Home", pt: "Casa" }`). */
8
+ export type ContactText = string | Readonly<Record<string, string>>;
9
+ /** The email's words around the visitor's answers, in one language. */
8
10
  export interface ContactLabels {
11
+ /** The form's name: first in the subject ("Contact · Ana · …") and in small capitals above the heading. */
12
+ contact: string;
13
+ /** Before the visitor's name in the heading: "Thank you" ("Thank you, Ana."). */
14
+ thanks: string;
15
+ /** Under the heading: what happens next, and that replying adds to the conversation. */
16
+ paragraphs: readonly string[];
9
17
  name: string;
18
+ organization: string;
10
19
  email: string;
11
20
  phone: string;
12
- company: string;
13
21
  needs: string;
14
- language: string;
15
- /** The small capitals above the visitor's name: "Contact". */
16
- contact: string;
17
- /** Above the visitor's message: "Message". */
18
22
  message: string;
19
- /** The page the form was sent from: "Form". */
20
- page: string;
21
- /** When it was sent: "Sent". */
22
- sent: string;
23
- /** The button that answers the visitor, before their first name: "Reply to". */
24
- reply: string;
25
- /** The button that calls a visitor who left only a phone, before their first name: "Call". */
26
- call: string;
27
- }
28
- /** The automatic reply to the visitor, in one language: thanks, what happens next, and their message back. */
29
- export interface ContactAcknowledgement {
30
- /** For example "Sharadox · We received your message". */
31
- subject: string;
32
- /** The heading, from the visitor's name, for example `Thank you, ${name}.`. */
33
- heading: (name: string) => string;
34
- /** What happens next. */
35
- paragraphs: readonly string[];
36
- /** Above their message: "Your message". */
37
- messageLabel: string;
38
- /** The small capitals above the heading, for example "Message received". */
39
- eyebrow: string;
40
- /** A button under their message, for example to the site. */
41
- button?: {
42
- label: string;
43
- href: string;
44
- };
23
+ /** Above the conversation's identifier: "Conversation identifier". */
24
+ conversation: string;
25
+ /** Before the company's name at the end: "Best regards,". */
26
+ closing: string;
45
27
  }
46
28
  /** The company's logo at the top of every email: a square image (PNG), sent inside the email. */
47
29
  export interface EmailLogo {
@@ -50,36 +32,32 @@ export interface EmailLogo {
50
32
  filename: string;
51
33
  }
52
34
  export interface ContactActionOptions {
53
- /** Where messages go, for example "contact@sharadox.com". */
35
+ /**
36
+ * The company's address, for example "contact@sharadox.com": the email goes to it and to the visitor, and replies
37
+ * come to it.
38
+ */
54
39
  to: string;
55
40
  /**
56
- * The company, for example "Sharadox". Its emails come from "<company> Web Application", with the subject
57
- * "<company> Web Application · Contact · Name (Company)", and carry its name beside the logo.
41
+ * The company, for example "Sharadox". Its emails come from it by name (unless `senderName` says otherwise), and
42
+ * sign off with its name. The subject is the form's name, the visitor's and the conversation's identifier:
43
+ * "Contact · Name (Organization) · 019a…".
58
44
  */
59
45
  company: string;
46
+ /** The name emails come from; the company's by default. */
47
+ senderName?: string;
60
48
  /** The sender address (an address the email server may send from); `EMAIL_SENDER_ADDRESS` or the server user. */
61
49
  senderAddress?: string;
62
- /** The company's logo, at the top of every email. */
50
+ /** The company's logo at the top of every email, in black, with a thin white outline for darkened mail apps. */
63
51
  logo?: () => Promise<EmailLogo>;
52
+ /** The same logo in white, shown instead where the mail app is in a dark theme (with `logo` only). */
53
+ darkLogo?: () => Promise<EmailLogo>;
64
54
  /**
65
- * The brand's design for its emails (email-web-library's `EmailDesign`: colors, type, rules, header, button,
66
- * signature), so they look like its website; plain black on white by default.
55
+ * What makes the emails the company's (email-web-library's `EmailDesign`: its name, its logo's size, whether the
56
+ * name sits beside the logo, its signature), in the one layout every mail app shows alike.
67
57
  */
68
58
  design?: EmailDesign;
69
- /** Each language's name in the email, by code; English names of common languages by default. */
70
- languageNames?: Readonly<Record<string, string>>;
71
- /**
72
- * The automatic reply to visitors who left an email, by language (the form's locale; the first one otherwise). It
73
- * comes from the same sender, and replying to it reaches `to`. None by default.
74
- */
75
- acknowledgement?: Readonly<Record<string, ContactAcknowledgement>>;
76
- /** Choices the form may send, and how each is named in the email; none by default. */
77
- choices?: Readonly<Record<string, string>>;
78
- /**
79
- * The site's domain, for example "sharadox.com". The page the form was sent from (the "page" field) is shown only
80
- * when it is on this domain or one of its subdomains.
81
- */
82
- site: string;
59
+ /** Choices the form may send, and how each is named in the email (in each language, or one); none by default. */
60
+ choices?: Readonly<Record<string, ContactText>>;
83
61
  /** "email" (the default) requires an email; "email-or-phone" accepts either way of answering. */
84
62
  reach?: ContactReach;
85
63
  /** False lets the message be empty; true by default. */
@@ -88,10 +66,16 @@ export interface ContactActionOptions {
88
66
  minimumMessageLength?: number;
89
67
  /** True requires at least one choice; false by default. */
90
68
  requireChoice?: boolean;
91
- /** Extra single-line fields the form sends, and how each is named in the email, for example `{ place: "Home" }`. */
92
- fields?: Readonly<Record<string, string>>;
93
- /** The email's words, in English by default. */
94
- labels?: Partial<ContactLabels>;
69
+ /**
70
+ * Extra single-line fields the form sends, and how each is named in the email (in each language, or one), for
71
+ * example `{ place: { en: "Place", pt: "Local" } }`.
72
+ */
73
+ fields?: Readonly<Record<string, ContactText>>;
74
+ /**
75
+ * The email's words in each language, by code, over the built-in English and Portuguese ones. The email is in the
76
+ * language the visitor used the form in (English when it has no words for it).
77
+ */
78
+ labels?: Readonly<Record<string, Partial<ContactLabels>>>;
95
79
  /** Messages per address per window; 5 per hour by default. */
96
80
  rateLimit?: {
97
81
  window: number;
@@ -107,7 +91,7 @@ export interface ContactActionOptions {
107
91
  createSender?: (configuration: EmailServerConfiguration) => EmailSender;
108
92
  /** Where failures are reported; `console.error` by default. */
109
93
  reportError?: (message: string, error: unknown) => void;
110
- /** Now, for the time the email shows (tests). */
111
- now?: () => Date;
94
+ /** A new conversation identifier, a UUID version 7 by default (tests give their own). */
95
+ identifier?: () => string;
112
96
  }
113
97
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-action/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACtG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAC;AAElF,8CAA8C;AAC9C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,QAAQ,CAAC;CACjE;AAED,2GAA2G;AAC3G,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,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D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,2DAA2D;IAC3D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC/C;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1D,8DAA8D;IAC9D,SAAS,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,iBAAiB,CAAC,EAAE,MAAM,wBAAwB,CAAC;IACnD,YAAY,CAAC,EAAE,CAAC,aAAa,EAAE,wBAAwB,KAAK,WAAW,CAAC;IACxE,+DAA+D;IAC/D,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;CAC3B"}
package/llms.txt CHANGED
@@ -5,7 +5,7 @@
5
5
  - /contact-problem: contactProblems({ name, email, phone }) → ("name" | "reach" | "email" | "phone")[]: a name and a valid way to reply, same rules on page and server
6
6
  - /choice-request: requestChoices(event, choices) and useChoiceRequests(event, onRequest): a button elsewhere on the page asks the form to tick choices
7
7
  - /bot-field: <BotFields honeypotField? startedAtField? honeypotLabel? />: the hidden honeypot and fill-time fields isLikelyBot reads
8
- - /contact-action: createContactAction({ to, company (sender "<company> Web Application", subject "<company> Web Application · <labels.contact> · Name (Company)"), senderAddress?, site (domain; the form's `page` field is shown only on it or a subdomain), logo?: () => Promise<{ content, contentType, filename }> (inline cid:logo at the top), design? { background, foreground, accent }, languageNames?, acknowledgement?: { [locale]: { subject, eyebrow, heading(name), paragraphs, messageLabel } } (automatic reply to the visitor's email, in their language, reply-to = to; a failed reply never fails the send), choices?: { key: label }, reach? = 'email' | 'email-or-phone', requireMessage? = true, minimumMessageLength? = 1, requireChoice? = false, fields?: { name: label }, labels?: Partial<ContactLabels> (English default, ENGLISH_LABELS), rateLimit? = 5/hour per address, dailyMaximum? = 50 emails/day from everyone (per server instance; caps email cost under a flood), readConfiguration?, createSender?, reportError? }) → (form, ip) => { status: idle|sent|invalid|rate-limited|failed }. Reply-to = visitor when they gave an email; bots get fake 'sent'. The email: branded layout (logo + company on the design, accent line), every detail, the message, then Form (page), Language (name), Sent (UTC), IP.
8
+ - /contact-action: createContactAction({ to (company address: the email goes to it and the visitor; Reply-To), company (sender name unless senderName?; sign-off "Best regards, Company."), senderAddress? (EMAIL_SENDER_ADDRESS), logo?/darkLogo?: () => Promise<{ content, contentType, filename }> (cid:logo black with white outline, cid:logo-dark white), design? EmailDesign (default plainDesign(company)), choices?: { key: label | { [locale]: label } }, reach? = email | email-or-phone, requireMessage? = true, minimumMessageLength? = 1, requireChoice? = false, fields?: { name: label | { [locale]: label } }, labels?: { [locale]: Partial<ContactLabels> } (over CONTACT_LABELS en/pt), rateLimit? = 5/hour per address, dailyMaximum? = 50/day, identifier? = uuidVersion7, readConfiguration?, createSender?, reportError? }) → (form, ip) => { status }. ONE email to [visitor (if email), to], Reply-To: to (visitor replies reach the company; company replies-all reach the visitor; one thread). Subject "<contact> · Name (Organization) · <UUIDv7>" in the visitor's form language. Body: logo, CONTACT eyebrow, "Thank you, Name.", 2 paragraphs, rows Name / Organization / Email / Phone / site fields / Needs (dotted list) / Message (line breaks kept) / Conversation identifier, "Best regards," + bold company. Phone-only visitor: only the company gets it. Bots get a fake "sent".
9
9
  - Form fields: name, email, phone (valid: + digits spaces ().- with ≥7 digits), company, message, extra fields, locale, started-at, page (location.href at sending), website (honeypot), need (checkboxes).
10
10
  - /parse-contact: parseContact(form, { choices, choiceField='need', reach, requireMessage, minimumMessageLength, requireChoice, fields, now }) → value { name, email, phone, company, message, locale, choices, fields }
11
11
  - /contact-check isEmail(text), isPhone(text) (browser-safe, same rules as the server); /bot-check isLikelyBot; /rate-limit createRateLimiter({ window, maximum }); /field readField(form, name, max)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/form-web-library",
3
- "version": "0.7.1-development.26",
3
+ "version": "0.8.0-development.38",
4
4
  "description": "Forms: a phone field with every country's flag and calling code, and on the server field reading, honeypot and fill-time bot checks, rate limiting and a contact form action that emails messages with the visitor as reply-to.",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENCA.md",
@@ -50,12 +50,12 @@
50
50
  },
51
51
  "homepage": "https://github.com/Sharadox/form-web-library#readme",
52
52
  "devDependencies": {
53
- "@sharadox/es-lint-configuration-web-library": "^0.1.1",
54
- "@sharadox/library-build-web-library": "^0.1.2",
55
- "@sharadox/prettier-configuration-web-library": "^0.1.0",
56
- "@sharadox/turborepo-configuration-web-library": "^0.1.0",
57
- "@sharadox/type-script-configuration-web-library": "^0.2.0",
58
- "@sharadox/vitest-configuration-web-library": "^0.1.2",
53
+ "@sharadox/es-lint-configuration-web-library": "^0.1.2",
54
+ "@sharadox/library-build-web-library": "^0.2.0",
55
+ "@sharadox/prettier-configuration-web-library": "^0.1.1",
56
+ "@sharadox/turborepo-configuration-web-library": "0.1.3",
57
+ "@sharadox/type-script-configuration-web-library": "^0.2.2",
58
+ "@sharadox/vitest-configuration-web-library": "^0.2.0",
59
59
  "@testing-library/dom": "^10.4.2",
60
60
  "@testing-library/react": "^16.3.3",
61
61
  "@types/node": "^24.19.2",
@@ -75,9 +75,9 @@
75
75
  "vitest": "^5.1.0"
76
76
  },
77
77
  "dependencies": {
78
- "@sharadox/email-web-library": "^0.4.0",
79
- "@sharadox/icon-web-library": "^0.6.0",
80
- "@sharadox/web-library": "^0.8.0"
78
+ "@sharadox/email-web-library": "0.6.0",
79
+ "@sharadox/icon-web-library": "^0.6.1",
80
+ "@sharadox/web-library": "0.10.0"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": ">=19"