@sharadox/form-web-library 0.6.2-development.16 → 0.7.0-form-plumbing.18
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/README.md +11 -8
- package/distribution/bot-field/index.d.ts +11 -0
- package/distribution/bot-field/index.d.ts.map +1 -0
- package/distribution/bot-field/index.js +21 -0
- package/distribution/bot-field/index.js.map +1 -0
- package/distribution/bot-field/type.d.ts +9 -0
- package/distribution/bot-field/type.d.ts.map +1 -0
- package/distribution/bot-field/type.js +2 -0
- package/distribution/bot-field/type.js.map +1 -0
- package/distribution/choice-request/index.d.ts +16 -0
- package/distribution/choice-request/index.d.ts.map +1 -0
- package/distribution/choice-request/index.js +30 -0
- package/distribution/choice-request/index.js.map +1 -0
- package/distribution/contact-problem/index.d.ts +15 -0
- package/distribution/contact-problem/index.d.ts.map +1 -0
- package/distribution/contact-problem/index.js +23 -0
- package/distribution/contact-problem/index.js.map +1 -0
- package/distribution/contact-problem/type.d.ts +3 -0
- package/distribution/contact-problem/type.d.ts.map +1 -0
- package/distribution/contact-problem/type.js +2 -0
- package/distribution/contact-problem/type.js.map +1 -0
- package/llms.txt +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,14 +92,17 @@ The email server comes from `EMAIL_SERVER_*` and `EMAIL_SENDER_ADDRESS`.
|
|
|
92
92
|
|
|
93
93
|
## API
|
|
94
94
|
|
|
95
|
-
| Import
|
|
96
|
-
|
|
|
97
|
-
| `…/contact-
|
|
98
|
-
| `…/
|
|
99
|
-
| `…/
|
|
100
|
-
| `…/
|
|
101
|
-
| `…/
|
|
102
|
-
| `…/
|
|
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)` |
|
|
103
106
|
|
|
104
107
|
## Develop
|
|
105
108
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BotFieldsProperties } from "@sharadox/form-web-library/bot-field/type";
|
|
2
|
+
/**
|
|
3
|
+
* The two hidden fields `isLikelyBot` reads: a honeypot people never see, and the moment the form appeared (forms
|
|
4
|
+
* sent faster than a person can type are refused). Put it inside the form; field names match `isLikelyBot`'s
|
|
5
|
+
* defaults.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <form action={send}><BotFields />…</form>
|
|
9
|
+
*/
|
|
10
|
+
export declare function BotFields({ honeypotField, startedAtField, honeypotLabel, }: BotFieldsProperties): import("react").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/bot-field/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAKrF;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EACxB,aAAyB,EACzB,cAA6B,EAC7B,aAAyB,GAC1B,EAAE,mBAAmB,+BAgBrB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
/** Out of sight but still in the form, so robots that fill every field give themselves away. */
|
|
5
|
+
const HIDDEN = { position: "absolute", left: "-9999px", width: 1, height: 1, overflow: "hidden" };
|
|
6
|
+
/**
|
|
7
|
+
* The two hidden fields `isLikelyBot` reads: a honeypot people never see, and the moment the form appeared (forms
|
|
8
|
+
* sent faster than a person can type are refused). Put it inside the form; field names match `isLikelyBot`'s
|
|
9
|
+
* defaults.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <form action={send}><BotFields />…</form>
|
|
13
|
+
*/
|
|
14
|
+
export function BotFields({ honeypotField = "website", startedAtField = "started-at", honeypotLabel = "Website", }) {
|
|
15
|
+
const startedAt = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
startedAt.current.value = String(Date.now());
|
|
18
|
+
}, []);
|
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { ref: startedAt, type: "hidden", name: startedAtField, defaultValue: "0" }), _jsx("div", { style: HIDDEN, "aria-hidden": true, children: _jsxs("label", { children: [honeypotLabel, _jsx("input", { name: honeypotField, tabIndex: -1, autoComplete: "off" })] }) })] }));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/bot-field/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG1C,gGAAgG;AAChG,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAW,CAAC;AAE3G;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,EACxB,aAAa,GAAG,SAAS,EACzB,cAAc,GAAG,YAAY,EAC7B,aAAa,GAAG,SAAS,GACL;IACpB,MAAM,SAAS,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,CAAC,OAAQ,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAChD,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,CACL,8BACE,gBAAO,GAAG,EAAE,SAAS,EAAE,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,cAAc,EAAE,YAAY,EAAC,GAAG,GAAG,EAC9E,cAAK,KAAK,EAAE,MAAM,iCAChB,4BACG,aAAa,EACd,gBAAO,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,YAAY,EAAC,KAAK,GAAG,IACzD,GACJ,IACL,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface BotFieldsProperties {
|
|
2
|
+
/** The honeypot's field name: people never fill it (it's out of sight), robots do. `website` by default. */
|
|
3
|
+
honeypotField?: string;
|
|
4
|
+
/** The field that records when the form appeared. `started-at` by default. */
|
|
5
|
+
startedAtField?: string;
|
|
6
|
+
/** The honeypot's visible label, read only by robots. */
|
|
7
|
+
honeypotLabel?: string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/bot-field/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,4GAA4G;IAC5G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/bot-field/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asks a form on the page to tick some choices (those already ticked stay ticked), for buttons that lead to the form,
|
|
3
|
+
* such as a service card's. `event` names the form's channel, for example "site:contact-choice".
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* requestChoices("sharadox:contact-need", ["website"]);
|
|
7
|
+
*/
|
|
8
|
+
export declare function requestChoices<Key extends string>(event: string, choices: readonly Key[]): void;
|
|
9
|
+
/**
|
|
10
|
+
* The form's side: calls `onRequest` with the choices each request asks for, while the form is on the page.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* useChoiceRequests("sharadox:contact-need", (choices) => setTicked((ticked) => new Set([...ticked, ...choices])));
|
|
14
|
+
*/
|
|
15
|
+
export declare function useChoiceRequests<Key extends string>(event: string, onRequest: (choices: readonly Key[]) => void): void;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/choice-request/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE,GAAG,IAAI,CAE/F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,SAAS,MAAM,EAClD,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,GAAG,EAAE,KAAK,IAAI,GAC3C,IAAI,CAUN"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Asks a form on the page to tick some choices (those already ticked stay ticked), for buttons that lead to the form,
|
|
5
|
+
* such as a service card's. `event` names the form's channel, for example "site:contact-choice".
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* requestChoices("sharadox:contact-need", ["website"]);
|
|
9
|
+
*/
|
|
10
|
+
export function requestChoices(event, choices) {
|
|
11
|
+
dispatchEvent(new CustomEvent(event, { detail: choices }));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The form's side: calls `onRequest` with the choices each request asks for, while the form is on the page.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* useChoiceRequests("sharadox:contact-need", (choices) => setTicked((ticked) => new Set([...ticked, ...choices])));
|
|
18
|
+
*/
|
|
19
|
+
export function useChoiceRequests(event, onRequest) {
|
|
20
|
+
const latest = useRef(onRequest);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
latest.current = onRequest;
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const listener = (request) => latest.current(request.detail);
|
|
26
|
+
addEventListener(event, listener);
|
|
27
|
+
return () => removeEventListener(event, listener);
|
|
28
|
+
}, [event]);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/choice-request/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAqB,KAAa,EAAE,OAAuB;IACvF,aAAa,CAAC,IAAI,WAAW,CAAiB,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,SAA4C;IAE5C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IACjC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,CAAC,OAAc,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAE,OAAuC,CAAC,MAAM,CAAC,CAAC;QACrG,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContactProblem } from "@sharadox/form-web-library/contact-problem/type";
|
|
2
|
+
/**
|
|
3
|
+
* What a form's contact details still lack, by the same rules on the page and on the server: a name, and a way to
|
|
4
|
+
* reply (an email, a phone or both), each valid when given. Empty when they're complete. Forms add their own checks
|
|
5
|
+
* (choices, a message) after these.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* contactProblems({ name: "Ana", email: "", phone: "912" }); // ["phone"]
|
|
9
|
+
*/
|
|
10
|
+
export declare function contactProblems({ name, email, phone, }: {
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
phone: string;
|
|
14
|
+
}): ContactProblem[];
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-problem/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEtF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,EAC9B,IAAI,EACJ,KAAK,EACL,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,cAAc,EAAE,CAQnB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isEmail, isPhone } from "@sharadox/form-web-library/contact-check";
|
|
2
|
+
/**
|
|
3
|
+
* What a form's contact details still lack, by the same rules on the page and on the server: a name, and a way to
|
|
4
|
+
* reply (an email, a phone or both), each valid when given. Empty when they're complete. Forms add their own checks
|
|
5
|
+
* (choices, a message) after these.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* contactProblems({ name: "Ana", email: "", phone: "912" }); // ["phone"]
|
|
9
|
+
*/
|
|
10
|
+
export function contactProblems({ name, email, phone, }) {
|
|
11
|
+
const [trimmedEmail, trimmedPhone] = [email.trim(), phone.trim()];
|
|
12
|
+
const problems = [];
|
|
13
|
+
if (!name.trim())
|
|
14
|
+
problems.push("name");
|
|
15
|
+
if (!trimmedEmail && !trimmedPhone)
|
|
16
|
+
problems.push("reach");
|
|
17
|
+
if (trimmedEmail && !isEmail(trimmedEmail))
|
|
18
|
+
problems.push("email");
|
|
19
|
+
if (trimmedPhone && !isPhone(trimmedPhone))
|
|
20
|
+
problems.push("phone");
|
|
21
|
+
return problems;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-problem/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,0CAA0C,CAAC;AAG5E;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,IAAI,EACJ,KAAK,EACL,KAAK,GAKN;IACC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAqB,EAAE,CAAC;IACtC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY;QAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3D,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnE,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-problem/type.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/contact-problem/type.ts"],"names":[],"mappings":""}
|
package/llms.txt
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
> Forms: a phone field with country flags and calling codes (React), and on the server bot checks, rate limit and a contact action emailing via @sharadox/email-web-library.
|
|
4
4
|
|
|
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
|
+
- /choice-request: requestChoices(event, choices) and useChoiceRequests(event, onRequest): a button elsewhere on the page asks the form to tick choices
|
|
7
|
+
- /bot-field: <BotFields honeypotField? startedAtField? honeypotLabel? />: the hidden honeypot and fill-time fields isLikelyBot reads
|
|
5
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.
|
|
6
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).
|
|
7
10
|
- /parse-contact: parseContact(form, { choices, choiceField='need', reach, requireMessage, minimumMessageLength, requireChoice, fields, now }) → value { name, email, phone, company, message, locale, choices, fields }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/form-web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-form-plumbing.18",
|
|
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",
|