Skip to content

Commit 452f069

Browse files
committed
refactor: remove configurable endpoint option and update documentation
- Removed the optional parameter from FormsReach initialization and submission options. - Updated the SDK to use a fixed submit URL: . - Adjusted documentation across various files to reflect these changes and clarify that the endpoint is not configurable.
1 parent ae1d06e commit 452f069

14 files changed

Lines changed: 40 additions & 44 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@formsreach/js": minor
3+
"@formsreach/react": minor
4+
"@formsreach/vue": minor
5+
---
6+
7+
Bake the submit endpoint into the SDK and stop exposing it
8+
9+
All requests now go to `https://app.formsreach.com/api/v1/submit`, which is fixed inside `@formsreach/js`.
10+
11+
**Breaking:**
12+
13+
- Removed the `endpoint` option from `FormsReach.init`, `submitForm`, and `useFormsReach` (React and Vue).
14+
- Removed the `DEFAULT_ENDPOINT` export from `@formsreach/js`.

‎examples/html/index.html‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ <h1>FormsReach HTML example</h1>
6363

6464
FormsReach.init({
6565
apiKey,
66-
// Optional: point at local formsreach-app
67-
// endpoint: "http://localhost:3000/api/v1/submit",
6866
onSuccess(result) {
6967
log.textContent = "Success: " + JSON.stringify(result, null, 2);
7068
},

‎packages/js/AGENTS.md‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import { FormsReach, init, submitForm } from "@formsreach/js";
4545

4646
FormsReach.init({
4747
apiKey: "fr_…",
48-
// endpoint?: string — default https://formsreach.com/api/v1/submit
4948
onSuccess: ({ id, redirectUrl }) => {},
5049
onError: (err) => {},
5150
});
@@ -63,7 +62,6 @@ try {
6362
const { id, redirectUrl } = await submitForm({
6463
apiKey: "fr_…",
6564
data: { name: "Ada", email: "ada@example.com" },
66-
// endpoint?: string
6765
});
6866
} catch (e) {
6967
if (e instanceof FormsReachClientError) {
@@ -84,28 +82,25 @@ Field values must be strings (`Record<string, string>`). File uploads are **not*
8482
| `ensureSpamFields(form, opts?)` | function | Injects empty `_gotcha` + once-set `_ts` into the form DOM (idempotent). |
8583
| `FormsReach` | object | `{ init, submitForm }` — also default export. |
8684
| `FormsReachClientError` | class | `error.formsreach` holds normalized error payload. |
87-
| `DEFAULT_ENDPOINT` | const | `https://formsreach.com/api/v1/submit` |
8885
| `FORM_ATTR` | const | `data-formsreach` |
8986
| `EVENT_SUCCESS` / `EVENT_ERROR` | const | DOM event names (see below) |
9087

9188
### `FormsReachInitOptions`
9289

9390
- `apiKey: string` (required)
94-
- `endpoint?: string`
9591
- `onSuccess?: (result: { id: string; redirectUrl: string \| null }) => void`
9692
- `onError?: (error: FormsReachError) => void`
9793

9894
### `SubmitFormOptions`
9995

10096
- `apiKey: string`
101-
- `endpoint?: string`
10297
- `data: Record<string, string>`
10398

10499
## Backend contract (do not invent alternatives)
105100

106-
- `POST` to endpoint (default above)
101+
- `POST` to the fixed FormsReach endpoint `https://app.formsreach.com/api/v1/submit` (baked into the SDK; not configurable)
107102
- Body JSON: form fields + `api_key` + `_gotcha` (non-empty → silent spam) + `_ts` (render ms; too fast → silent spam; missing skips)
108-
- `init` / React / Vue auto-inject `_gotcha` + `_ts` via `ensureSpamFields`. Raw HTML POST without the SDK must include both in markup.
103+
- `init` / React / Vue auto-inject `_gotcha` + `_ts` via `ensureSpamFields`. Raw HTML POST without the SDK must include both in markup, and posts to a different host: `https://api.formsreach.com/submit`.
109104
- Programmatic `submitForm({ data })` without a form does not invent `_ts` (server skips time-trap).
110105
- Success envelope: `{ status: "success", data: { ok: true, id, redirectUrl }, meta: { requestId } }`
111106
- Failure envelope: `{ status: "failure", data: null, error: Problem, meta }`
@@ -129,7 +124,7 @@ Field values must be strings (`Record<string, string>`). File uploads are **not*
129124

130125
- Rename CDN file, `FormsReach` global, or `data-formsreach` without a major version + product snippet update
131126
- Ship or document file-upload fields until the product API supports them
132-
- Point at a non-FormsReach submit API unless the user explicitly overrides `endpoint` for self-host/testing
127+
- Add an `endpoint` / `baseUrl` option back — the submit URL is intentionally fixed and not part of the public API
133128
- Put dashboard or server code in the client
134129

135130
## Related packages

‎packages/js/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const { id, redirectUrl } = await submitForm({
4545
});
4646
```
4747

48+
All requests go to `https://app.formsreach.com/api/v1/submit`. The endpoint is built into the SDK and is not configurable.
49+
4850
## Events
4951

5052
After `init`, the SDK dispatches DOM events on `document`:

‎packages/js/src/bind.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ async function handleSubmit(event: Event): Promise<void> {
6868
const data = formToPayload(form, config.apiKey);
6969
const result = await submitForm({
7070
apiKey: config.apiKey,
71-
endpoint: config.endpoint,
7271
data,
7372
});
7473

‎packages/js/src/client.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
DEFAULT_ENDPOINT,
2+
SUBMIT_ENDPOINT,
33
type FormsReachError,
44
type FormsReachSuccess,
55
type SubmitFormOptions,
@@ -64,12 +64,11 @@ function fromFailure(
6464
export async function submitForm(
6565
options: SubmitFormOptions,
6666
): Promise<FormsReachSuccess> {
67-
const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
6867
const payload = withSubmitMeta(options.data, options.apiKey);
6968

7069
let res: Response;
7170
try {
72-
res = await fetch(endpoint, {
71+
res = await fetch(SUBMIT_ENDPOINT, {
7372
method: "POST",
7473
headers: {
7574
"Content-Type": "application/json",

‎packages/js/src/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export { init } from "./init";
22
export { submitForm, FormsReachClientError } from "./client";
33
export { ensureSpamFields, type EnsureSpamFieldsOptions } from "./spam-fields";
44
export {
5-
DEFAULT_ENDPOINT,
65
FORM_ATTR,
76
EVENT_SUCCESS,
87
EVENT_ERROR,

‎packages/js/src/init.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function init(options: FormsReachInitOptions): void {
1616

1717
setConfig({
1818
apiKey: options.apiKey.trim(),
19-
endpoint: options.endpoint,
2019
onSuccess: options.onSuccess,
2120
onError: options.onError,
2221
});

‎packages/js/src/types.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@ export type FormsReachError = {
1616
export type FormsReachInitOptions = {
1717
/** Form API key from the FormsReach dashboard (`fr_…`). */
1818
apiKey: string;
19-
/**
20-
* Public submit URL.
21-
* @default "https://formsreach.com/api/v1/submit"
22-
*/
23-
endpoint?: string;
2419
onSuccess?: (result: FormsReachSuccess) => void;
2520
onError?: (error: FormsReachError) => void;
2621
};
2722

2823
export type SubmitFormOptions = {
2924
apiKey: string;
30-
endpoint?: string;
3125
data: Record<string, string>;
3226
};
3327

34-
export const DEFAULT_ENDPOINT = "https://formsreach.com/api/v1/submit";
28+
/** Fixed FormsReach submit URL. Internal — not part of the public API. */
29+
export const SUBMIT_ENDPOINT = "https://app.formsreach.com/api/v1/submit";
3530

3631
export const FORM_ATTR = "data-formsreach";
3732

‎packages/js/tests/client.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("submitForm", () => {
3535
});
3636

3737
expect(fetch).toHaveBeenCalledWith(
38-
"https://formsreach.com/api/v1/submit",
38+
"https://app.formsreach.com/api/v1/submit",
3939
expect.objectContaining({
4040
method: "POST",
4141
headers: expect.objectContaining({

0 commit comments

Comments
 (0)