@formizeflow/sdk 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +91 -2
- package/dist/index.cjs +1874 -0
- package/dist/index.d.cts +5582 -0
- package/dist/index.d.ts +5582 -0
- package/dist/index.js +1751 -0
- package/dist/pgp-EDC744IM.js +28 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FormizeFlow
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FormFlow TypeScript SDK v2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/formizeflow/formflow-js/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
Zero dependencies, Node 18+ and modern browsers (`fetch`, WebCrypto, `AbortSignal`). Never ship an API key to a browser: use `ff.public` (no key) or the embed SDK there.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { FormFlowClient, form, constructWebhookEvent, ConflictError } from "@formizeflow/sdk";
|
|
9
|
+
|
|
10
|
+
const ff = new FormFlowClient({ apiKey: process.env.FORMFLOW_API_KEY!, baseUrl: "https://forms.example.com" });
|
|
11
|
+
console.log(await ff.account.me()); // credential, workspace, scopes
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Build a form in code
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
const def = form("Customer feedback")
|
|
18
|
+
.welcome({ title: "2 minutes, promise", buttonLabel: "Start" })
|
|
19
|
+
.nps("nps")
|
|
20
|
+
.longText("why", "What is the main reason for your score?")
|
|
21
|
+
.choice("channel", "How did you find us?", ["Search", "Friend", "Social"], { multiple: true })
|
|
22
|
+
.email("email", "Email (optional)")
|
|
23
|
+
.theme({ colors: { primary: "#4f46e5", background: "#0b1020", text: "#f8fafc" }, colorScheme: "dark", alignment: "center" })
|
|
24
|
+
.settings({ presentation: "conversational", notifications: { ownerEmails: ["team@example.com"] } })
|
|
25
|
+
.ending("Thank you!", "We read every answer.")
|
|
26
|
+
.build();
|
|
27
|
+
|
|
28
|
+
const created = await ff.forms.create({ name: "Feedback", definition: def });
|
|
29
|
+
await ff.forms.update(created.id, { password: "s3cret-launch" }); // write-only; response has passwordRequired: true
|
|
30
|
+
const { version, warnings } = await ff.forms.publish(created.id);
|
|
31
|
+
const links = await ff.forms.share(created.id); // hosted URL, QR, embed snippets
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Edit atomically
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
await ff.forms.edit(created.id, (f) => [
|
|
38
|
+
{ op: "add_field", field: { id: "company", type: "company", label: "Company" }, index: 1 },
|
|
39
|
+
{ op: "set_theme", theme: { radius: 20 } },
|
|
40
|
+
]); // all-or-nothing, returns engine `issues`
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Responses, pagination, cancellation
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const ac = new AbortController();
|
|
47
|
+
for await (const s of ff.submissions.listAll(created.id, { status: "completed", limit: 100, expand: ["form"], redact: "sensitive" }, { signal: ac.signal })) {
|
|
48
|
+
console.log(s.id, s.answers);
|
|
49
|
+
}
|
|
50
|
+
const hot = await ff.submissions.search(created.id, { filters: { type: "condition", source: { kind: "field", id: "nps" }, operator: "lte", value: 6 }, fields: ["nps", "why"] });
|
|
51
|
+
const job = await ff.submissions.export(created.id, { format: "xlsx" });
|
|
52
|
+
const done = await ff.exports.wait(job.export.id); // done.url
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Analytics and AI
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
await ff.analytics.metrics(id, { from: Date.now() - 7 * 864e5 });
|
|
59
|
+
await ff.analytics.satisfaction(id); // NPS / CSAT / CES
|
|
60
|
+
const a = await ff.ai.analyzeResponses(id, { question: "What annoys detractors?" }); // always show a.caveats
|
|
61
|
+
const gen = await ff.ai.generateForm({ prompt: "Event registration with meal preferences", create: { name: "Event" } });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Webhooks (typed)
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
export async function POST(req: Request) {
|
|
68
|
+
const event = await constructWebhookEvent(await req.text(), req.headers.get("formflow-signature"), process.env.WEBHOOK_SECRET!);
|
|
69
|
+
switch (event.type) {
|
|
70
|
+
case "submission.completed": return handle(event.data.answers, event.data.labels);
|
|
71
|
+
case "form.published": /* event.data.slug */ break;
|
|
72
|
+
}
|
|
73
|
+
return new Response("ok");
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Experiments and conversions
|
|
78
|
+
```ts
|
|
79
|
+
// your backend, when a user reaches the goal (key needs form:write); uid is the id your app passes to the form
|
|
80
|
+
await ff.experiments.reportConversion("exp_123", { uid: "user_42", event: "subscribed", value: 9.99, eventId: "sub_abc" });
|
|
81
|
+
const results = await ff.experiments.results("exp_123"); // frequentist + Bayesian, funnels, sample-ratio check
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Errors, retries, options
|
|
85
|
+
|
|
86
|
+
`FormFlowError` (`status`, `code`, `details`, `requestId`) with subclasses `AuthenticationError`, `PermissionError`, `NotFoundError`, `ConflictError` (`details.currentRevision`), `ValidationError` (`details.issues`), `RateLimitError` (`retryAfterSec`). 429, 5xx and network errors are retried with backoff honoring `Retry-After` (`maxRetries`, default 3); POSTs carry an automatic `Idempotency-Key`. Every method accepts `{ signal, idempotencyKey }`. Client options: `apiKey`, `baseUrl`, `version`, `maxRetries`, `timeoutMs`, `workspaceId`, `fetch`.
|
|
87
|
+
|
|
88
|
+
## Respondent endpoints (no key)
|
|
89
|
+
|
|
90
|
+
`ff.public.getForm(slug)`, `unlock(slug, password)` (httpOnly cookie; use `credentials: "include"` in browsers), `start`, `save`, `complete`.
|
|
91
|
+
|
|
92
|
+
The types in `resources/*.ts` are maintained by hand next to `/openapi.json`; when you add an endpoint, update both.
|